From 15682ae9d22575078372e6713ca04392f401d651 Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Tue, 28 Jan 2020 13:47:26 -0800 Subject: [PATCH] photontelemetry: publish events, ignoring duplicates --- firmware/PhotonTelemetry.cpp | 14 +++++++++++--- firmware/PhotonTelemetry.h | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/firmware/PhotonTelemetry.cpp b/firmware/PhotonTelemetry.cpp index cd8ab33..46bb34e 100644 --- a/firmware/PhotonTelemetry.cpp +++ b/firmware/PhotonTelemetry.cpp @@ -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); } diff --git a/firmware/PhotonTelemetry.h b/firmware/PhotonTelemetry.h index 1e9a137..f209b45 100644 --- a/firmware/PhotonTelemetry.h +++ b/firmware/PhotonTelemetry.h @@ -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; };