Scott Vincent / GUI
Committer:
khaiminhvn
Date:
Wed Mar 24 23:39:40 2021 +0000
Revision:
3:ff63deac3f4a
Parent:
2:3232132ce1ea
Child:
4:4643a545bcf9
Adjusted refreshConnection() function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jump_man 0:3fb966466a8d 1 #include "GUI.h"
jump_man 1:1912637769a0 2 //#include "Defs_Sett.h"
jump_man 0:3fb966466a8d 3
jump_man 0:3fb966466a8d 4 //Constructor
jump_man 1:1912637769a0 5 GUI::GUI(char *GUI_URL, EthernetInterface *eth, bool* flag):ws(GUI_URL, eth)
jump_man 0:3fb966466a8d 6 {
jump_man 0:3fb966466a8d 7 if(ws.connect()) {
jump_man 0:3fb966466a8d 8 printf("WS connected\r\n");
jump_man 1:1912637769a0 9 *flag = true;
jump_man 0:3fb966466a8d 10 } else {
jump_man 0:3fb966466a8d 11 printf("WS failed\r\n");
jump_man 1:1912637769a0 12 *flag = false;
jump_man 0:3fb966466a8d 13 }
jump_man 0:3fb966466a8d 14
jump_man 0:3fb966466a8d 15 ws.send("{\"topic\":\"FRDM\"}");
jump_man 0:3fb966466a8d 16 ws.send("{\"topic\":\"update\"}");
jump_man 0:3fb966466a8d 17
jump_man 0:3fb966466a8d 18 }
jump_man 0:3fb966466a8d 19
khaiminhvn 3:ff63deac3f4a 20 void GUI::refreshConnection(bool* flag)
jump_man 0:3fb966466a8d 21 {
khaiminhvn 3:ff63deac3f4a 22 if(ws.connect()) {
khaiminhvn 3:ff63deac3f4a 23 printf("WS connected\r\n");
khaiminhvn 3:ff63deac3f4a 24 *flag = true;
khaiminhvn 3:ff63deac3f4a 25 } else {
khaiminhvn 3:ff63deac3f4a 26 printf("WS failed\r\n");
khaiminhvn 3:ff63deac3f4a 27 *flag = false;
khaiminhvn 3:ff63deac3f4a 28 }
jump_man 0:3fb966466a8d 29 }
jump_man 0:3fb966466a8d 30
jump_man 2:3232132ce1ea 31 bool GUI::receives(int *survivalSpeed, bool *activeTracking, bool *powerOn, float *sunAngle)
jump_man 0:3fb966466a8d 32 {
jump_man 0:3fb966466a8d 33 char recvSer[500];
jump_man 0:3fb966466a8d 34 bool msgReceived = false;
jump_man 0:3fb966466a8d 35
jump_man 0:3fb966466a8d 36 while (ws.read(recvSer)) {
jump_man 0:3fb966466a8d 37 StaticJsonDocument<128> doc;
jump_man 0:3fb966466a8d 38 deserializeJson(doc, recvSer, 500);
jump_man 0:3fb966466a8d 39
jump_man 0:3fb966466a8d 40 if (doc.containsKey("survivalSpeed")) {
jump_man 0:3fb966466a8d 41 *survivalSpeed = doc["survivalSpeed"];
jump_man 0:3fb966466a8d 42 msgReceived = true;
jump_man 0:3fb966466a8d 43 }
jump_man 0:3fb966466a8d 44
jump_man 0:3fb966466a8d 45 if (doc.containsKey("activeTracking")) {
jump_man 0:3fb966466a8d 46 *activeTracking = doc["activeTracking"];
jump_man 0:3fb966466a8d 47 msgReceived = true;
jump_man 0:3fb966466a8d 48 }
jump_man 1:1912637769a0 49
jump_man 0:3fb966466a8d 50 if (doc.containsKey("powerOn")) {
jump_man 0:3fb966466a8d 51 *powerOn = doc["powerOn"];
jump_man 1:1912637769a0 52 //*mode = (*powerOn) ? 1 : *mode; // OP_POWER_OFF
jump_man 1:1912637769a0 53 //*mode = (*mode == 1 && *powerOn) ? 1 : *mode; // OP_POWER_OFF, OP_NORMAL
jump_man 0:3fb966466a8d 54 msgReceived = true;
jump_man 0:3fb966466a8d 55 }
jump_man 1:1912637769a0 56
jump_man 2:3232132ce1ea 57 // Only update sunAngle if in AUTO tracking
jump_man 2:3232132ce1ea 58 if (!(*activeTracking)) {
jump_man 2:3232132ce1ea 59 if (doc.containsKey("angle")) {
jump_man 2:3232132ce1ea 60 *sunAngle = doc["angle"];
jump_man 2:3232132ce1ea 61 msgReceived = true;
jump_man 2:3232132ce1ea 62 }
jump_man 2:3232132ce1ea 63 }
jump_man 2:3232132ce1ea 64
jump_man 0:3fb966466a8d 65 }
jump_man 0:3fb966466a8d 66
jump_man 0:3fb966466a8d 67 return msgReceived;
jump_man 0:3fb966466a8d 68 }
jump_man 0:3fb966466a8d 69
jump_man 0:3fb966466a8d 70 void GUI::windSpeed(float windSpeed)
jump_man 0:3fb966466a8d 71 {
jump_man 0:3fb966466a8d 72 char output[32];
jump_man 0:3fb966466a8d 73 sprintf(output, "{\"windSpeed\":%d}", (int)windSpeed);
jump_man 0:3fb966466a8d 74 ws.send((char*)output);
jump_man 0:3fb966466a8d 75 }
jump_man 0:3fb966466a8d 76
jump_man 0:3fb966466a8d 77 void GUI::state(int state)
jump_man 0:3fb966466a8d 78 {
jump_man 0:3fb966466a8d 79 char output[32];
jump_man 0:3fb966466a8d 80 sprintf(output, "{\"state\":%d}", state);
jump_man 0:3fb966466a8d 81 ws.send((char*)output);
jump_man 0:3fb966466a8d 82 }
jump_man 0:3fb966466a8d 83
jump_man 0:3fb966466a8d 84 void GUI::survivalSpeed(int survivalSpeed)
jump_man 0:3fb966466a8d 85 {
jump_man 0:3fb966466a8d 86 char output[32];
jump_man 0:3fb966466a8d 87 sprintf(output, "{\"survivalSpeed\":%d}", survivalSpeed);
jump_man 0:3fb966466a8d 88 ws.send((char*)output);
jump_man 0:3fb966466a8d 89 }
jump_man 0:3fb966466a8d 90
jump_man 0:3fb966466a8d 91 void GUI::activeTracking(bool activeTracking)
jump_man 0:3fb966466a8d 92 {
jump_man 0:3fb966466a8d 93 char output[32];
jump_man 0:3fb966466a8d 94 sprintf(output, "{\"activeTracking\":%s}", activeTracking ? "true" : "false");
jump_man 0:3fb966466a8d 95 ws.send((char*)output);
jump_man 0:3fb966466a8d 96 }
jump_man 0:3fb966466a8d 97
jump_man 0:3fb966466a8d 98 void GUI::inverterPower(int power)
jump_man 0:3fb966466a8d 99 {
jump_man 0:3fb966466a8d 100 char output[32];
jump_man 0:3fb966466a8d 101 sprintf(output, "{\"inverterPower\":%d}", power);
jump_man 0:3fb966466a8d 102 ws.send((char*)output);
jump_man 0:3fb966466a8d 103 }
jump_man 0:3fb966466a8d 104
jump_man 2:3232132ce1ea 105 void GUI::getSunAngle()
jump_man 2:3232132ce1ea 106 {
jump_man 2:3232132ce1ea 107 ws.send("{\"topic\":\"getSunPosition\"}");
jump_man 2:3232132ce1ea 108 }
jump_man 2:3232132ce1ea 109
jump_man 2:3232132ce1ea 110