photontelemetry: publish events, ignoring duplicates

This commit is contained in:
Torrie Fischer 2020-01-28 13:47:26 -08:00
parent 354b72f160
commit 15682ae9d2
2 changed files with 13 additions and 4 deletions

View File

@ -54,7 +54,6 @@ PhotonTelemetry::loop()
void
PhotonTelemetry::handleEvent(const InputEvent &evt)
{
m_lastEvent = evt;
if (evt.intent == InputEvent::NetworkStatus) {
onConnected();
}
@ -118,8 +117,17 @@ PhotonTelemetry::handleEvent(const InputEvent &evt)
char buf[255];
snprintf(buf, sizeof(buf), "{\"intent\": \"%s\", \"value\": %s}", sourceName, valueBuf);
if (m_online) {
Log.info("Event: %s", buf);
Particle.publish("renderbug/event", buf, PRIVATE);
if (evt.intent != m_lastEvent.intent) {
if (m_duplicateEvents > 0) {
Log.info("Suppressed reporting %d duplicate events.", m_duplicateEvents);
}
Log.info("Event: %s", buf);
m_duplicateEvents = 0;
m_lastEvent = evt;
Particle.publish("renderbug/event", buf, PRIVATE);
} else {
m_duplicateEvents++;
}
} else {
Log.info("[offline] Event: %s", buf);
}

View File

@ -12,12 +12,13 @@ private:
int m_frameIdx;
String m_serviceList;
InputEvent m_lastEvent;
uint32_t m_currentBrightness;
LEDStatus m_ledStatus = LEDStatus(0, LED_PATTERN_FADE, LED_SPEED_FAST);
uint32_t m_rgbPulseFrame = 0;
uint32_t m_pixelCount = 0;
uint32_t m_startPixel = 0;
uint32_t m_fps = 0;
uint32_t m_duplicateEvents = 0;
InputEvent m_lastEvent;
bool m_online = false;
};