Scott Vincent / GUI
Committer:
jump_man
Date:
Wed Mar 24 01:11:38 2021 +0000
Revision:
2:3232132ce1ea
Parent:
1:1912637769a0
Child:
3:ff63deac3f4a
Get sun angle added by Scott.

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
jump_man 0:3fb966466a8d 20 void GUI::refreshConnection()
jump_man 0:3fb966466a8d 21 {
jump_man 0:3fb966466a8d 22 ws.connect();
jump_man 0:3fb966466a8d 23 }
jump_man 0:3fb966466a8d 24
jump_man 2:3232132ce1ea 25 bool GUI::receives(int *survivalSpeed, bool *activeTracking, bool *powerOn, float *sunAngle)
jump_man 0:3fb966466a8d 26 {
jump_man 0:3fb966466a8d 27 char recvSer[500];
jump_man 0:3fb966466a8d 28 bool msgReceived = false;
jump_man 0:3fb966466a8d 29
jump_man 0:3fb966466a8d 30 while (ws.read(recvSer)) {
jump_man 0:3fb966466a8d 31 StaticJsonDocument<128> doc;
jump_man 0:3fb966466a8d 32 deserializeJson(doc, recvSer, 500);
jump_man 0:3fb966466a8d 33
jump_man 0:3fb966466a8d 34 if (doc.containsKey("survivalSpeed")) {
jump_man 0:3fb966466a8d 35 *survivalSpeed = doc["survivalSpeed"];
jump_man 0:3fb966466a8d 36 msgReceived = true;
jump_man 0:3fb966466a8d 37 }
jump_man 0:3fb966466a8d 38
jump_man 0:3fb966466a8d 39 if (doc.containsKey("activeTracking")) {
jump_man 0:3fb966466a8d 40 *activeTracking = doc["activeTracking"];
jump_man 0:3fb966466a8d 41 msgReceived = true;
jump_man 0:3fb966466a8d 42 }
jump_man 1:1912637769a0 43
jump_man 0:3fb966466a8d 44 if (doc.containsKey("powerOn")) {
jump_man 0:3fb966466a8d 45 *powerOn = doc["powerOn"];
jump_man 1:1912637769a0 46 //*mode = (*powerOn) ? 1 : *mode; // OP_POWER_OFF
jump_man 1:1912637769a0 47 //*mode = (*mode == 1 && *powerOn) ? 1 : *mode; // OP_POWER_OFF, OP_NORMAL
jump_man 0:3fb966466a8d 48 msgReceived = true;
jump_man 0:3fb966466a8d 49 }
jump_man 1:1912637769a0 50
jump_man 2:3232132ce1ea 51 // Only update sunAngle if in AUTO tracking
jump_man 2:3232132ce1ea 52 if (!(*activeTracking)) {
jump_man 2:3232132ce1ea 53 if (doc.containsKey("angle")) {
jump_man 2:3232132ce1ea 54 *sunAngle = doc["angle"];
jump_man 2:3232132ce1ea 55 msgReceived = true;
jump_man 2:3232132ce1ea 56 }
jump_man 2:3232132ce1ea 57 }
jump_man 2:3232132ce1ea 58
jump_man 0:3fb966466a8d 59 }
jump_man 0:3fb966466a8d 60
jump_man 0:3fb966466a8d 61 return msgReceived;
jump_man 0:3fb966466a8d 62 }
jump_man 0:3fb966466a8d 63
jump_man 0:3fb966466a8d 64 void GUI::windSpeed(float windSpeed)
jump_man 0:3fb966466a8d 65 {
jump_man 0:3fb966466a8d 66 char output[32];
jump_man 0:3fb966466a8d 67 sprintf(output, "{\"windSpeed\":%d}", (int)windSpeed);
jump_man 0:3fb966466a8d 68 ws.send((char*)output);
jump_man 0:3fb966466a8d 69 }
jump_man 0:3fb966466a8d 70
jump_man 0:3fb966466a8d 71 void GUI::state(int state)
jump_man 0:3fb966466a8d 72 {
jump_man 0:3fb966466a8d 73 char output[32];
jump_man 0:3fb966466a8d 74 sprintf(output, "{\"state\":%d}", state);
jump_man 0:3fb966466a8d 75 ws.send((char*)output);
jump_man 0:3fb966466a8d 76 }
jump_man 0:3fb966466a8d 77
jump_man 0:3fb966466a8d 78 void GUI::survivalSpeed(int survivalSpeed)
jump_man 0:3fb966466a8d 79 {
jump_man 0:3fb966466a8d 80 char output[32];
jump_man 0:3fb966466a8d 81 sprintf(output, "{\"survivalSpeed\":%d}", survivalSpeed);
jump_man 0:3fb966466a8d 82 ws.send((char*)output);
jump_man 0:3fb966466a8d 83 }
jump_man 0:3fb966466a8d 84
jump_man 0:3fb966466a8d 85 void GUI::activeTracking(bool activeTracking)
jump_man 0:3fb966466a8d 86 {
jump_man 0:3fb966466a8d 87 char output[32];
jump_man 0:3fb966466a8d 88 sprintf(output, "{\"activeTracking\":%s}", activeTracking ? "true" : "false");
jump_man 0:3fb966466a8d 89 ws.send((char*)output);
jump_man 0:3fb966466a8d 90 }
jump_man 0:3fb966466a8d 91
jump_man 0:3fb966466a8d 92 void GUI::inverterPower(int power)
jump_man 0:3fb966466a8d 93 {
jump_man 0:3fb966466a8d 94 char output[32];
jump_man 0:3fb966466a8d 95 sprintf(output, "{\"inverterPower\":%d}", power);
jump_man 0:3fb966466a8d 96 ws.send((char*)output);
jump_man 0:3fb966466a8d 97 }
jump_man 0:3fb966466a8d 98
jump_man 2:3232132ce1ea 99 void GUI::getSunAngle()
jump_man 2:3232132ce1ea 100 {
jump_man 2:3232132ce1ea 101 ws.send("{\"topic\":\"getSunPosition\"}");
jump_man 2:3232132ce1ea 102 }
jump_man 2:3232132ce1ea 103
jump_man 2:3232132ce1ea 104