From 9a3bf842143e62bfa04c5b280f4bbe2e60fa8602 Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Sun, 28 Mar 2021 17:18:03 -0700 Subject: [PATCH] fix brightness event spam, add configuration backdoor in mqtt events --- firmware/Config.cpp | 2 -- firmware/Config.h | 8 ++++++-- firmware/main.cpp | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/firmware/Config.cpp b/firmware/Config.cpp index b9aee18..5966582 100644 --- a/firmware/Config.cpp +++ b/firmware/Config.cpp @@ -60,8 +60,6 @@ ConfigService::onStart() m_config.save(); } m_coordMap = m_config.toCoordMap(); - //m_coordMap.pixelCount = min(HardwareConfig::MAX_LED_NUM, max(1, m_config.data.pixelCount)); - //m_coordMap.startPixel = min(m_coordMap.pixelCount, max(0, m_config.data.startPixel)); m_pixelCount = AnimatedNumber{max(1, m_coordMap.pixelCount)}; m_startPixel = AnimatedNumber{max(0, m_coordMap.startPixel)}; diff --git a/firmware/Config.h b/firmware/Config.h index 875f200..23fc211 100644 --- a/firmware/Config.h +++ b/firmware/Config.h @@ -3,15 +3,19 @@ #include "./Figments/Figments.h" struct HardwareConfig { - uint8_t version = 1; + uint8_t version = 2; uint8_t checksum = 0; struct TaskState { char name[16] = {0}; - bool isRunning = false; + bool isDisabled = false; }; struct Data { uint16_t pixelCount = 255; uint16_t startPixel = 0; + uint8_t lastRed = 255; + uint8_t lastGreen = 255; + uint8_t lastBlue = 255; + char lastScene[16] = {0}; TaskState serviceStates[32]; }; Data data; diff --git a/firmware/main.cpp b/firmware/main.cpp index 4bddb56..91b2461 100644 --- a/firmware/main.cpp +++ b/firmware/main.cpp @@ -37,7 +37,8 @@ using namespace NSFastLED; #define MAX_BRIGHTNESS 255 //#define PSU_MILLIAMPS 4800 //#define PSU_MILLIAMPS 500 -#define PSU_MILLIAMPS 1000 +//#define PSU_MILLIAMPS 1000 +#define PSU_MILLIAMPS 2000 // Enable system thread, so rendering happens while booting SYSTEM_THREAD(ENABLED); @@ -276,6 +277,8 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin { writer.name("SSID").value(WiFi.SSID()); //writer.name("MAC").value(WiFi.macAddress()); writer.name("localip").value(WiFi.localIP().toString()); + writer.name("startPixel").value(Static::instance()->coordMap()->startPixel); + writer.name("pixelCount").value(Static::instance()->coordMap()->pixelCount); writer.endObject(); writer.buffer()[std::min(writer.bufferSize(), writer.dataSize())] = 0; m_client.publish(m_attrTopic, heartbeatBuf); @@ -369,6 +372,18 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin { strcpy(m_patternBuf, (const char*) cmdIter.value().toString()); setEvent(InputEvent{InputEvent::SetPattern, m_patternBuf}); } + + if (cmdIter.name() == "pixelCount") { + setEvent(InputEvent{InputEvent::SetDisplayLength, cmdIter.value().toInt()}); + } + + if (cmdIter.name() == "startPixel") { + setEvent(InputEvent{InputEvent::SetDisplayOffset, cmdIter.value().toInt()}); + } + + if (cmdIter.name() == "save") { + setEvent(InputEvent{InputEvent::SaveConfigurationRequest}); + } } } } @@ -557,6 +572,7 @@ InputFunc circadianRhythm([]() { needsUpdate = true; } if (needsUpdate) { + needsUpdate = false; return InputEvent{InputEvent::SetBrightness, brightnessForTime(Time.hour(), Time.minute())}; } }