diff --git a/src/network/connection.cpp b/src/network/connection.cpp index dd906df26..741842100 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -347,6 +347,14 @@ void Connection::sendAcknowledgeConfigChange( )); } +void Connection::sendAcknowledgeIdentification(uint8_t sensorId, bool on) { + MUST(m_Connected); + MUST(sendPacket( + SendPacketType::AcknowledgeIdentificiation, + IdentificationPacket{.sensorId = sensorId, .on = on} + )); +} + void Connection::sendTrackerDiscovery() { MUST(!m_Connected); MUST(sendPacketCallback( @@ -763,6 +771,24 @@ void Connection::update() { configuration.save(); break; } + + case ReceivePacketType::Identification: { + IdentificationPacket packet{}; + + // TODO: do something with sensorId, currently we don't have a way + // to light up a LED on an extension, even if it had one, instead + // for the time being it will just light up the main LED + + memcpy(&packet, m_Packet + 12, sizeof(packet)); + if (packet.on) { + ledManager.forceOn(); + } else { + ledManager.forceOff(); + } + + sendAcknowledgeIdentification(packet.sensorId, packet.on); + break; + } } } diff --git a/src/network/connection.h b/src/network/connection.h index dc7d26c1d..544f285ce 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -213,6 +213,8 @@ class Connection { void sendAcknowledgeConfigChange(uint8_t sensorId, SensorToggles configType); + void sendAcknowledgeIdentification(uint8_t sensorId, bool on); + bool m_Connected = false; SlimeVR::Logging::Logger m_Logger = SlimeVR::Logging::Logger("UDPConnection"); diff --git a/src/network/packets.h b/src/network/packets.h index fcff747d4..ec167b867 100644 --- a/src/network/packets.h +++ b/src/network/packets.h @@ -54,6 +54,7 @@ enum class SendPacketType : uint8_t { // RotationAcceleration = 23, AcknowledgeConfigChange = 24, FlexData = 26, + AcknowledgeIdentificiation = 28, Bundle = 100, Inspection = 105, }; @@ -68,6 +69,7 @@ enum class ReceivePacketType : uint8_t { SensorInfo = 15, FeatureFlags = 22, SetConfigFlag = 25, + Identification = 28, }; enum class InspectionPacketType : uint8_t { @@ -230,6 +232,11 @@ struct SetConfigFlagPacket { bool newState{}; }; +struct IdentificationPacket { + uint8_t sensorId{}; + bool on{}; +}; + #pragma pack(pop) #endif // SLIMEVR_PACKETS_H_ diff --git a/src/status/LEDManager.cpp b/src/status/LEDManager.cpp index c8a8f6493..1beb6a8bb 100644 --- a/src/status/LEDManager.cpp +++ b/src/status/LEDManager.cpp @@ -37,24 +37,50 @@ void LEDManager::setup() { } void LEDManager::on() { + if (forcedOn) { + return; + } + if (m_Enabled) { digitalWrite(m_Pin, m_On); } } void LEDManager::off() { + if (forcedOn) { + return; + } + if (m_Enabled) { digitalWrite(m_Pin, m_Off); } } +void LEDManager::forceOn() { + on(); + forcedOn = true; +} + +void LEDManager::forceOff() { + forcedOn = false; + off(); +} + void LEDManager::blink(unsigned long time) { + if (forcedOn) { + return; + } + on(); delay(time); off(); } void LEDManager::pattern(unsigned long timeon, unsigned long timeoff, int times) { + if (forcedOn) { + return; + } + for (int i = 0; i < times; i++) { blink(timeon); delay(timeoff); diff --git a/src/status/LEDManager.h b/src/status/LEDManager.h index 9c6b1afba..2f7ba1b18 100644 --- a/src/status/LEDManager.h +++ b/src/status/LEDManager.h @@ -63,6 +63,9 @@ class LEDManager { */ void off(); + void forceOn(); + void forceOff(); + /*! * @brief Blink the LED for [time]ms. *Can* cause lag * @param time Amount of ms to turn the LED on @@ -84,6 +87,7 @@ class LEDManager { unsigned long m_Timer = 0; LEDStage m_CurrentStage = OFF; unsigned long m_LastUpdate = millis(); + bool forcedOn = false; uint8_t m_Pin = LED_PIN; bool m_Enabled = m_Pin >= 0 && m_Pin < LED_OFF;