Neurosky-Mindwave-M5Stack-C.../sources/GUI/GUI/GUI.ino

135 lines
4 KiB
C++

#include <M5Core2.h>
#include "icons.cpp" // icons
float batPercentage;
ButtonColors noDraw = {NODRAW, NODRAW, NODRAW};
Button screenModeButton(0, 190, 50, 50, false, "", noDraw);
Button restartButton(200, 191, 45, 50, false, "", noDraw);
Button powerOffButton(260, 186, 55, 55, false, "", noDraw);
enum screenMode {DARK, LIGHT};
screenMode COLOR_MODE = LIGHT;
uint16_t COLORS[2] = {WHITE, BLACK};
void setup() {
M5.begin();
screenModeButton.addHandler(screenModeHandler, E_TOUCH);
restartButton.addHandler(restartHandler, E_TOUCH);
powerOffButton.addHandler(powerOffHandler, E_TOUCH);
drawGui(COLOR_MODE);
}
void loop() {
// put your main code here, to run repeatedly:
M5.update();
}
void drawGui(screenMode COLOR_MODE) {
M5.Lcd.clear();
M5.Lcd.fillScreen((COLORS[COLOR_MODE] - 1) % 2);
M5.Lcd.setTextColor(COLORS[COLOR_MODE]);
// HEADER
if (COLOR_MODE == DARK) {
M5.lcd.drawBitmap(5, 5, 50, 50, (uint16_t *) signal_white_2_3);
} else {
M5.lcd.drawBitmap(5, 5, 50, 50, (uint16_t *) signal_1_3);
}
M5.Lcd.drawString("100", 60, 20, 4);
if (COLOR_MODE == DARK) {
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *) bluetooth_dark);
} else {
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *) bluetooth_light);
}
// NOT CONNECTED BLUETOOTH
for (int i = 0; i < 4; i++) { // thicker line
M5.lcd.drawLine(240 + i, 55, 270 + i, 5, RED);
}
drawBattery();
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);
M5.Lcd.drawString("20", 60, 130, 4);
M5.Lcd.drawString("0", 220, 130, 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(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(200, 191, 45, 50, (uint16_t *) restart);
M5.lcd.drawBitmap(260, 186, 55, 55, (uint16_t *) power_off);
}
}
void drawBattery() {
batPercentage = 5;
Serial.print(M5.Axp.isCharging());
if (COLOR_MODE == DARK) {
if (M5.Axp.isCharging()) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryCharging_white);
} else {
if (batPercentage > 90) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus4_white);
} else if ((90 > batPercentage) && (batPercentage > 60)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus3_white);
} else if ((60 > batPercentage) && (batPercentage > 20)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus2_white);
} else if ((20 > batPercentage) && (batPercentage > 10)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus1_white);
} else {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus0_white);
}
}
} else {
if (M5.Axp.isCharging()) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryCharging);
} else {
if (batPercentage > 90) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus4);
} else if ((90 > batPercentage) && (batPercentage > 60)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus3);
} else if ((60 > batPercentage) && (batPercentage > 20)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus2);
} else if ((20 > batPercentage) && (batPercentage > 10)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus1);
} else {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus0);
}
}
}
}
void screenModeHandler(Event& e) {
if (COLOR_MODE == DARK) {
COLOR_MODE = LIGHT;
} else {
COLOR_MODE = DARK;
}
drawGui(COLOR_MODE);
}
void restartHandler(Event& e) {
M5.shutdown(1);
}
void powerOffHandler(Event& e) {
M5.shutdown();
}