diff options
author | Daniel Jones <daniel@danieljon.es> | 2024-10-20 12:25:36 +1100 |
---|---|---|
committer | Daniel Jones <daniel@danieljon.es> | 2024-10-20 12:25:36 +1100 |
commit | 0eddc06ca0f38c7ea14b727f19b4943b35392c6b (patch) | |
tree | 9ca76623f8be1938e2876a09cf7a3b5d8a195ba0 | |
parent | 6a9b68e3ed234de9348d8dd1ba495422b819346d (diff) |
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.
-rwxr-xr-x | html/index.html | 3 | ||||
-rwxr-xr-x | src/index.h | 3 | ||||
-rwxr-xr-x | src/matrixdisplay.cpp | 24 | ||||
-rw-r--r-- | src/networking.cpp | 0 |
4 files changed, 28 insertions, 2 deletions
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 @@ <input type="date" id="datep" name="datep"><br> <label for="brightness">Brightness:</label> <input type="range" min="0" max="15" value="3" class="slider" name="brightness" id="brightness"> + <label for="autoBrightness">Auto Brightness:</label> + <input type="checkbox" id="autoBrightness" name="autoBrightness" value="autoBrightness"><br><br> <input class="block" type="submit" value="Save"> <br> <div style="overflow-y: scroll; height:400px;"> @@ -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( <input type="date" id="datep" name="datep"><br> <label for="brightness">Brightness:</label> <input type="range" min="0" max="15" value="3" class="slider" name="brightness" id="brightness"> + <label for="autoBrightness">Auto Brightness:</label> + <input type="checkbox" id="autoBrightness" name="autoBrightness" value="autoBrightness"><br><br> <input class="block" type="submit" value="Save"> <br> <div style="overflow-y: scroll; height:400px;"> @@ -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 --- a/src/networking.cpp +++ /dev/null |