From ea504f5d0cfc1a5c1c7bfa712cd6aa78f14e7a41 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Fri, 18 Oct 2024 10:29:52 +0200 Subject: [PATCH 1/2] Fixed building for ESP32 --- include/clockWork.h | 2 +- include/clockWork.hpp | 9 +++++++-- platformio.ini | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/clockWork.h b/include/clockWork.h index 3504f71..123a844 100644 --- a/include/clockWork.h +++ b/include/clockWork.h @@ -13,7 +13,7 @@ class ClockWork { }; stateBH1750Type stateBH1750 = stateBH1750Type::toBeInitialized; float lux = 0.0; - uint16 adcValue0Lux = 10; // Hier wird der niedrigste LDR-ADC Wert getrackt, + uint16_t adcValue0Lux = 10; // Hier wird der niedrigste LDR-ADC Wert getrackt, // für eine dynamische offset korrektur bei 0 LUX private: diff --git a/include/clockWork.hpp b/include/clockWork.hpp index 12ed820..75d5e04 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -39,7 +39,7 @@ void ClockWork::loopAutoBrightLogic() { // Using legacy LDR for ambient light measurement // Electrical circuit = voltage divider: 3.3V--LDR-->ADC<--220 // Ohm--GND - uint16 adcValue = analogRead( + uint16_t adcValue = analogRead( A0); // Read out ADC, pin TOUT = 0.0V - 1.0V = adcValue 0-1023 // Track lowest ADC value for offest correction at 0 LUX if (adcValue < adcValue0Lux) @@ -60,7 +60,8 @@ void ClockWork::loopAutoBrightLogic() { // aBS=16 then ledGain should reach 100.0% at 500.0 LUX. ledGain = (lux * (float)(G.autoBrightSlope + 1)) / 80.0; // Add autoBrightOffset 0-255 - ledGain += ((uint16)100 * (uint16)G.autoBrightOffset) / (uint16)255; + ledGain += + ((uint16_t)100 * (uint16_t)G.autoBrightOffset) / (uint16_t)255; if (ledGain > 100.0) ledGain = 100.0; } @@ -73,7 +74,11 @@ void ClockWork::loopAutoBrightLogic() { // Initialize the I2C bus using SCL and SDA pins // (BH1750 library doesn't do this automatically) void ClockWork::initBH1750Logic() { +#ifdef ESP8266 Wire.begin(D4, D3); +#elif defined(ESP32) + Wire.begin(21, 22); +#endif // begin returns a boolean that can be used to detect setup problems. if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) { Serial.println("BH1750 initialized. Using this sensor for ambient " diff --git a/platformio.ini b/platformio.ini index 7e9b3e2..01c9c04 100644 --- a/platformio.ini +++ b/platformio.ini @@ -48,4 +48,5 @@ lib_deps = adafruit/RTClib@^1.11.2 knolleary/PubSubClient@^2.8.0 https://github.com/tzapu/WiFiManager#v2.0.17 + claws/BH1750@^1.3.0 extra_scripts = pre:extra_scripts.py \ No newline at end of file From 23f620c039de36d263b90e380e4005e4c78076d1 Mon Sep 17 00:00:00 2001 From: David Panusch Date: Fri, 18 Oct 2024 10:31:26 +0200 Subject: [PATCH 2/2] Clang formatted --- include/clockWork.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/clockWork.h b/include/clockWork.h index 123a844..8553f52 100644 --- a/include/clockWork.h +++ b/include/clockWork.h @@ -13,8 +13,9 @@ class ClockWork { }; stateBH1750Type stateBH1750 = stateBH1750Type::toBeInitialized; float lux = 0.0; - uint16_t adcValue0Lux = 10; // Hier wird der niedrigste LDR-ADC Wert getrackt, - // für eine dynamische offset korrektur bei 0 LUX + uint16_t adcValue0Lux = + 10; // Hier wird der niedrigste LDR-ADC Wert getrackt, + // für eine dynamische offset korrektur bei 0 LUX private: //------------------------------------------------------------------------------