Skip to content

Add id command #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/network/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/network/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
7 changes: 7 additions & 0 deletions src/network/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum class SendPacketType : uint8_t {
// RotationAcceleration = 23,
AcknowledgeConfigChange = 24,
FlexData = 26,
AcknowledgeIdentificiation = 28,
Bundle = 100,
Inspection = 105,
};
Expand All @@ -68,6 +69,7 @@ enum class ReceivePacketType : uint8_t {
SensorInfo = 15,
FeatureFlags = 22,
SetConfigFlag = 25,
Identification = 28,
};

enum class InspectionPacketType : uint8_t {
Expand Down Expand Up @@ -230,6 +232,11 @@ struct SetConfigFlagPacket {
bool newState{};
};

struct IdentificationPacket {
uint8_t sensorId{};
bool on{};
};

#pragma pack(pop)

#endif // SLIMEVR_PACKETS_H_
26 changes: 26 additions & 0 deletions src/status/LEDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/status/LEDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down