Skip to content

Instantly share code, notes, and snippets.

@reefwing
Last active April 24, 2023 23:24
Show Gist options
  • Save reefwing/15eb2808e448926cc3f21d09bc104422 to your computer and use it in GitHub Desktop.
Save reefwing/15eb2808e448926cc3f21d09bc104422 to your computer and use it in GitHub Desktop.
void parseCommand() {
char *cmdPtr = rx.getCommand();
switch(rx.hash(cmdPtr) % HASH_SIZE) {
case xIMU3_ping:
rx.sendPing(pingPacket);
break;
case xIMU3_deviceName:
rx.sendResponse("deviceName", "Arduino");
break;
case xIMU3_serialNumber:
rx.sendResponse("serialNumber", "0123-4567");
break;
case xIMU3_firmwareVersion:
rx.sendResponse("firmwareVersion", "v1.0");
break;
case xIMU3_bootloaderVersion:
rx.sendResponse("bootloaderVersion", "Rel: 4.0.2");
break;
case xIMU3_hardwareVersion:
rx.sendResponse("hardwareVersion", "v1.0");
break;
case xIMU3_serialMode:
rx.sendResponse("serialMode", STANDARD);
break;
case xIMU3_serialBaudRate:
rx.sendResponse("serialBaudRate", 115200);
break;
case xIMU3_serialRtsCtsEnabled:
rx.sendResponse("serialRtsCtsEnabled", "false");
break;
case xIMU3_note:
rx.sendResponse("note", rx.getValue());
break;
case xIMU3_shutdown:
// Shutdown Arduino command received
rx.sendResponse("shutdown", "true");
break;
case xIMU3_strobe:
rx.sendResponse("strobe", "null");
strobe = true;
digitalWrite(LED_BUILTIN, HIGH);
previousMillis = millis();
break;
case blinkLED: {
char *cmdValue = rx.getValue();
char msg[100] = "Custom Command Received - blinkLED - ";
rx.sendResponse("blinkLED", cmdValue);
rx.sendNotification(strcat(msg, cmdValue));
if (strcasecmp("true", cmdValue) == 0) {
blink = true;
digitalWrite(LED_BUILTIN, HIGH);
previousMillis = millis();
}
else {
blink = false;
digitalWrite(LED_BUILTIN, LOW);
}
}
break;
default:
char msg[100] = "Unhandled x-IMU3 command - ";
rx.sendError(strcat(msg, cmdPtr));
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment