From bce33a2ec11142841f7c4c0602d932d07af2140c Mon Sep 17 00:00:00 2001 From: gorbit99 Date: Mon, 5 May 2025 22:40:29 +0200 Subject: [PATCH 1/3] Add ID Command --- src/LEDManager.cpp | 26 ++++++++++++++++++++++++++ src/LEDManager.h | 4 ++++ src/network/connection.cpp | 10 ++++++++++ src/network/packets.h | 5 +++++ 4 files changed, 45 insertions(+) diff --git a/src/LEDManager.cpp b/src/LEDManager.cpp index 51ef864f1..67c009c68 100644 --- a/src/LEDManager.cpp +++ b/src/LEDManager.cpp @@ -37,24 +37,50 @@ void LEDManager::setup() { } void LEDManager::on() { + if (forcedOn) { + return; + } + #if ENABLE_LEDS digitalWrite(m_Pin, LED__ON); #endif } void LEDManager::off() { + if (forcedOn) { + return; + } + #if ENABLE_LEDS digitalWrite(m_Pin, LED__OFF); #endif } +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/LEDManager.h b/src/LEDManager.h index 1d30cb2bd..87e3e21a5 100644 --- a/src/LEDManager.h +++ b/src/LEDManager.h @@ -66,6 +66,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 @@ -87,6 +90,7 @@ class LEDManager { unsigned long m_Timer = 0; LEDStage m_CurrentStage = OFF; unsigned long m_LastUpdate = millis(); + bool forcedOn = false; uint8_t m_Pin; diff --git a/src/network/connection.cpp b/src/network/connection.cpp index dd906df26..904fa2e8e 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -763,6 +763,16 @@ void Connection::update() { configuration.save(); break; } + + case ReceivePacketType::Identification: { + IdentificationPacket packet{}; + memcpy(&packet, m_Packet + 12, sizeof(packet)); + if (packet.on) { + ledManager.forceOn(); + } else { + ledManager.forceOff(); + } + } } } diff --git a/src/network/packets.h b/src/network/packets.h index fcff747d4..459b6ffc4 100644 --- a/src/network/packets.h +++ b/src/network/packets.h @@ -68,6 +68,7 @@ enum class ReceivePacketType : uint8_t { SensorInfo = 15, FeatureFlags = 22, SetConfigFlag = 25, + Identification = 28, }; enum class InspectionPacketType : uint8_t { @@ -230,6 +231,10 @@ struct SetConfigFlagPacket { bool newState{}; }; +struct IdentificationPacket { + bool on; +} + #pragma pack(pop) #endif // SLIMEVR_PACKETS_H_ From 70347d4a802ad9ea27c9a9550fbfd6e90849d4b9 Mon Sep 17 00:00:00 2001 From: gorbit99 Date: Mon, 5 May 2025 23:04:27 +0200 Subject: [PATCH 2/3] Acknowledge packet --- src/network/connection.cpp | 16 ++++++++++++++++ src/network/connection.h | 2 ++ src/network/packets.h | 4 +++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 904fa2e8e..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( @@ -766,12 +774,20 @@ void Connection::update() { 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 459b6ffc4..1f4bad691 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, }; @@ -232,7 +233,8 @@ struct SetConfigFlagPacket { }; struct IdentificationPacket { - bool on; + uint8_t sensorId{}; + bool on{}; } #pragma pack(pop) From 7ec0d58198da19ef62feced0c4a79a8ee62f3afc Mon Sep 17 00:00:00 2001 From: gorbit99 Date: Mon, 5 May 2025 23:18:14 +0200 Subject: [PATCH 3/3] Oops --- src/network/packets.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/packets.h b/src/network/packets.h index 1f4bad691..ec167b867 100644 --- a/src/network/packets.h +++ b/src/network/packets.h @@ -235,7 +235,7 @@ struct SetConfigFlagPacket { struct IdentificationPacket { uint8_t sensorId{}; bool on{}; -} +}; #pragma pack(pop)