Repaired comunication
This commit is contained in:
parent
52c0fcf109
commit
6153088b84
70
M2/M2.ino
70
M2/M2.ino
|
@ -58,10 +58,6 @@ void drawGui(screenMode 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();
|
||||
|
@ -148,7 +144,6 @@ void attentionHandler(Event& e) {
|
|||
DATA_MODE = STOP;
|
||||
Serial.println("Stopping");
|
||||
}else{
|
||||
Serial2.print("0");
|
||||
delay(50);
|
||||
Serial2.print("1");
|
||||
DATA_MODE = ATTENTION;
|
||||
|
@ -166,7 +161,6 @@ void meditationHandler(Event& e) {
|
|||
DATA_MODE = STOP;
|
||||
Serial.println("Stopping");
|
||||
}else{
|
||||
Serial2.print("0");
|
||||
delay(50);
|
||||
Serial2.print("2");
|
||||
DATA_MODE = MEDITATION;
|
||||
|
@ -184,7 +178,6 @@ void qualityHandler(Event& e) {
|
|||
DATA_MODE = STOP;
|
||||
Serial.println("Stopping");
|
||||
}else{
|
||||
Serial2.print("0");
|
||||
delay(50);
|
||||
Serial2.print("3");
|
||||
DATA_MODE = QUALITY;
|
||||
|
@ -202,7 +195,6 @@ void rawHandler(Event& e) {
|
|||
DATA_MODE = STOP;
|
||||
Serial.println("Stopping");
|
||||
}else{
|
||||
Serial2.print("0");
|
||||
delay(50);
|
||||
Serial2.print("4");
|
||||
DATA_MODE = RAW;
|
||||
|
@ -213,56 +205,58 @@ void rawHandler(Event& e) {
|
|||
void writeScreenData(dataMode DATA_MODE, screenMode COLOR_MODE, String 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(data, 132, 128, 4);
|
||||
}
|
||||
}
|
||||
|
||||
String stringReceived = "";
|
||||
String serialCommand = "";
|
||||
int valueReceived = 0;
|
||||
|
||||
void loop() {
|
||||
M5.update();
|
||||
if(Serial2.available() > 0){
|
||||
stringReceived = Serial2.read();
|
||||
if(Serial2.available()){
|
||||
char c = Serial2.read();
|
||||
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;
|
||||
}
|
||||
}
|
||||
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