Separate behavior when receiving different serials

This commit is contained in:
Matt McWilliams 2023-02-13 15:41:33 -05:00
parent 84d3c68f31
commit 4a5314c78d
1 changed files with 19 additions and 9 deletions

View File

@ -93,7 +93,7 @@ void loop() {
} }
if (cmdChar != 'z') { if (cmdChar != 'z') {
cmd(cmdChar); cmd(cmdChar, 0);
} }
cmdChar = 'z'; cmdChar = 'z';
@ -103,7 +103,7 @@ void loop() {
} }
if (cmdChar != 'z') { if (cmdChar != 'z') {
cmd(cmdChar); cmd(cmdChar, 1);
} }
cmdChar = 'z'; cmdChar = 'z';
@ -116,11 +116,11 @@ void loop() {
} }
} }
void cmd (char which) { void cmd (char which, int source) {
if (which == Fcmd && !Frunning) { if (which == Fcmd && !Frunning) {
forward(); forward(source);
} else if (which == Bcmd && !Brunning) { } else if (which == Bcmd && !Brunning) {
backward(); backward(source);
} else if (which == cmd_debug) { } else if (which == cmd_debug) {
debug(); debug();
} else if (which == cmd_connect) { } else if (which == cmd_connect) {
@ -130,15 +130,25 @@ void cmd (char which) {
} }
} }
void forward () { void forward (int source) {
log("forward()"); log("forward()");
if (source == 0) {
Serial.println(Fcmd);
} else if (source == 1) {
softSerial.write(Fcmd);
}
Ftime = timer; Ftime = timer;
set_speed(Fmotor, frameSpeed); set_speed(Fmotor, frameSpeed);
clockwise(Fmotor); clockwise(Fmotor);
} }
void backward () { void backward (int source) {
log("backward()"); log("backward()");
if (source == 0) {
Serial.println(Bcmd);
} else if (source == 1) {
softSerial.write(Bcmd);
}
Btime = timer; Btime = timer;
set_speed(Bmotor, frameSpeed); set_speed(Bmotor, frameSpeed);
counter_clockwise(Bmotor); counter_clockwise(Bmotor);
@ -294,9 +304,9 @@ void btnCmd (int index, int time) {
int multiple = floor(time / buttonPress); int multiple = floor(time / buttonPress);
if (multiple > ButtonMultiple[index]) { if (multiple > ButtonMultiple[index]) {
if (index == Fmotor) { if (index == Fmotor) {
cmd(Fcmd); cmd(Fcmd, 0);
} else if (index == Bmotor) { } else if (index == Bmotor) {
cmd(Bcmd); cmd(Bcmd, 0);
} }
ButtonMultiple[index] = multiple; ButtonMultiple[index] = multiple;
} }