@@ -54,15 +54,12 @@ void Commander::run(Stream& serial, char eol){
5454 }
5555
5656 com_port = tmp; // reset the instance to the internal value
57- this ->eol = eol_tmp;
57+ this ->eol = eol_tmp;
5858}
5959
6060void Commander::run (char * user_input){
6161 // execute the user command
6262 char id = user_input[0 ];
63-
64-
65-
6663 switch (id){
6764 case CMD_SCAN:
6865 for (int i=0 ; i < call_count; i++){
@@ -102,14 +99,25 @@ void Commander::run(char* user_input){
10299}
103100
104101void Commander::motor (FOCMotor* motor, char * user_command) {
102+
103+ // if target setting
104+ if (isDigit (user_command[0 ]) || user_command[0 ] == ' -' || user_command[0 ] == ' +' ){
105+ printVerbose (F (" Target: " ));
106+ motor->target = atof (user_command);
107+ println (motor->target );
108+ return ;
109+ }
110+
105111 // parse command letter
106112 char cmd = user_command[0 ];
107113 char sub_cmd = user_command[1 ];
114+ // check if there is a subcommand or not
108115 int value_index = (sub_cmd >= ' A' && sub_cmd <= ' Z' ) ? 2 : 1 ;
109116 // check if get command
110117 bool GET = isSentinel (user_command[value_index]);
111118 // parse command values
112- float value = atof (&user_command[value_index]);
119+ float value = atof (&user_command[value_index]);
120+
113121
114122 // a bit of optimisation of variable memory for Arduino UNO (atmega328)
115123 switch (cmd){
@@ -181,7 +189,7 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
181189 break ;
182190 default :
183191 // change control type
184- if (!GET && value >= 0 && (int )value < 5 )// if set command
192+ if (!GET && value >= 0 && (int )value < 5 ) // if set command
185193 motor->controller = (MotionControlType)value;
186194 switch (motor->controller ){
187195 case MotionControlType::torque:
@@ -367,10 +375,9 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
367375 break ;
368376 }
369377 break ;
370- default : // target change
371- printVerbose (F (" Target: " ));
372- motor->target = atof (user_command);
373- println (motor->target );
378+ default : // unknown cmd
379+ printVerbose (F (" unknown cmd " ));
380+ printError ();
374381 }
375382}
376383
@@ -440,12 +447,7 @@ bool Commander::isSentinel(char ch)
440447 return true ;
441448 else if (ch == ' \r ' )
442449 {
443- if (verbose == VerboseMode::user_friendly)
444- {
445- print (F (" Warning! \\ r detected but is not configured as end of line sentinel, which is configured as ascii code '" ));
446- print (int (eol));
447- print (" '\n " );
448- }
450+ printVerbose (F (" Warn: \\ r detected! \n " ));
449451 }
450452 return false ;
451453}
0 commit comments