Skip to content

Commit a8ec9c0

Browse files
authored
fix for derqurps findings
1 parent 90229e3 commit a8ec9c0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@
407407

408408
if (lux >= 0) { // Ensure we got a valid lux value
409409
uint16_t brightness;
410+
411+
// Constrain lux values within defined range
412+
float constrainedLux = constrain(lux, umSSDRLuxMin, umSSDRLuxMax);
413+
410414
// float linear interpolation to preserve full 0–255 resolution
411415
float spanLux = umSSDRLuxMax - umSSDRLuxMin;
412416
float spanBright = umSSDRBrightnessMax - umSSDRBrightnessMin;
@@ -417,7 +421,7 @@
417421
} else {
418422
brightness = static_cast<uint16_t>((1.0f - ratio) * spanBright + umSSDRBrightnessMin);
419423
}
420-
_logUsermodSSDR("Lux=%.2f?brightness=%d",lux,br);
424+
_logUsermodSSDR("Lux=%.2f brightness=%d", lux, brightness)
421425

422426
if (bri != brightness) {
423427
_logUsermodSSDR("Adjusting brightness based on lux value: %.2f lx, new brightness: %d", lux, brightness);

usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,23 @@ class UsermodSSDR : public Usermod {
180180
int _checkForNumber(int count, int index, String *map);
181181
void _publishMQTTint_P(const char *subTopic, int value);
182182
void _publishMQTTstr_P(const char *subTopic, String Value);
183-
bool _cmpIntSetting_P(char *topic, char *payload, const char *setting, void *value);
183+
184+
template<typename T>
185+
bool _cmpIntSetting_P(char *topic, char *payload, const char *setting, T *value) {
186+
char settingBuffer[30];
187+
strlcpy(settingBuffer, setting, sizeof(settingBuffer));
188+
189+
_logUsermodSSDR("Checking topic='%s' payload='%s' against setting='%s'", topic, payload, settingBuffer);
190+
191+
if (strcmp(topic, settingBuffer) != 0) return false;
192+
193+
T oldValue = *value;
194+
*value = static_cast<T>(strtol(payload, nullptr, 10));
195+
_publishMQTTint_P(setting, static_cast<int>(*value));
196+
_logUsermodSSDR("Setting '%s' updated from %d to %d", setting, static_cast<int>(oldValue), static_cast<int>(*value));
197+
return true;
198+
}
199+
184200
bool _handleSetting(char *topic, char *payload);
185201
void _updateMQTT();
186202
void _addJSONObject(JsonObject& root);

0 commit comments

Comments
 (0)