Compare commits
6 commits
6cd1eb7fe8
...
dcf83b2146
Author | SHA1 | Date | |
---|---|---|---|
sebhajek | dcf83b2146 | ||
sebhajek | 64c31e94e9 | ||
sebhajek | d54f37258d | ||
sebhajek | d2687e3c2c | ||
sebhajek | ee2c1f36d2 | ||
sebhajek | a719dd6890 |
2493
projectEEG2/icons.cpp
Normal file
2493
projectEEG2/icons.cpp
Normal file
File diff suppressed because it is too large
Load diff
268
projectEEG2/projectEEG2.ino
Normal file
268
projectEEG2/projectEEG2.ino
Normal file
|
@ -0,0 +1,268 @@
|
|||
#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 = STOP;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
///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]);
|
||||
|
||||
// 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);
|
||||
|
||||
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{
|
||||
Serial2.print("0");
|
||||
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{
|
||||
Serial2.print("0");
|
||||
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{
|
||||
Serial2.print("0");
|
||||
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{
|
||||
Serial2.print("0");
|
||||
delay(50);
|
||||
Serial2.print("4");
|
||||
DATA_MODE = RAW;
|
||||
}
|
||||
drawGui(COLOR_MODE);
|
||||
}
|
||||
|
||||
void writeScreenData(dataMode DATA_MODE, screenMode COLOR_MODE, String data){
|
||||
M5.Lcd.setTextColor(COLORS[COLOR_MODE]);
|
||||
if(DATA_MODE == ATTENTION){
|
||||
M5.Lcd.drawString("ATTENTION", 90, 80, 4);
|
||||
}else if(DATA_MODE ==MEDITATION){
|
||||
M5.Lcd.drawString("MEDITATION", 84, 80, 4);
|
||||
}else if(DATA_MODE == QUALITY){
|
||||
M5.Lcd.drawString("SIGNAL QUALITY", 60, 80, 4);
|
||||
}else if(DATA_MODE == RAW){
|
||||
M5.Lcd.drawString("RAW", 132, 80, 4);
|
||||
}else{
|
||||
M5.Lcd.drawString("...", 148, 100, 4);
|
||||
}
|
||||
if(DATA_MODE != STOP){
|
||||
M5.Lcd.drawString(data, 132, 128, 4);
|
||||
}
|
||||
}
|
||||
|
||||
String stringReceived = "";
|
||||
String serialCommand = "";
|
||||
|
||||
void loop() {
|
||||
M5.update();
|
||||
if(Serial2.available() > 0){
|
||||
stringReceived = Serial2.read();
|
||||
Serial.print("data recieved:");
|
||||
Serial.println(stringReceived);
|
||||
writeScreenData(DATA_MODE, COLOR_MODE, stringReceived);
|
||||
stringReceived = "";
|
||||
}
|
||||
|
||||
if (Serial.available() > 0){
|
||||
//TODO
|
||||
serialCommand = Serial.read();
|
||||
if (serialCommand == "attention"){
|
||||
Serial.println("in ATTENTION");
|
||||
DATA_MODE = ATTENTION;
|
||||
}
|
||||
if (serialCommand == "meditation"){
|
||||
Serial.println("in MEDITATION");
|
||||
DATA_MODE = MEDITATION;
|
||||
}
|
||||
if (serialCommand == "quality"){
|
||||
Serial.println("in QUALITY");
|
||||
DATA_MODE = QUALITY;
|
||||
}
|
||||
if (serialCommand == "stop"){
|
||||
Serial.println("Stoping");
|
||||
DATA_MODE = STOP;
|
||||
}
|
||||
|
||||
serialCommand = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue