LED state changing (Device LEDs work now)
parent
4426334f3f
commit
b4fc3edd0f
|
|
@ -24,6 +24,9 @@ std::vector<uint8_t> Encoder::encode(const std::shared_ptr<Message>& message) {
|
||||||
// }
|
// }
|
||||||
default:
|
default:
|
||||||
switch(message->network.getNetID()) {
|
switch(message->network.getNetID()) {
|
||||||
|
case Network::NetID::Device:
|
||||||
|
shortFormat = true;
|
||||||
|
break;
|
||||||
case Network::NetID::Main51:
|
case Network::NetID::Main51:
|
||||||
if(message->data.size() > 0xF) {
|
if(message->data.size() > 0xF) {
|
||||||
// Main51 can be sent as a long message without setting the NetID to RED first
|
// Main51 can be sent as a long message without setting the NetID to RED first
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,9 @@ bool Device::goOnline() {
|
||||||
if(!com->sendCommand(Command::EnableNetworkCommunication, true))
|
if(!com->sendCommand(Command::EnableNetworkCommunication, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
ledState = LEDState::Online;
|
||||||
|
updateLEDState();
|
||||||
|
|
||||||
online = true;
|
online = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -181,6 +184,9 @@ bool Device::goOffline() {
|
||||||
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
|
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
ledState = latestResetStatus->cmRunning ? LEDState::CoreMiniRunning : LEDState::Offline;
|
||||||
|
updateLEDState();
|
||||||
|
|
||||||
online = false;
|
online = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -193,4 +199,17 @@ void Device::handleInternalMessage(std::shared_ptr<Message> message) {
|
||||||
default:
|
default:
|
||||||
break; //std::cout << "HandleInternalMessage got a message from " << message->network << " and it was unhandled!" << std::endl;
|
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);
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +72,14 @@ private:
|
||||||
neodevice_t data;
|
neodevice_t data;
|
||||||
std::shared_ptr<ResetStatusMessage> latestResetStatus;
|
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;
|
size_t pollingMessageLimit = 20000;
|
||||||
moodycamel::ConcurrentQueue<std::shared_ptr<Message>> pollingContainer;
|
moodycamel::ConcurrentQueue<std::shared_ptr<Message>> pollingContainer;
|
||||||
void enforcePollingMessageLimit();
|
void enforcePollingMessageLimit();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue