Project aiming to make a self-controlled solar reflector
Dependencies: Accelerometer LCD Inverter Algorithm MotorDriver Anemometer GUI ArduinoJson Misc Definitions Pushbutton WebSocketClient temp_fan
Diff: main.cpp
- Revision:
- 24:ea7abc25a697
- Parent:
- 23:5dff9aed3727
- Child:
- 25:b04abb0930ef
--- a/main.cpp Wed Mar 24 23:44:48 2021 +0000 +++ b/main.cpp Thu Mar 25 00:47:25 2021 +0000 @@ -53,6 +53,7 @@ int flag_disp = 1; //Anti-flickering int flag_bres = 0; //Flag for checking button released int flag_flas = 1; //Flag for flashing symbol +int flag_cali = 0; //Flag for calibration bool flag_eth; //Flag for ethernet connection bool flag_aTrack; //Flag for active tracking (0 - offline, 1 - online) bool flag_powerOn; @@ -96,14 +97,16 @@ switch(mode) { case OP_PLACEMENT:{ - topL = "CALIBRATING"; - botL = ""; - lcd.LCD_display(topL,botL); - acc.calibrate(); - topL = "PUT SENSOR ON"; - botL = "PANEL&REFLECTORS"; - lcd.LCD_display(topL,botL); - while(mode == OP_PLACEMENT){} + if(flag_cali == 0){ + topL = "CALIBRATING"; + botL = ""; + lcd.LCD_display(topL,botL); + acc.calibrate(); + topL = "PUT SENSOR ON"; + botL = "PANEL&REFLECTORS"; + lcd.LCD_display(topL,botL); + flag_cali = 1; + } break; } //////////////////////////////////////////////////////////////////////////////// @@ -126,6 +129,7 @@ ane.checkWind(&mode);if(mode != OP_NORMAL){break;} if (flag_eth){gui.windSpeed(ane.getWind());} topL = "NORMAL:IDLING"; + topL = (flag_aTrack) ? topL : "*" + topL; if(timer_read_ms(t_disp) >= LCD_RRATE){ botL = Misc::itos(ane.getWind(&flag_disp),3) + "kph | " + Misc::itos(fan.getTemp()) + "C"; t_disp.reset(); @@ -161,7 +165,7 @@ ane.checkWind(&mode);if(mode != OP_NORMAL){break;} if(timer_read_ms(t_disp) >= LCD_RRATE){ topL = (flag_flas)? "NORMAL:R1 <=>" : "NORMAL:R1 <-=->"; - topL = (flag_aTrack) ? " "+topL : "*" + topL; + topL = (flag_aTrack) ? topL : "*" + topL; flag_flas = !flag_flas; botL = Misc::itos(ane.getWind(&flag_disp),3) + "kph | " + Misc::itos(fan.getTemp()) + "C"; t_disp.reset(); @@ -179,7 +183,7 @@ ane.checkWind(&mode);if(mode != OP_NORMAL){break;} if(timer_read_ms(t_disp) >= LCD_RRATE){ topL = (flag_flas)? "NORMAL:R1 > = < " : "NORMAL:R1 ->=<-"; - topL = (flag_aTrack) ? " "+topL : "*" + topL; + topL = (flag_aTrack) ? topL : "*" + topL; flag_flas = !flag_flas; botL = Misc::itos(ane.getWind(&flag_disp),3) + "kph | " + Misc::itos(fan.getTemp()) + "C"; t_disp.reset(); @@ -201,7 +205,7 @@ ane.checkWind(&mode);if(mode != OP_NORMAL){break;} if(timer_read_ms(t_disp) >= LCD_RRATE){ topL = (flag_flas)? "NORMAL:R2 <=>" : "NORMAL:R2 <-=->"; - topL = (flag_aTrack) ? " "+topL : "*" + topL; + topL = (flag_aTrack) ? topL : "*" + topL; flag_flas = !flag_flas; botL = Misc::itos(ane.getWind(&flag_disp),3) + "kph | " + Misc::itos(fan.getTemp()) + "C"; t_disp.reset(); @@ -219,7 +223,7 @@ ane.checkWind(&mode);if(mode != OP_NORMAL){break;} if(timer_read_ms(t_disp) >= LCD_RRATE){ topL = (flag_flas)? "NORMAL:R2 > = < " : "NORMAL:R2 ->=<-"; - topL = (flag_aTrack) ? " "+topL : "*" + topL; + topL = (flag_aTrack) ? topL : "*" + topL; flag_flas = !flag_flas; botL = Misc::itos(ane.getWind(&flag_disp),3) + "kph | " + Misc::itos(fan.getTemp()) + "C"; t_disp.reset(); @@ -488,7 +492,8 @@ if(!(flag_bres == 1 && bt_inc.read()) && !(flag_bres == -1 && bt_dec.read())){ if(bt_inc.read() && wthres < WIND_THRES_MAX) { - ane.setThres(++wthres); + wthres += WIND_INC; + ane.setThres(wthres); if(flag_eth){gui.survivalSpeed(wthres);} botL = Misc::itos(wthres) + " kph"; lcd.LCD_display(topL,botL); @@ -497,7 +502,8 @@ } else if(bt_dec.read() && wthres > WIND_THRES_MIN) { - ane.setThres(--wthres); + wthres -= WIND_INC; + ane.setThres(wthres); if(flag_eth){gui.survivalSpeed(wthres);} botL = Misc::itos(wthres) + " kph"; lcd.LCD_display(topL,botL);