@@ -62,6 +62,7 @@ void Commander::run(char* user_input){
62
62
switch (id){
63
63
case CMD_SCAN:
64
64
for (int i=0 ; i < call_count; i++){
65
+ printMachineReadable (F (" ?" ));
65
66
print (call_ids[i]);
66
67
print (" :" );
67
68
if (call_label[i]) println (call_label[i]);
@@ -79,16 +80,21 @@ void Commander::run(char* user_input){
79
80
case VerboseMode::user_friendly:
80
81
println (F (" on!" ));
81
82
break ;
83
+ case VerboseMode::machine_readable:
84
+ printlnMachineReadable (F (" @3" ));
85
+ break ;
82
86
}
83
87
break ;
84
88
case CMD_DECIMAL:
85
89
if (!isSentinel (user_input[1 ])) decimal_places = atoi (&user_input[1 ]);
86
90
printVerbose (F (" Decimal:" ));
91
+ printMachineReadable (F (" #" ));
87
92
println (decimal_places);
88
93
break ;
89
94
default :
90
95
for (int i=0 ; i < call_count; i++){
91
96
if (id == call_ids[i]){
97
+ printMachineReadable (user_input[0 ]);
92
98
call_list[i](&user_input[1 ]);
93
99
break ;
94
100
}
@@ -100,7 +106,7 @@ void Commander::run(char* user_input){
100
106
void Commander::motor (FOCMotor* motor, char * user_command) {
101
107
102
108
// if target setting
103
- if (isDigit (user_command[0 ]) || user_command[0 ] == ' -' || user_command[0 ] == ' +' ){
109
+ if (isDigit (user_command[0 ]) || user_command[0 ] == ' -' || user_command[0 ] == ' +' || isSentinel (user_command[ 0 ]) ){
104
110
target (motor, user_command);
105
111
return ;
106
112
}
@@ -114,7 +120,10 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
114
120
bool GET = isSentinel (user_command[value_index]);
115
121
// parse command values
116
122
float value = atof (&user_command[value_index]);
117
-
123
+ printMachineReadable (cmd);
124
+ if (sub_cmd >= ' A' && sub_cmd <= ' Z' ) {
125
+ printMachineReadable (sub_cmd);
126
+ }
118
127
119
128
// a bit of optimisation of variable memory for Arduino UNO (atmega328)
120
129
switch (cmd){
@@ -313,9 +322,9 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
313
322
break ;
314
323
case SCMD_SET:
315
324
if (!GET) motor->monitor_variables = (uint8_t ) 0 ;
316
- for (int i = 0 ; i < 7 ; i++){
325
+ for (int i = 0 ; i < 8 ; i++){
317
326
if (isSentinel (user_command[value_index+i])) break ;
318
- if (!GET) motor->monitor_variables |= (user_command[value_index+i] - ' 0' ) << (6 -i);
327
+ if (!GET) motor->monitor_variables |= (user_command[value_index+i] - ' 0' ) << (7 -i);
319
328
print ( (user_command[value_index+i] - ' 0' ) );
320
329
}
321
330
println (" " );
@@ -468,8 +477,11 @@ void Commander::scalar(float* value, char* user_cmd){
468
477
469
478
void Commander::target (FOCMotor* motor, char * user_cmd, char * separator){
470
479
// if no values sent
471
- if (isSentinel (user_cmd[0 ])) return ;
472
-
480
+ if (isSentinel (user_cmd[0 ])) {
481
+ printlnMachineReadable (motor->target );
482
+ return ;
483
+ };
484
+
473
485
float pos, vel, torque;
474
486
char * next_value;
475
487
switch (motor->controller ){
@@ -614,6 +626,39 @@ void Commander::printVerbose(const char* message){
614
626
void Commander::printVerbose (const __FlashStringHelper *message){
615
627
if (verbose == VerboseMode::user_friendly) print (message);
616
628
}
629
+
630
+ void Commander::printMachineReadable (const int number){
631
+ if (verbose == VerboseMode::machine_readable) print (number);
632
+ }
633
+ void Commander::printMachineReadable (const float number){
634
+ if (verbose == VerboseMode::machine_readable) print (number);
635
+ }
636
+ void Commander::printMachineReadable (const char * message){
637
+ if (verbose == VerboseMode::machine_readable) print (message);
638
+ }
639
+ void Commander::printMachineReadable (const __FlashStringHelper *message){
640
+ if (verbose == VerboseMode::machine_readable) print (message);
641
+ }
642
+ void Commander::printMachineReadable (const char message){
643
+ if (verbose == VerboseMode::machine_readable) print (message);
644
+ }
645
+
646
+ void Commander::printlnMachineReadable (const int number){
647
+ if (verbose == VerboseMode::machine_readable) println (number);
648
+ }
649
+ void Commander::printlnMachineReadable (const float number){
650
+ if (verbose == VerboseMode::machine_readable) println (number);
651
+ }
652
+ void Commander::printlnMachineReadable (const char * message){
653
+ if (verbose == VerboseMode::machine_readable) println (message);
654
+ }
655
+ void Commander::printlnMachineReadable (const __FlashStringHelper *message){
656
+ if (verbose == VerboseMode::machine_readable) println (message);
657
+ }
658
+ void Commander::printlnMachineReadable (const char message){
659
+ if (verbose == VerboseMode::machine_readable) println (message);
660
+ }
661
+
617
662
void Commander::printError (){
618
663
println (F (" err" ));
619
664
}
0 commit comments