@@ -53,28 +53,25 @@ static void show_get_usage(void)
5353 SHELL_OPTION ("-c, --channel" , "Selected channel in hex, e.g, f means channel 1 to channel 4." );
5454}
5555
56- static rt_size_t act_device_write (rt_device_t dev , rt_uint16_t chan_sel , const rt_uint16_t * chan_val , rt_size_t size )
56+ static rt_size_t act_device_write (actuator_dev_t act_dev , rt_uint16_t chan_sel , const rt_uint16_t * chan_val , rt_size_t size )
5757{
58- actuator_dev_t act_dev = (actuator_dev_t )dev ;
5958 rt_size_t ret = size ;
6059
6160 /* Suspend controller output */
6261 mcn_suspend (MCN_HUB (control_output ));
6362
6463 if (act_dev -> config .protocol == ACT_PROTOCOL_PWM ) {
65- ret = rt_device_write (dev , chan_sel , chan_val , size );
64+ ret = rt_device_write (& act_dev -> parent , chan_sel , chan_val , size );
6665 } else if (act_dev -> config .protocol == ACT_PROTOCOL_DSHOT ) {
67-
6866 printf ("Press any key to stop...\n" );
69-
7067 while (1 ) {
7168 /* type any key to exit */
7269 if (syscmd_has_input ()) {
7370 syscmd_flush ();
7471 break ;
7572 }
7673
77- if (rt_device_write (dev , chan_sel , chan_val , size ) != size ) {
74+ if (rt_device_write (& act_dev -> parent , chan_sel , chan_val , size ) != size ) {
7875 printf ("dshot write failed!\n" );
7976 ret = 0 ;
8077 break ;
@@ -109,7 +106,7 @@ static int set(int argc, struct optparse options)
109106 uint8_t all = 0 ;
110107 uint16_t chan_sel = 0 ;
111108 uint16_t chan_val [16 ] = { 0 };
112- rt_device_t dev = NULL ;
109+ actuator_dev_t dev = NULL ;
113110
114111 FMS_Out_Bus fms_out ;
115112 if (mcn_copy_from_hub (MCN_HUB (fms_output ), & fms_out ) == FMT_EOK ) {
@@ -132,7 +129,7 @@ static int set(int argc, struct optparse options)
132129 chan_sel = 0xFFFF ;
133130 break ;
134131 case 'd' :
135- dev = rt_device_find (options .optarg );
132+ dev = ( actuator_dev_t ) rt_device_find (options .optarg );
136133 if (dev == NULL ) {
137134 printf ("Can not find device:%s\n" , options .optarg );
138135 return EXIT_FAILURE ;
@@ -154,6 +151,7 @@ static int set(int argc, struct optparse options)
154151
155152 int arg_c = argc - options .optind ;
156153 int chan_num = 0 ;
154+ uint16_t val ;
157155
158156 for (int i = 0 ; i < 16 ; i ++ ) {
159157 if (chan_sel & (1 << i )) {
@@ -167,7 +165,6 @@ static int set(int argc, struct optparse options)
167165 }
168166
169167 if (all ) {
170- uint16_t val ;
171168 arg = optparse_arg (& options );
172169 if (arg == NULL ) {
173170 show_set_usage ();
@@ -176,6 +173,10 @@ static int set(int argc, struct optparse options)
176173 val = atoi (arg );
177174
178175 for (int i = 0 ; i < 16 ; i ++ ) {
176+ if (val < dev -> range [0 ] || val > dev -> range [1 ]) {
177+ printf ("Invalid value! The allowed range is [%d, %d]\n" , dev -> range [0 ], dev -> range [1 ]);
178+ return EXIT_FAILURE ;
179+ }
179180 chan_val [i ] = val ;
180181 }
181182
@@ -188,7 +189,13 @@ static int set(int argc, struct optparse options)
188189 show_set_usage ();
189190 return EXIT_FAILURE ;
190191 }
191- chan_val [index ++ ] = atoi (arg );
192+
193+ val = atoi (arg );
194+ if (val < dev -> range [0 ] || val > dev -> range [1 ]) {
195+ printf ("the allowed range is [%d, %d]\n" , dev -> range [0 ], dev -> range [1 ]);
196+ return EXIT_FAILURE ;
197+ }
198+ chan_val [index ++ ] = val ;
192199 }
193200 }
194201
0 commit comments