diff --git a/README.md b/README.md index 01e96f0..898fba5 100644 --- a/README.md +++ b/README.md @@ -267,42 +267,74 @@ With a hash table of the command keys that we want to respond to, we can now rec ``` c++ void parseCommand() { - char *cmdPtr = cmd; + char *cmdPtr = rx.getCommand(); - switch(hash(cmdPtr) % HASH_SIZE) { + switch(rx.hash(cmdPtr) % HASH_SIZE) { case xIMU3_ping: - sendPing("Raven"); + rx.sendPing(pingPacket); break; case xIMU3_deviceName: - sendCommand("deviceName", "Raven"); + rx.sendResponse("deviceName", "Arduino"); break; case xIMU3_serialNumber: - sendCommand("serialNumber", "0123-4567"); + rx.sendResponse("serialNumber", "0123-4567"); break; case xIMU3_firmwareVersion: - sendCommand("firmwareVersion", "v1.0"); + rx.sendResponse("firmwareVersion", "v1.0"); break; case xIMU3_bootloaderVersion: - sendCommand("bootloaderVersion", "Rel: 4.0.2"); + rx.sendResponse("bootloaderVersion", "Rel: 4.0.2"); break; case xIMU3_hardwareVersion: - sendCommand("hardwareVersion", "v1.0"); + rx.sendResponse("hardwareVersion", "v1.0"); break; case xIMU3_serialMode: - sendCommand("serialMode", STANDARD); + rx.sendResponse("serialMode", STANDARD); break; case xIMU3_serialBaudRate: - sendCommand("serialBaudRate", 115200); + rx.sendResponse("serialBaudRate", 115200); break; case xIMU3_serialRtsCtsEnabled: - sendCommand("serialRtsCtsEnabled", "false"); + 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 - "; - sendError(strcat(msg, cmdPtr)); + rx.sendError(strcat(msg, cmdPtr)); break; } + } ``` @@ -354,7 +386,7 @@ void setup() { } ``` -The code, `while (!Serial)`, is not required for boards with an FT232 chip or other USB to Serial bridge (e.g., Uno, and Mega2560). This because these boards will reset when they receive a DTR serial command. +The code, `while (!Serial)`, is not required for boards with an FT232 chip or other USB to Serial bridge (e.g., Uno, and Mega2560). This is because these boards will reset when they receive a DTR serial command. The code within `loop()` will depend on your sketch objectives. You will either be sending data messages, responding to commands or a combination of both. Refer to the library examples. diff --git a/src/Reefwing_xIMU3.cpp b/src/Reefwing_xIMU3.cpp index b7d0a3e..c81e6bc 100644 --- a/src/Reefwing_xIMU3.cpp +++ b/src/Reefwing_xIMU3.cpp @@ -80,13 +80,13 @@ void Reefwing_xIMU3::sendQuaternion(Quaternion quaternion) { Serial.print("Q,"); Serial.print(quaternion.timeStamp); Serial.print(","); - Serial.print(quaternion.q[0], 4); + Serial.print(quaternion.q0, 4); Serial.print(","); - Serial.print(quaternion.q[1], 4); + Serial.print(quaternion.q1, 4); Serial.print(","); - Serial.print(quaternion.q[2], 4); + Serial.print(quaternion.q2, 4); Serial.print(","); - Serial.print(quaternion.q[3], 4); + Serial.print(quaternion.q3, 4); Serial.print("\r\n"); } diff --git a/src/xIMU3_Types.h b/src/xIMU3_Types.h index 7a1f148..d55d78b 100644 --- a/src/xIMU3_Types.h +++ b/src/xIMU3_Types.h @@ -114,4 +114,23 @@ struct RSSIData { float power; }; +struct Ping { + char *interface; + char *dName; + char *sNumber; +}; + +struct NetworkAnnouncement { + uint16_t sync; + char *displayName; + char *serialNumber; + char *ipAddress; + uint16_t portTCP; + uint16_t sendUDP; + uint16_t receiveUDP; + uint8_t rssiPercentage; + uint8_t batteryPercentage; + uint8_t chargingStatus; +}; + #endif \ No newline at end of file