Skip to content

Commit 01a7113

Browse files
authored
connect the seven segment reloaded usermod to BH1750 usermod (wled#4503)
1 parent a421a90 commit 01a7113

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

usermods/seven_segment_display_reloaded/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Very loosely based on the existing usermod "seven segment display".
99

1010
Add the compile-time option `-D USERMOD_SSDR` to your `platformio.ini` (or `platformio_override.ini`) or use `#define USERMOD_SSDR` in `my_config.h`.
1111

12-
For the auto brightness option, the usermod SN_Photoresistor has to be installed as well. See SN_Photoresistor/readme.md for instructions.
12+
For the auto brightness option, the usermod SN_Photoresistor or BH1750_V2 has to be installed as well. See SN_Photoresistor/readme.md or BH1750_V2/readme.md for instructions.
1313

1414
## Settings
1515
All settings can be controlled via the usermod settings page.
@@ -28,10 +28,10 @@ Enables the blinking colon(s) if they are defined
2828
Shows the leading zero of the hour if it exists (i.e. shows `07` instead of `7`)
2929

3030
### enable-auto-brightness
31-
Enables the auto brightness feature. Can be used only when the usermod SN_Photoresistor is installed.
31+
Enables the auto brightness feature. Can be used only when the usermods SN_Photoresistor or BH1750_V2 are installed.
3232

3333
### auto-brightness-min / auto-brightness-max
34-
The lux value calculated from usermod SN_Photoresistor will be mapped to the values defined here.
34+
The lux value calculated from usermod SN_Photoresistor or BH1750_V2 will be mapped to the values defined here.
3535
The mapping, 0 - 1000 lux, will be mapped to auto-brightness-min and auto-brightness-max
3636

3737
WLED current protection will override the calculated value if it is too high.

usermods/seven_segment_display_reloaded/usermod_seven_segment_reloaded.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class UsermodSSDR : public Usermod {
9797
#else
9898
void* ptr = nullptr;
9999
#endif
100+
#ifdef USERMOD_BH1750
101+
Usermod_BH1750* bh1750 = nullptr;
102+
#else
103+
void* bh1750 = nullptr;
104+
#endif
100105

101106
void _overlaySevenSegmentDraw() {
102107
int displayMaskLen = static_cast<int>(umSSDRDisplayMask.length());
@@ -387,6 +392,9 @@ class UsermodSSDR : public Usermod {
387392
#ifdef USERMOD_SN_PHOTORESISTOR
388393
ptr = (Usermod_SN_Photoresistor*) UsermodManager::lookup(USERMOD_ID_SN_PHOTORESISTOR);
389394
#endif
395+
#ifdef USERMOD_BH1750
396+
bh1750 = (Usermod_BH1750*) UsermodManager::lookup(USERMOD_ID_BH1750);
397+
#endif
390398
DEBUG_PRINTLN(F("Setup done"));
391399
}
392400

@@ -410,6 +418,20 @@ class UsermodSSDR : public Usermod {
410418
umSSDRLastRefresh = millis();
411419
}
412420
#endif
421+
#ifdef USERMOD_BH1750
422+
if(bri != 0 && umSSDREnableLDR && (millis() - umSSDRLastRefresh > umSSDRResfreshTime)) {
423+
if (bh1750 != nullptr) {
424+
float lux = bh1750->getIlluminance();
425+
uint16_t brightness = map(lux, 0, 1000, umSSDRBrightnessMin, umSSDRBrightnessMax);
426+
if (bri != brightness) {
427+
DEBUG_PRINTF("Adjusting brightness based on lux value: %.2f lx, new brightness: %d\n", lux, brightness);
428+
bri = brightness;
429+
stateUpdated(1);
430+
}
431+
}
432+
umSSDRLastRefresh = millis();
433+
}
434+
#endif
413435
}
414436

415437
void handleOverlayDraw() {

0 commit comments

Comments
 (0)