Added basic UI
This commit is contained in:
parent
a719dd6890
commit
ee2c1f36d2
|
@ -4,12 +4,120 @@
|
|||
#include <M5Core2.h>
|
||||
#include "icons.cpp"
|
||||
|
||||
///UART SETUP
|
||||
#define RX_PIN 19
|
||||
#define TX_PIN 27
|
||||
|
||||
///UI SETUP
|
||||
|
||||
int brightnessValue = 1;
|
||||
ButtonColors noDraw = {NODRAW, NODRAW, NODRAW};
|
||||
enum screenMode {DARK, LIGHT};
|
||||
screenMode COLOR_MODE = DARK;
|
||||
|
||||
Button screenModeButton(0, 190, 50, 50, false, "", noDraw);
|
||||
Button brightnessButton(55, 190, 50, 50, false, "", noDraw);
|
||||
Button restartButton(200, 191, 45, 50, false, "", noDraw);
|
||||
Button powerOffButton(260, 186, 55, 55, false, "", noDraw);
|
||||
|
||||
uint16_t COLORS[2] = {WHITE, BLACK};
|
||||
|
||||
///SETUP
|
||||
void setup(){
|
||||
Serial.begin(BAUDRATE);
|
||||
Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||
M5.begin();
|
||||
M5.Axp.SetLcdVoltage(3150);
|
||||
|
||||
// GUI SETUP
|
||||
screenModeButton.addHandler(screenModeHandler, E_TOUCH);
|
||||
brightnessButton.addHandler(brightnessHandler, E_TOUCH);
|
||||
restartButton.addHandler(restartHandler, E_TOUCH);
|
||||
powerOffButton.addHandler(powerOffHandler, E_TOUCH);
|
||||
drawGui(COLOR_MODE);
|
||||
}
|
||||
|
||||
///DRAW GUI
|
||||
void drawGui(screenMode COLOR_MODE) {
|
||||
M5.Lcd.clear();
|
||||
M5.Lcd.fillScreen((COLORS[COLOR_MODE] - 1) % 2);
|
||||
M5.Lcd.setTextColor(COLORS[COLOR_MODE]);
|
||||
|
||||
if (COLOR_MODE == DARK) {
|
||||
M5.lcd.drawBitmap(280, 5, 30, 50, (uint16_t *) bluetooth_dark);
|
||||
} else {
|
||||
M5.lcd.drawBitmap(280, 5, 30, 50, (uint16_t *) bluetooth_light);
|
||||
}
|
||||
|
||||
M5.Lcd.drawLine(0, 60, 320, 60, COLORS[COLOR_MODE]);
|
||||
|
||||
// BODY
|
||||
M5.Lcd.drawString("Attention", 20, 80, 4);
|
||||
M5.Lcd.drawString("Meditation", 160, 80, 4);
|
||||
|
||||
// BOTTOM
|
||||
M5.Lcd.drawLine(0, 180, 320, 180, COLORS[COLOR_MODE]);
|
||||
screenModeButton.draw();
|
||||
if (COLOR_MODE == DARK) {
|
||||
M5.lcd.drawBitmap(0, 191, 50, 50, (uint16_t *) modeSwitchDark);
|
||||
M5.lcd.drawBitmap(55, 191, 50, 50, (uint16_t *) brightness_white);
|
||||
M5.lcd.drawBitmap(200, 191, 45, 50, (uint16_t *) restart_white);
|
||||
M5.lcd.drawBitmap(260, 186, 55, 55, (uint16_t *) power_off_white);
|
||||
} else {
|
||||
M5.lcd.drawBitmap(0, 191, 50, 50, (uint16_t *) modeSwitchLight);
|
||||
M5.lcd.drawBitmap(55, 191, 50, 50, (uint16_t *) brightness);
|
||||
M5.lcd.drawBitmap(200, 191, 45, 50, (uint16_t *) restart);
|
||||
M5.lcd.drawBitmap(260, 186, 55, 55, (uint16_t *) power_off);
|
||||
}
|
||||
}
|
||||
|
||||
void screenModeHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(125);
|
||||
M5.Axp.SetLDOEnable(3, false);
|
||||
if (COLOR_MODE == DARK) {
|
||||
COLOR_MODE = LIGHT;
|
||||
} else {
|
||||
COLOR_MODE = DARK;
|
||||
}
|
||||
|
||||
drawGui(COLOR_MODE);
|
||||
}
|
||||
|
||||
void brightnessHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(125);
|
||||
M5.Axp.SetLDOEnable(3, false);
|
||||
switch (brightnessValue) {
|
||||
case 1:
|
||||
M5.Axp.SetLcdVoltage(2500);
|
||||
brightnessValue += 1;
|
||||
break;
|
||||
case 2:
|
||||
M5.Axp.SetLcdVoltage(2750);
|
||||
brightnessValue += 1;
|
||||
break;
|
||||
case 3:
|
||||
M5.Axp.SetLcdVoltage(2900);
|
||||
brightnessValue += 1;
|
||||
break;
|
||||
case 4:
|
||||
M5.Axp.SetLcdVoltage(3150);
|
||||
brightnessValue = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void restartHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(250);
|
||||
M5.Axp.SetLDOEnable(3, false);
|
||||
M5.shutdown(1);
|
||||
}
|
||||
|
||||
void powerOffHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(500);
|
||||
M5.Axp.SetLDOEnable(3, false);
|
||||
M5.shutdown();
|
||||
}
|
Loading…
Reference in a new issue