Added storing GUI variables in the memory of the Core.
This commit is contained in:
parent
e76f6f8c68
commit
0aa636d957
|
@ -3,6 +3,13 @@
|
|||
#include <BluetoothSerial.h> // Bluetooth
|
||||
#include <M5Core2.h>
|
||||
#include "icons.cpp" // icons
|
||||
#include <Preferences.h>
|
||||
|
||||
// store screen mode and brightness in the memory of the Core
|
||||
Preferences preferences;
|
||||
const char* key1 = "lightDark";
|
||||
const char* key2 = "brightness";
|
||||
int lightMode;
|
||||
|
||||
// UART communication variables
|
||||
#define RX_PIN 19
|
||||
|
@ -11,7 +18,8 @@ String stringReceived = "";
|
|||
int valueReceived = 0;
|
||||
|
||||
// GUI variables
|
||||
int brightnessValue = 1;
|
||||
int brightnessValues[4] = {2500, 2750, 2900, 3150};
|
||||
int brightnessValue;
|
||||
ButtonColors noDraw = { NODRAW, NODRAW, NODRAW };
|
||||
Button screenModeButton(0, 190, 50, 50, false, "", noDraw);
|
||||
Button brightnessButton(65, 190, 50, 50, false, "", noDraw);
|
||||
|
@ -19,8 +27,8 @@ Button restartButton(200, 191, 45, 50, false, "", noDraw);
|
|||
Button powerOffButton(260, 186, 55, 55, false, "", noDraw);
|
||||
boolean buttonPressed = false;
|
||||
|
||||
enum screenMode { DARK, LIGHT };
|
||||
screenMode COLOR_MODE = LIGHT;
|
||||
enum screenMode {DARK, LIGHT};
|
||||
screenMode COLOR_MODE;
|
||||
|
||||
uint16_t COLORS[2] = { WHITE, BLACK };
|
||||
|
||||
|
@ -60,7 +68,14 @@ TaskHandle_t TaskHandle_2;
|
|||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
M5.Axp.SetLcdVoltage(3150); // Set initial brightness
|
||||
preferences.begin("Key");
|
||||
Serial.print(preferences.getUInt(key1));
|
||||
if (preferences.getUInt(key1) == 0) {
|
||||
COLOR_MODE = DARK;
|
||||
} else {
|
||||
COLOR_MODE = LIGHT;
|
||||
}
|
||||
M5.Axp.SetLcdVoltage(brightnessValues[preferences.getUInt(key2)]); // Set initial brightness
|
||||
Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); // UART communication
|
||||
|
||||
// MULTITHREADING
|
||||
|
@ -334,8 +349,10 @@ void screenModeHandler(Event &e) {
|
|||
M5.Axp.SetLDOEnable(3, false);
|
||||
if (COLOR_MODE == DARK) {
|
||||
COLOR_MODE = LIGHT;
|
||||
preferences.putUInt(key1, 1);
|
||||
} else {
|
||||
COLOR_MODE = DARK;
|
||||
preferences.putUInt(key1, 0);
|
||||
}
|
||||
|
||||
buttonPressed = true;
|
||||
|
@ -489,24 +506,21 @@ void brightnessHandler(Event &e) {
|
|||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(125);
|
||||
M5.Axp.SetLDOEnable(3, false);
|
||||
switch (brightnessValue) {
|
||||
switch (preferences.getUInt(key2)) {
|
||||
case 0:
|
||||
preferences.putUInt(key2, 1);
|
||||
break;
|
||||
case 1:
|
||||
M5.Axp.SetLcdVoltage(2500);
|
||||
brightnessValue += 1;
|
||||
preferences.putUInt(key2, 2);
|
||||
break;
|
||||
case 2:
|
||||
M5.Axp.SetLcdVoltage(2750);
|
||||
brightnessValue += 1;
|
||||
preferences.putUInt(key2, 3);
|
||||
break;
|
||||
case 3:
|
||||
M5.Axp.SetLcdVoltage(2900);
|
||||
brightnessValue += 1;
|
||||
break;
|
||||
case 4:
|
||||
M5.Axp.SetLcdVoltage(3150);
|
||||
brightnessValue = 1;
|
||||
preferences.putUInt(key2, 0);
|
||||
break;
|
||||
}
|
||||
M5.Axp.SetLcdVoltage(brightnessValues[preferences.getUInt(key2)]);
|
||||
}
|
||||
|
||||
void restartHandler(Event &e) {
|
||||
|
|
Loading…
Reference in a new issue