basic parsing of data
This commit is contained in:
parent
71161ecde5
commit
275ea1330e
60
M2/M2.ino
60
M2/M2.ino
|
@ -139,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");
|
||||
}
|
||||
|
@ -156,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");
|
||||
}
|
||||
|
@ -173,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");
|
||||
}
|
||||
|
@ -190,16 +178,13 @@ 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);
|
||||
}
|
||||
|
@ -233,29 +218,24 @@ void writeScreenData(dataMode DATA_MODE, screenMode COLOR_MODE, int data){
|
|||
|
||||
String stringReceived = "";
|
||||
int valueReceived = 0;
|
||||
int valuesReceived[4];
|
||||
|
||||
void loop() {
|
||||
//M5.update();
|
||||
if(Serial2.available()){
|
||||
M5.update();
|
||||
while(Serial2.available())
|
||||
{
|
||||
char c = Serial2.read();
|
||||
//Serial.print(c);
|
||||
Serial.print(c);
|
||||
Serial.println;
|
||||
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);
|
||||
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 = "";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue