LED state changing (Device LEDs work now)

pull/4/head
Paul Hollinsky 2018-10-17 16:15:15 -04:00
parent 4426334f3f
commit b4fc3edd0f
3 changed files with 30 additions and 0 deletions

View File

@ -24,6 +24,9 @@ std::vector<uint8_t> Encoder::encode(const std::shared_ptr<Message>& 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

View File

@ -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> 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<Message>();
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);
}

View File

@ -72,6 +72,14 @@ private:
neodevice_t data;
std::shared_ptr<ResetStatusMessage> 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<std::shared_ptr<Message>> pollingContainer;
void enforcePollingMessageLimit();