Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GUI.cpp@4:4643a545bcf9, 2021-03-25 (annotated)
- Committer:
- khaiminhvn
- Date:
- Thu Mar 25 01:17:19 2021 +0000
- Revision:
- 4:4643a545bcf9
- Parent:
- 3:ff63deac3f4a
- Child:
- 5:8a9cb632e91b
Reworked private variables
Who changed what in which revision?
User | Revision | Line number | New 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 |
khaiminhvn | 4:4643a545bcf9 | 5 | GUI::GUI(char *GUI_URL, EthernetInterface* ethIn, bool* flag) |
jump_man | 0:3fb966466a8d | 6 | { |
khaiminhvn | 4:4643a545bcf9 | 7 | eth = ethIn; |
khaiminhvn | 4:4643a545bcf9 | 8 | ws = new Websocket(GUI_URL,eth); |
khaiminhvn | 4:4643a545bcf9 | 9 | if(ws->connect()) { |
jump_man | 0:3fb966466a8d | 10 | printf("WS connected\r\n"); |
jump_man | 1:1912637769a0 | 11 | *flag = true; |
jump_man | 0:3fb966466a8d | 12 | } else { |
jump_man | 0:3fb966466a8d | 13 | printf("WS failed\r\n"); |
jump_man | 1:1912637769a0 | 14 | *flag = false; |
jump_man | 0:3fb966466a8d | 15 | } |
jump_man | 0:3fb966466a8d | 16 | |
khaiminhvn | 4:4643a545bcf9 | 17 | ws->send("{\"topic\":\"FRDM\"}"); |
khaiminhvn | 4:4643a545bcf9 | 18 | ws->send("{\"topic\":\"update\"}"); |
jump_man | 0:3fb966466a8d | 19 | |
jump_man | 0:3fb966466a8d | 20 | } |
jump_man | 0:3fb966466a8d | 21 | |
khaiminhvn | 4:4643a545bcf9 | 22 | void GUI::refreshConnection(char *GUI_URL, bool* flag) |
jump_man | 0:3fb966466a8d | 23 | { |
khaiminhvn | 4:4643a545bcf9 | 24 | delete ws; |
khaiminhvn | 4:4643a545bcf9 | 25 | ws = new Websocket(GUI_URL, eth); |
khaiminhvn | 4:4643a545bcf9 | 26 | if(ws->connect()) { |
khaiminhvn | 3:ff63deac3f4a | 27 | printf("WS connected\r\n"); |
khaiminhvn | 3:ff63deac3f4a | 28 | *flag = true; |
khaiminhvn | 3:ff63deac3f4a | 29 | } else { |
khaiminhvn | 3:ff63deac3f4a | 30 | printf("WS failed\r\n"); |
khaiminhvn | 3:ff63deac3f4a | 31 | *flag = false; |
khaiminhvn | 3:ff63deac3f4a | 32 | } |
jump_man | 0:3fb966466a8d | 33 | } |
jump_man | 0:3fb966466a8d | 34 | |
jump_man | 2:3232132ce1ea | 35 | bool GUI::receives(int *survivalSpeed, bool *activeTracking, bool *powerOn, float *sunAngle) |
jump_man | 0:3fb966466a8d | 36 | { |
jump_man | 0:3fb966466a8d | 37 | char recvSer[500]; |
jump_man | 0:3fb966466a8d | 38 | bool msgReceived = false; |
jump_man | 0:3fb966466a8d | 39 | |
khaiminhvn | 4:4643a545bcf9 | 40 | while (ws->read(recvSer)) { |
jump_man | 0:3fb966466a8d | 41 | StaticJsonDocument<128> doc; |
jump_man | 0:3fb966466a8d | 42 | deserializeJson(doc, recvSer, 500); |
jump_man | 0:3fb966466a8d | 43 | |
jump_man | 0:3fb966466a8d | 44 | if (doc.containsKey("survivalSpeed")) { |
jump_man | 0:3fb966466a8d | 45 | *survivalSpeed = doc["survivalSpeed"]; |
jump_man | 0:3fb966466a8d | 46 | msgReceived = true; |
jump_man | 0:3fb966466a8d | 47 | } |
jump_man | 0:3fb966466a8d | 48 | |
jump_man | 0:3fb966466a8d | 49 | if (doc.containsKey("activeTracking")) { |
jump_man | 0:3fb966466a8d | 50 | *activeTracking = doc["activeTracking"]; |
jump_man | 0:3fb966466a8d | 51 | msgReceived = true; |
jump_man | 0:3fb966466a8d | 52 | } |
jump_man | 1:1912637769a0 | 53 | |
jump_man | 0:3fb966466a8d | 54 | if (doc.containsKey("powerOn")) { |
jump_man | 0:3fb966466a8d | 55 | *powerOn = doc["powerOn"]; |
jump_man | 1:1912637769a0 | 56 | //*mode = (*powerOn) ? 1 : *mode; // OP_POWER_OFF |
jump_man | 1:1912637769a0 | 57 | //*mode = (*mode == 1 && *powerOn) ? 1 : *mode; // OP_POWER_OFF, OP_NORMAL |
jump_man | 0:3fb966466a8d | 58 | msgReceived = true; |
jump_man | 0:3fb966466a8d | 59 | } |
jump_man | 1:1912637769a0 | 60 | |
jump_man | 2:3232132ce1ea | 61 | // Only update sunAngle if in AUTO tracking |
jump_man | 2:3232132ce1ea | 62 | if (!(*activeTracking)) { |
jump_man | 2:3232132ce1ea | 63 | if (doc.containsKey("angle")) { |
jump_man | 2:3232132ce1ea | 64 | *sunAngle = doc["angle"]; |
jump_man | 2:3232132ce1ea | 65 | msgReceived = true; |
jump_man | 2:3232132ce1ea | 66 | } |
jump_man | 2:3232132ce1ea | 67 | } |
jump_man | 2:3232132ce1ea | 68 | |
jump_man | 0:3fb966466a8d | 69 | } |
jump_man | 0:3fb966466a8d | 70 | |
jump_man | 0:3fb966466a8d | 71 | return msgReceived; |
jump_man | 0:3fb966466a8d | 72 | } |
jump_man | 0:3fb966466a8d | 73 | |
jump_man | 0:3fb966466a8d | 74 | void GUI::windSpeed(float windSpeed) |
jump_man | 0:3fb966466a8d | 75 | { |
jump_man | 0:3fb966466a8d | 76 | char output[32]; |
jump_man | 0:3fb966466a8d | 77 | sprintf(output, "{\"windSpeed\":%d}", (int)windSpeed); |
khaiminhvn | 4:4643a545bcf9 | 78 | ws->send((char*)output); |
jump_man | 0:3fb966466a8d | 79 | } |
jump_man | 0:3fb966466a8d | 80 | |
jump_man | 0:3fb966466a8d | 81 | void GUI::state(int state) |
jump_man | 0:3fb966466a8d | 82 | { |
jump_man | 0:3fb966466a8d | 83 | char output[32]; |
jump_man | 0:3fb966466a8d | 84 | sprintf(output, "{\"state\":%d}", state); |
khaiminhvn | 4:4643a545bcf9 | 85 | ws->send((char*)output); |
jump_man | 0:3fb966466a8d | 86 | } |
jump_man | 0:3fb966466a8d | 87 | |
jump_man | 0:3fb966466a8d | 88 | void GUI::survivalSpeed(int survivalSpeed) |
jump_man | 0:3fb966466a8d | 89 | { |
jump_man | 0:3fb966466a8d | 90 | char output[32]; |
jump_man | 0:3fb966466a8d | 91 | sprintf(output, "{\"survivalSpeed\":%d}", survivalSpeed); |
khaiminhvn | 4:4643a545bcf9 | 92 | ws->send((char*)output); |
jump_man | 0:3fb966466a8d | 93 | } |
jump_man | 0:3fb966466a8d | 94 | |
jump_man | 0:3fb966466a8d | 95 | void GUI::activeTracking(bool activeTracking) |
jump_man | 0:3fb966466a8d | 96 | { |
jump_man | 0:3fb966466a8d | 97 | char output[32]; |
jump_man | 0:3fb966466a8d | 98 | sprintf(output, "{\"activeTracking\":%s}", activeTracking ? "true" : "false"); |
khaiminhvn | 4:4643a545bcf9 | 99 | ws->send((char*)output); |
jump_man | 0:3fb966466a8d | 100 | } |
jump_man | 0:3fb966466a8d | 101 | |
jump_man | 0:3fb966466a8d | 102 | void GUI::inverterPower(int power) |
jump_man | 0:3fb966466a8d | 103 | { |
jump_man | 0:3fb966466a8d | 104 | char output[32]; |
jump_man | 0:3fb966466a8d | 105 | sprintf(output, "{\"inverterPower\":%d}", power); |
khaiminhvn | 4:4643a545bcf9 | 106 | ws->send((char*)output); |
jump_man | 0:3fb966466a8d | 107 | } |
jump_man | 0:3fb966466a8d | 108 | |
jump_man | 2:3232132ce1ea | 109 | void GUI::getSunAngle() |
jump_man | 2:3232132ce1ea | 110 | { |
khaiminhvn | 4:4643a545bcf9 | 111 | ws->send("{\"topic\":\"getSunPosition\"}"); |
jump_man | 2:3232132ce1ea | 112 | } |
jump_man | 2:3232132ce1ea | 113 | |
jump_man | 2:3232132ce1ea | 114 |