basic recieving
This commit is contained in:
parent
fa701086a1
commit
71161ecde5
58
M2/M2.ino
58
M2/M2.ino
|
@ -15,7 +15,7 @@ ButtonColors noDraw = {NODRAW, NODRAW, NODRAW};
|
||||||
enum screenMode {DARK, LIGHT};
|
enum screenMode {DARK, LIGHT};
|
||||||
screenMode COLOR_MODE = DARK;
|
screenMode COLOR_MODE = DARK;
|
||||||
enum dataMode {ATTENTION, MEDITATION, QUALITY, RAW, STOP};
|
enum dataMode {ATTENTION, MEDITATION, QUALITY, RAW, STOP};
|
||||||
dataMode DATA_MODE = STOP;
|
dataMode DATA_MODE = RAW;
|
||||||
|
|
||||||
Button screenModeButton(0, 190, 50, 50, false, "", noDraw);
|
Button screenModeButton(0, 190, 50, 50, false, "", noDraw);
|
||||||
Button brightnessButton(55, 190, 50, 50, false, "", noDraw);
|
Button brightnessButton(55, 190, 50, 50, false, "", noDraw);
|
||||||
|
@ -48,6 +48,8 @@ void setup(){
|
||||||
rawButton.addHandler(rawHandler, E_TOUCH);
|
rawButton.addHandler(rawHandler, E_TOUCH);
|
||||||
|
|
||||||
drawGui(COLOR_MODE);
|
drawGui(COLOR_MODE);
|
||||||
|
|
||||||
|
//Serial2.print("4");
|
||||||
}
|
}
|
||||||
|
|
||||||
///DRAW GUI
|
///DRAW GUI
|
||||||
|
@ -202,21 +204,21 @@ void rawHandler(Event& e) {
|
||||||
drawGui(COLOR_MODE);
|
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]);
|
M5.Lcd.setTextColor(COLORS[COLOR_MODE]);
|
||||||
if(DATA_MODE == ATTENTION){
|
if(DATA_MODE == ATTENTION){
|
||||||
Serial2.print((1));
|
//Serial2.print((1));
|
||||||
M5.Lcd.drawString("ATTENTION", 90, 80, 4);
|
M5.Lcd.drawString("ATTENTION", 90, 80, 4);
|
||||||
}else if(DATA_MODE ==MEDITATION){
|
}else if(DATA_MODE ==MEDITATION){
|
||||||
Serial2.print(String(2));
|
//Serial2.print(String(2));
|
||||||
M5.Lcd.drawString("MEDITATION", 84, 80, 4);
|
M5.Lcd.drawString("MEDITATION", 84, 80, 4);
|
||||||
}else if(DATA_MODE == QUALITY){
|
}else if(DATA_MODE == QUALITY){
|
||||||
Serial2.print(String(3));
|
//Serial2.print(String(3));
|
||||||
M5.Lcd.drawString("SIGNAL QUALITY", 60, 80, 4);
|
M5.Lcd.drawString("SIGNAL QUALITY", 60, 80, 4);
|
||||||
}else if(DATA_MODE == RAW){
|
}else if(DATA_MODE == RAW){
|
||||||
M5.Lcd.drawString("RAW", 132, 80, 4);
|
M5.Lcd.drawString("RAW", 132, 80, 4);
|
||||||
}else{
|
}else{
|
||||||
Serial2.print(String(0));
|
//Serial2.print(String(0));
|
||||||
M5.Lcd.drawString("...", 148, 100, 4);
|
M5.Lcd.drawString("...", 148, 100, 4);
|
||||||
}
|
}
|
||||||
if(DATA_MODE != STOP){
|
if(DATA_MODE != STOP){
|
||||||
|
@ -225,8 +227,7 @@ void writeScreenData(dataMode DATA_MODE, screenMode COLOR_MODE, String data){
|
||||||
} else {
|
} else {
|
||||||
M5.Lcd.fillRect(132,116,64,64,COLORS[DARK]);
|
M5.Lcd.fillRect(132,116,64,64,COLORS[DARK]);
|
||||||
}
|
}
|
||||||
M5.Lcd.drawString(data, 132, 128, 4);
|
M5.Lcd.drawString(String(data), 132, 128, 4);
|
||||||
delay(80);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,30 +235,27 @@ String stringReceived = "";
|
||||||
int valueReceived = 0;
|
int valueReceived = 0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
M5.update();
|
//M5.update();
|
||||||
if(Serial2.available()){
|
if(Serial2.available()){
|
||||||
char c = Serial2.read();
|
char c = Serial2.read();
|
||||||
|
//Serial.print(c);
|
||||||
stringReceived += c;
|
stringReceived += c;
|
||||||
|
if (stringReceived.length() == 17) {
|
||||||
if(DATA_MODE != RAW){
|
Serial.println("s:"+stringReceived);
|
||||||
if (stringReceived.length() == 3) {
|
String rawData = stringReceived.substring(9);
|
||||||
Serial.println("s:"+stringReceived);
|
/*int r = 8;
|
||||||
valueReceived = stringReceived.toInt();
|
while (r < 17){
|
||||||
Serial.println(valueReceived);
|
rawData += stringReceived[r];
|
||||||
stringReceived = "";
|
r++;
|
||||||
valueReceived= 0;
|
}*/
|
||||||
}
|
Serial.println("r:" +rawData);
|
||||||
}else {
|
//valueReceived = stringReceived.toInt();
|
||||||
if (stringReceived.length() == 8) {
|
//Serial.println(valueReceived);
|
||||||
Serial.println("s:"+stringReceived);
|
stringReceived = "";
|
||||||
valueReceived = stringReceived.toInt();
|
//valueReceived= 0;
|
||||||
Serial.println(valueReceived);
|
} else {
|
||||||
stringReceived = "";
|
//stringReceived = "";
|
||||||
valueReceived= 0;
|
}
|
||||||
}
|
//writeScreenData(DATA_MODE, COLOR_MODE, valueReceived);
|
||||||
}
|
|
||||||
Serial.print("data recieved:");
|
|
||||||
Serial.println(stringReceived);
|
|
||||||
writeScreenData(DATA_MODE, COLOR_MODE, stringReceived);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue