fix brightness event spam, add configuration backdoor in mqtt events

This commit is contained in:
Torrie Fischer 2021-03-28 17:18:03 -07:00
parent 92d5e73bd8
commit 9a3bf84214
3 changed files with 23 additions and 5 deletions

View File

@ -60,8 +60,6 @@ ConfigService::onStart()
m_config.save(); m_config.save();
} }
m_coordMap = m_config.toCoordMap(); 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_pixelCount = AnimatedNumber{max(1, m_coordMap.pixelCount)};
m_startPixel = AnimatedNumber{max(0, m_coordMap.startPixel)}; m_startPixel = AnimatedNumber{max(0, m_coordMap.startPixel)};

View File

@ -3,15 +3,19 @@
#include "./Figments/Figments.h" #include "./Figments/Figments.h"
struct HardwareConfig { struct HardwareConfig {
uint8_t version = 1; uint8_t version = 2;
uint8_t checksum = 0; uint8_t checksum = 0;
struct TaskState { struct TaskState {
char name[16] = {0}; char name[16] = {0};
bool isRunning = false; bool isDisabled = false;
}; };
struct Data { struct Data {
uint16_t pixelCount = 255; uint16_t pixelCount = 255;
uint16_t startPixel = 0; uint16_t startPixel = 0;
uint8_t lastRed = 255;
uint8_t lastGreen = 255;
uint8_t lastBlue = 255;
char lastScene[16] = {0};
TaskState serviceStates[32]; TaskState serviceStates[32];
}; };
Data data; Data data;

View File

@ -37,7 +37,8 @@ using namespace NSFastLED;
#define MAX_BRIGHTNESS 255 #define MAX_BRIGHTNESS 255
//#define PSU_MILLIAMPS 4800 //#define PSU_MILLIAMPS 4800
//#define PSU_MILLIAMPS 500 //#define PSU_MILLIAMPS 500
#define PSU_MILLIAMPS 1000 //#define PSU_MILLIAMPS 1000
#define PSU_MILLIAMPS 2000
// Enable system thread, so rendering happens while booting // Enable system thread, so rendering happens while booting
SYSTEM_THREAD(ENABLED); SYSTEM_THREAD(ENABLED);
@ -276,6 +277,8 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
writer.name("SSID").value(WiFi.SSID()); writer.name("SSID").value(WiFi.SSID());
//writer.name("MAC").value(WiFi.macAddress()); //writer.name("MAC").value(WiFi.macAddress());
writer.name("localip").value(WiFi.localIP().toString()); writer.name("localip").value(WiFi.localIP().toString());
writer.name("startPixel").value(Static<ConfigService>::instance()->coordMap()->startPixel);
writer.name("pixelCount").value(Static<ConfigService>::instance()->coordMap()->pixelCount);
writer.endObject(); writer.endObject();
writer.buffer()[std::min(writer.bufferSize(), writer.dataSize())] = 0; writer.buffer()[std::min(writer.bufferSize(), writer.dataSize())] = 0;
m_client.publish(m_attrTopic, heartbeatBuf); m_client.publish(m_attrTopic, heartbeatBuf);
@ -369,6 +372,18 @@ class MQTTTelemetry : public BufferedInputSource, OnlineTaskMixin {
strcpy(m_patternBuf, (const char*) cmdIter.value().toString()); strcpy(m_patternBuf, (const char*) cmdIter.value().toString());
setEvent(InputEvent{InputEvent::SetPattern, m_patternBuf}); 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; needsUpdate = true;
} }
if (needsUpdate) { if (needsUpdate) {
needsUpdate = false;
return InputEvent{InputEvent::SetBrightness, brightnessForTime(Time.hour(), Time.minute())}; return InputEvent{InputEvent::SetBrightness, brightnessForTime(Time.hour(), Time.minute())};
} }
} }