261 lines
6.7 KiB
C++
261 lines
6.7 KiB
C++
#define BAUDRATE 115200
|
|
#define DEBUGOUTPUT 0
|
|
|
|
#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;
|
|
enum dataMode {ATTENTION, MEDITATION, QUALITY, RAW, STOP};
|
|
dataMode DATA_MODE = RAW;
|
|
|
|
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);
|
|
|
|
Button attentionButton(0, 2, 48, 48, false, "", noDraw);
|
|
Button meditationButton(90, 2, 48, 48, false, "", noDraw);
|
|
Button qualityButton(180, 2, 48, 48, false, "", noDraw);
|
|
Button rawButton(270, 2, 48, 48, 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);
|
|
|
|
attentionButton.addHandler(attentionHandler, E_TOUCH);
|
|
meditationButton.addHandler(meditationHandler, E_TOUCH);
|
|
qualityButton.addHandler(qualityHandler, E_TOUCH);
|
|
rawButton.addHandler(rawHandler, E_TOUCH);
|
|
|
|
drawGui(COLOR_MODE);
|
|
|
|
//Serial2.print("4");
|
|
}
|
|
|
|
///DRAW GUI
|
|
void drawGui(screenMode COLOR_MODE) {
|
|
M5.Lcd.clear();
|
|
M5.Lcd.fillScreen((COLORS[COLOR_MODE] - 1) % 2);
|
|
M5.Lcd.setTextColor(COLORS[COLOR_MODE]);
|
|
|
|
M5.Lcd.drawLine(0, 60, 320, 60, COLORS[COLOR_MODE]);
|
|
|
|
// 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);
|
|
|
|
M5.lcd.drawBitmap(0, 2, 48, 48, (uint16_t *) attention_white);
|
|
M5.lcd.drawBitmap(90, 2, 48, 48, (uint16_t *) meditation_white);
|
|
M5.lcd.drawBitmap(180, 2, 48, 48, (uint16_t *) quality_white);
|
|
M5.lcd.drawBitmap(270, 2, 48, 48, (uint16_t *) raw_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);
|
|
|
|
M5.lcd.drawBitmap(0, 2, 48, 48, (uint16_t *) attention);
|
|
M5.lcd.drawBitmap(90, 2, 48, 48, (uint16_t *) meditation);
|
|
M5.lcd.drawBitmap(180, 2, 48, 48, (uint16_t *) quality);
|
|
M5.lcd.drawBitmap(270, 2, 48, 48, (uint16_t *) raw);
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
void attentionHandler(Event& e) {
|
|
M5.Axp.SetLDOEnable(3, true);
|
|
delay(50);
|
|
M5.Axp.SetLDOEnable(3, false);
|
|
if(DATA_MODE == ATTENTION){
|
|
Serial2.print("0");
|
|
DATA_MODE = STOP;
|
|
Serial.println("Stopping");
|
|
}else{
|
|
delay(50);
|
|
Serial2.print("1");
|
|
DATA_MODE = ATTENTION;
|
|
Serial.println("in ATTENTION");
|
|
}
|
|
drawGui(COLOR_MODE);
|
|
}
|
|
|
|
void meditationHandler(Event& e) {
|
|
M5.Axp.SetLDOEnable(3, true);
|
|
delay(50);
|
|
M5.Axp.SetLDOEnable(3, false);
|
|
if(DATA_MODE == MEDITATION){
|
|
Serial2.print("0");
|
|
DATA_MODE = STOP;
|
|
Serial.println("Stopping");
|
|
}else{
|
|
delay(50);
|
|
Serial2.print("2");
|
|
DATA_MODE = MEDITATION;
|
|
Serial.println("in MEDITATION");
|
|
}
|
|
drawGui(COLOR_MODE);
|
|
}
|
|
|
|
void qualityHandler(Event& e) {
|
|
M5.Axp.SetLDOEnable(3, true);
|
|
delay(50);
|
|
M5.Axp.SetLDOEnable(3, false);
|
|
if(DATA_MODE == QUALITY){
|
|
Serial2.print("0");
|
|
DATA_MODE = STOP;
|
|
Serial.println("Stopping");
|
|
}else{
|
|
delay(50);
|
|
Serial2.print("3");
|
|
DATA_MODE = QUALITY;
|
|
Serial.println("in QUALITY");
|
|
}
|
|
drawGui(COLOR_MODE);
|
|
}
|
|
|
|
void rawHandler(Event& e) {
|
|
M5.Axp.SetLDOEnable(3, true);
|
|
delay(50);
|
|
M5.Axp.SetLDOEnable(3, false);
|
|
if(DATA_MODE == RAW){
|
|
Serial2.print("0");
|
|
DATA_MODE = STOP;
|
|
Serial.println("Stopping");
|
|
}else{
|
|
delay(50);
|
|
Serial2.print("4");
|
|
DATA_MODE = RAW;
|
|
}
|
|
drawGui(COLOR_MODE);
|
|
}
|
|
|
|
void writeScreenData(dataMode DATA_MODE, screenMode COLOR_MODE, int data){
|
|
M5.Lcd.setTextColor(COLORS[COLOR_MODE]);
|
|
if(DATA_MODE == ATTENTION){
|
|
//Serial2.print((1));
|
|
M5.Lcd.drawString("ATTENTION", 90, 80, 4);
|
|
}else if(DATA_MODE ==MEDITATION){
|
|
//Serial2.print(String(2));
|
|
M5.Lcd.drawString("MEDITATION", 84, 80, 4);
|
|
}else if(DATA_MODE == QUALITY){
|
|
//Serial2.print(String(3));
|
|
M5.Lcd.drawString("SIGNAL QUALITY", 60, 80, 4);
|
|
}else if(DATA_MODE == RAW){
|
|
M5.Lcd.drawString("RAW", 132, 80, 4);
|
|
}else{
|
|
//Serial2.print(String(0));
|
|
M5.Lcd.drawString("...", 148, 100, 4);
|
|
}
|
|
if(DATA_MODE != STOP){
|
|
if(COLOR_MODE == DARK) {
|
|
M5.Lcd.fillRect(132,116,64,64,COLORS[LIGHT]);
|
|
} else {
|
|
M5.Lcd.fillRect(132,116,64,64,COLORS[DARK]);
|
|
}
|
|
M5.Lcd.drawString(String(data), 132, 128, 4);
|
|
}
|
|
}
|
|
|
|
String stringReceived = "";
|
|
int valueReceived = 0;
|
|
|
|
void loop() {
|
|
//M5.update();
|
|
if(Serial2.available()){
|
|
char c = Serial2.read();
|
|
//Serial.print(c);
|
|
stringReceived += c;
|
|
if (stringReceived.length() == 17) {
|
|
Serial.println("s:"+stringReceived);
|
|
String rawData = stringReceived.substring(9);
|
|
/*int r = 8;
|
|
while (r < 17){
|
|
rawData += stringReceived[r];
|
|
r++;
|
|
}*/
|
|
Serial.println("r:" +rawData);
|
|
//valueReceived = stringReceived.toInt();
|
|
//Serial.println(valueReceived);
|
|
stringReceived = "";
|
|
//valueReceived= 0;
|
|
} else {
|
|
//stringReceived = "";
|
|
}
|
|
//writeScreenData(DATA_MODE, COLOR_MODE, valueReceived);
|
|
}
|
|
} |