summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Jones <daniel@danieljon.es>2024-10-20 14:36:03 +1100
committerDaniel Jones <daniel@danieljon.es>2024-10-20 14:36:03 +1100
commitc9b207f282a366356084732ef1178e186d1d9f8b (patch)
treea3ecf28f6f9dfdb985b28c25ed0b35c0183f2fcd /src
parent0eddc06ca0f38c7ea14b727f19b4943b35392c6b (diff)
use bitfield for brightness
use bitfields for brightness settings in a hope to not corrupt existing settings saved on device
Diffstat (limited to 'src')
-rwxr-xr-xsrc/matrixdisplay.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/matrixdisplay.cpp b/src/matrixdisplay.cpp
index acb26ca..cc3fddb 100755
--- a/src/matrixdisplay.cpp
+++ b/src/matrixdisplay.cpp
@@ -54,12 +54,17 @@ IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
WebServer server(80);
+struct brightness
+{
+ unsigned int autoBrightness : 1;
+ unsigned int brightness : 4;
+ unsigned int RESERVED : 27;
+};
+
struct
{
int pos;
- int brightness;
- bool autoBrightness;
- int autoBrightnessValue;
+ struct brightness brightness;
char cssid[256];
char cpassword[256];
char date[32];
@@ -126,8 +131,8 @@ void handlein()
String cssid = jsonDocument["cssid"];
String cpassword = jsonDocument["cpassword"];
String date = jsonDocument["datep"];
- globalconf.brightness = brightness;
- globalconf.autoBrightness = autoBrightness;
+ globalconf.brightness.brightness = brightness;
+ globalconf.brightness.autoBrightness = autoBrightness;
strncpy(globalconf.cssid, cssid.c_str(), 256);
strncpy(globalconf.cpassword, cpassword.c_str(), 256);
strncpy(globalconf.date, date.c_str(), 32);
@@ -201,8 +206,8 @@ char wifistatus[32] = {0};
void handleconfigout()
{
jsonDocument.clear();
- jsonDocument["brightness"] = globalconf.brightness;
- jsonDocument["autoBrightness"] = globalconf.autoBrightness;
+ jsonDocument["brightness"] = globalconf.brightness.brightness;
+ jsonDocument["autoBrightness"] = globalconf.brightness.autoBrightness;
jsonDocument["cssid"] = globalconf.cssid;
jsonDocument["cpassword"] = globalconf.cpassword;
jsonDocument["datep"] = globalconf.date;
@@ -399,7 +404,7 @@ void setup()
esp_log_level_set("*", ESP_LOG_VERBOSE);
preferences.begin("matrixdisplay", false);
globalconf.pos = 0;
- globalconf.brightness = 7;
+ globalconf.brightness.brightness = 7;
Serial.begin(115200);
// Intialize the object
myDisplay.begin();
@@ -450,8 +455,8 @@ void loadconfig()
void defaultdata()
{
globalconf.pos = 0;
- globalconf.brightness = 4;
- globalconf.autoBrightness = false;
+ globalconf.brightness.brightness = 4;
+ globalconf.brightness.autoBrightness = false;
strncpy(globalconf.cssid, "Gensokyo", 256);
strncpy(globalconf.cpassword, "passwordhere", 256);
strncpy(globalconf.date, "0", 32);
@@ -585,7 +590,7 @@ void nextmessage()
#ifdef VERTICAL
strrev(msgbuff);
#endif
- if (globalconf.autoBrightness)
+ if (globalconf.brightness.autoBrightness)
{
int lightValue = analogRead(LIGHT_SENSOR_PIN);
int brightness = map(lightValue, 0, 950, 0, 15); // Map the light value to brightness range (0-15)
@@ -594,7 +599,7 @@ void nextmessage()
myDisplay.setIntensity(brightness);
} else
{
- myDisplay.setIntensity(globalconf.brightness);
+ myDisplay.setIntensity(globalconf.brightness.brightness);
}
myDisplay.setInvert(messages[globalconf.pos].invert);
scrollAlign = PA_CENTER;