From 0eddc06ca0f38c7ea14b727f19b4943b35392c6b Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sun, 20 Oct 2024 12:25:36 +1100 Subject: auto brightness add option to control brightness automatically from an LDR on pin 34. Note this adds a new value to the globalconf structure, so this breaks the layout of stored settings and will break them all. --- html/index.html | 3 +++ src/index.h | 3 +++ src/matrixdisplay.cpp | 24 ++++++++++++++++++++++-- src/networking.cpp | 0 4 files changed, 28 insertions(+), 2 deletions(-) delete mode 100644 src/networking.cpp diff --git a/html/index.html b/html/index.html index 20e7387..ef9778b 100755 --- a/html/index.html +++ b/html/index.html @@ -216,6 +216,8 @@
+ +


@@ -379,6 +381,7 @@ */ document.getElementById("brightness").value = data.brightness; + document.getElementById("autoBrightness").checked = data.autoBrightness; document.getElementById("cssid").value = data["cssid"]; document.getElementById("cpassword").value = data["cpassword"]; document.getElementById("datep").valueAsDate = new Date(data["datep"]); diff --git a/src/index.h b/src/index.h index 9a8edf3..92109b0 100755 --- a/src/index.h +++ b/src/index.h @@ -217,6 +217,8 @@ const char index_html[] PROGMEM = R"rawliteral(
+ +


@@ -380,6 +382,7 @@ const char index_html[] PROGMEM = R"rawliteral( */ document.getElementById("brightness").value = data.brightness; + document.getElementById("autoBrightness").checked = data.autoBrightness; document.getElementById("cssid").value = data["cssid"]; document.getElementById("cpassword").value = data["cpassword"]; document.getElementById("datep").valueAsDate = new Date(data["datep"]); diff --git a/src/matrixdisplay.cpp b/src/matrixdisplay.cpp index f54eefe..acb26ca 100755 --- a/src/matrixdisplay.cpp +++ b/src/matrixdisplay.cpp @@ -58,6 +58,8 @@ struct { int pos; int brightness; + bool autoBrightness; + int autoBrightnessValue; char cssid[256]; char cpassword[256]; char date[32]; @@ -88,6 +90,8 @@ struct message messages[NUM_MESSAGES] = {0}; MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); +#define LIGHT_SENSOR_PIN GPIO_NUM_34 + void handleroot() { server.send(200, "text/html", index_html); @@ -118,10 +122,12 @@ void handlein() String body = server.arg("plain"); deserializeJson(jsonDocument, body); int brightness = jsonDocument["brightness"]; + bool autoBrightness = jsonDocument["autoBrightness"]; String cssid = jsonDocument["cssid"]; String cpassword = jsonDocument["cpassword"]; String date = jsonDocument["datep"]; globalconf.brightness = brightness; + globalconf.autoBrightness = autoBrightness; strncpy(globalconf.cssid, cssid.c_str(), 256); strncpy(globalconf.cpassword, cpassword.c_str(), 256); strncpy(globalconf.date, date.c_str(), 32); @@ -196,6 +202,7 @@ void handleconfigout() { jsonDocument.clear(); jsonDocument["brightness"] = globalconf.brightness; + jsonDocument["autoBrightness"] = globalconf.autoBrightness; jsonDocument["cssid"] = globalconf.cssid; jsonDocument["cpassword"] = globalconf.cpassword; jsonDocument["datep"] = globalconf.date; @@ -416,6 +423,8 @@ void setup() 0); /* pin task to core 0 */ myDisplay.setTextAlignment(PA_LEFT); + + pinMode(LIGHT_SENSOR_PIN, INPUT); } void saveconfig() { @@ -442,6 +451,7 @@ void defaultdata() { globalconf.pos = 0; globalconf.brightness = 4; + globalconf.autoBrightness = false; strncpy(globalconf.cssid, "Gensokyo", 256); strncpy(globalconf.cpassword, "passwordhere", 256); strncpy(globalconf.date, "0", 32); @@ -575,7 +585,17 @@ void nextmessage() #ifdef VERTICAL strrev(msgbuff); #endif - myDisplay.setIntensity(globalconf.brightness); + if (globalconf.autoBrightness) + { + int lightValue = analogRead(LIGHT_SENSOR_PIN); + int brightness = map(lightValue, 0, 950, 0, 15); // Map the light value to brightness range (0-15) + printf("light value: %d\n", lightValue); + printf("Brightness: %d\n", brightness); + myDisplay.setIntensity(brightness); + } else + { + myDisplay.setIntensity(globalconf.brightness); + } myDisplay.setInvert(messages[globalconf.pos].invert); scrollAlign = PA_CENTER; myDisplay.displayText(msgbuff, scrollAlign, messages[globalconf.pos].speed, messages[globalconf.pos].scrollpause * 1000, messages[globalconf.pos].effect1, messages[globalconf.pos].effect2); @@ -589,4 +609,4 @@ void loop() nextmessage(); myDisplay.displayReset(); } -} \ No newline at end of file +} diff --git a/src/networking.cpp b/src/networking.cpp deleted file mode 100644 index e69de29..0000000 -- cgit v1.2.3