Compare commits
4 commits
c324407db7
...
f8f24240d8
Author | SHA1 | Date | |
---|---|---|---|
sebhajek | f8f24240d8 | ||
sebhajek | 275ea1330e | ||
sebhajek | 71161ecde5 | ||
sebhajek | fa701086a1 |
79
M2/M2.ino
79
M2/M2.ino
|
@ -15,7 +15,7 @@ ButtonColors noDraw = {NODRAW, NODRAW, NODRAW};
|
|||
enum screenMode {DARK, LIGHT};
|
||||
screenMode COLOR_MODE = DARK;
|
||||
enum dataMode {ATTENTION, MEDITATION, QUALITY, RAW, STOP};
|
||||
dataMode DATA_MODE = STOP;
|
||||
dataMode DATA_MODE = RAW;
|
||||
|
||||
Button screenModeButton(0, 190, 50, 50, false, "", noDraw);
|
||||
Button brightnessButton(55, 190, 50, 50, false, "", noDraw);
|
||||
|
@ -48,6 +48,8 @@ void setup(){
|
|||
rawButton.addHandler(rawHandler, E_TOUCH);
|
||||
|
||||
drawGui(COLOR_MODE);
|
||||
|
||||
//Serial2.print("4");
|
||||
}
|
||||
|
||||
///DRAW GUI
|
||||
|
@ -137,15 +139,11 @@ void powerOffHandler(Event& e) {
|
|||
|
||||
void attentionHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(50);
|
||||
delay(80);
|
||||
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");
|
||||
}
|
||||
|
@ -154,15 +152,11 @@ void attentionHandler(Event& e) {
|
|||
|
||||
void meditationHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(50);
|
||||
delay(80);
|
||||
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");
|
||||
}
|
||||
|
@ -171,15 +165,11 @@ void meditationHandler(Event& e) {
|
|||
|
||||
void qualityHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(50);
|
||||
delay(80);
|
||||
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");
|
||||
}
|
||||
|
@ -188,75 +178,64 @@ void qualityHandler(Event& e) {
|
|||
|
||||
void rawHandler(Event& e) {
|
||||
M5.Axp.SetLDOEnable(3, true);
|
||||
delay(50);
|
||||
delay(80);
|
||||
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;
|
||||
Serial.println("in RAW");
|
||||
}
|
||||
drawGui(COLOR_MODE);
|
||||
}
|
||||
|
||||
void writeScreenData(dataMode DATA_MODE, screenMode COLOR_MODE, String data){
|
||||
void writeScreenData(dataMode DATA_MODE, screenMode COLOR_MODE, int data){
|
||||
M5.Lcd.setTextColor(COLORS[COLOR_MODE]);
|
||||
if(DATA_MODE == ATTENTION){
|
||||
Serial2.print((1));
|
||||
//Serial2.print((1));
|
||||
M5.Lcd.drawString("ATTENTION", 90, 80, 4);
|
||||
}else if(DATA_MODE ==MEDITATION){
|
||||
Serial2.print(String(2));
|
||||
//Serial2.print(String(2));
|
||||
M5.Lcd.drawString("MEDITATION", 84, 80, 4);
|
||||
}else if(DATA_MODE == QUALITY){
|
||||
Serial2.print(String(3));
|
||||
//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));
|
||||
//Serial2.print(String(0));
|
||||
M5.Lcd.drawString("...", 148, 100, 4);
|
||||
}
|
||||
if(DATA_MODE != STOP){
|
||||
/* if(COLOR_MODE == DARK) {
|
||||
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(data, 132, 128, 4);
|
||||
}
|
||||
M5.Lcd.drawString(String(data), 132, 128, 4);
|
||||
}
|
||||
}
|
||||
|
||||
String stringReceived = "";
|
||||
int valueReceived = 0;
|
||||
int valuesReceived[4];
|
||||
|
||||
void loop() {
|
||||
M5.update();
|
||||
if(Serial2.available()){
|
||||
while(Serial2.available())
|
||||
{
|
||||
char c = Serial2.read();
|
||||
Serial.print(c);
|
||||
Serial.println;
|
||||
stringReceived += c;
|
||||
|
||||
if(DATA_MODE != RAW){
|
||||
if (stringReceived.length() >= 3) {
|
||||
Serial.println("s:"+stringReceived);
|
||||
valueReceived = stringReceived.toInt();
|
||||
Serial.println(valueReceived);
|
||||
stringReceived = "";
|
||||
valueReceived= 0;
|
||||
}
|
||||
}else {
|
||||
if (stringReceived.length() >= 8) {
|
||||
Serial.println("s:"+stringReceived);
|
||||
valueReceived = stringReceived.toInt();
|
||||
Serial.println(valueReceived);
|
||||
stringReceived = "";
|
||||
valueReceived= 0;
|
||||
}
|
||||
if (stringReceived.length() == 17) {
|
||||
Serial.println("s:"+stringReceived);
|
||||
valuesReceived[RAW] = {}stringReceived.substring(9);
|
||||
valuesReceived[QUALITY] = {}stringReceived.substring(6);
|
||||
valuesReceived[MEDITATION] = {}stringReceived.substring(3);
|
||||
valuesReceived[ATTENTION] = {}stringReceived.substring(0);
|
||||
Serial.printf("a:%3d m:%3d q:%3d r:%+8d\n",valuesReceived[ATTENTION],valueReceived[MEDITATION],valueReceived[QUALITY],valuesReceived[RAW]);
|
||||
stringReceived = "";
|
||||
}
|
||||
Serial.print("data recieved:");
|
||||
Serial.println(stringReceived);
|
||||
writeScreenData(DATA_MODE, COLOR_MODE, stringReceived);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue