From b4fc3edd0f2d000e2c148a29f4145b69eb8d78e4 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Wed, 17 Oct 2018 16:15:15 -0400 Subject: [PATCH] LED state changing (Device LEDs work now) --- communication/encoder.cpp | 3 +++ device/device.cpp | 19 +++++++++++++++++++ device/include/device.h | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/communication/encoder.cpp b/communication/encoder.cpp index 25d84be..c08bc47 100644 --- a/communication/encoder.cpp +++ b/communication/encoder.cpp @@ -24,6 +24,9 @@ std::vector Encoder::encode(const std::shared_ptr& message) { // } default: switch(message->network.getNetID()) { + case Network::NetID::Device: + shortFormat = true; + break; case Network::NetID::Main51: if(message->data.size() > 0xF) { // Main51 can be sent as a long message without setting the NetID to RED first diff --git a/device/device.cpp b/device/device.cpp index 7f094cb..346dbc0 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -173,6 +173,9 @@ bool Device::goOnline() { if(!com->sendCommand(Command::EnableNetworkCommunication, true)) return false; + ledState = LEDState::Online; + updateLEDState(); + online = true; return true; } @@ -181,6 +184,9 @@ bool Device::goOffline() { if(!com->sendCommand(Command::EnableNetworkCommunication, false)) return false; + ledState = latestResetStatus->cmRunning ? LEDState::CoreMiniRunning : LEDState::Offline; + updateLEDState(); + online = false; return true; } @@ -193,4 +199,17 @@ void Device::handleInternalMessage(std::shared_ptr message) { default: break; //std::cout << "HandleInternalMessage got a message from " << message->network << " and it was unhandled!" << std::endl; } +} + +void Device::updateLEDState() { + auto msg = std::make_shared(); + msg->network = Network::NetID::Device; + /* NetID::Device is a super old command type. + * It has a leading 0x00 byte, a byte for command, and a byte for an argument. + * In this case, command 0x06 is SetLEDState. + * This old command type is not really used anywhere else. + */ + msg->data = {0x00, 0x06, uint8_t(ledState)}; + auto packet = com->encoder->encode(msg); + com->sendPacket(packet); } \ No newline at end of file diff --git a/device/include/device.h b/device/include/device.h index 51cac76..89a8391 100644 --- a/device/include/device.h +++ b/device/include/device.h @@ -72,6 +72,14 @@ private: neodevice_t data; std::shared_ptr latestResetStatus; + enum class LEDState : uint8_t { + Offline = 0x04, + CoreMiniRunning = 0x08, // This should override "offline" if the CoreMini is running + Online = 0x10 + }; + LEDState ledState; + void updateLEDState(); + size_t pollingMessageLimit = 20000; moodycamel::ConcurrentQueue> pollingContainer; void enforcePollingMessageLimit();