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@0:3fb966466a8d, 2021-03-17 (annotated)
- Committer:
- jump_man
- Date:
- Wed Mar 17 16:12:07 2021 +0000
- Revision:
- 0:3fb966466a8d
- Child:
- 1:1912637769a0
Working revision.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jump_man | 0:3fb966466a8d | 1 | #include "GUI.h" |
jump_man | 0:3fb966466a8d | 2 | |
jump_man | 0:3fb966466a8d | 3 | //Constructor |
jump_man | 0:3fb966466a8d | 4 | GUI::GUI(char *GUI_URL, EthernetInterface *eth):ws(GUI_URL, eth) |
jump_man | 0:3fb966466a8d | 5 | { |
jump_man | 0:3fb966466a8d | 6 | if(ws.connect()) { |
jump_man | 0:3fb966466a8d | 7 | printf("WS connected\r\n"); |
jump_man | 0:3fb966466a8d | 8 | } else { |
jump_man | 0:3fb966466a8d | 9 | printf("WS failed\r\n"); |
jump_man | 0:3fb966466a8d | 10 | } |
jump_man | 0:3fb966466a8d | 11 | |
jump_man | 0:3fb966466a8d | 12 | ws.send("{\"topic\":\"FRDM\"}"); |
jump_man | 0:3fb966466a8d | 13 | ws.send("{\"topic\":\"update\"}"); |
jump_man | 0:3fb966466a8d | 14 | |
jump_man | 0:3fb966466a8d | 15 | } |
jump_man | 0:3fb966466a8d | 16 | |
jump_man | 0:3fb966466a8d | 17 | void GUI::refreshConnection() |
jump_man | 0:3fb966466a8d | 18 | { |
jump_man | 0:3fb966466a8d | 19 | ws.connect(); |
jump_man | 0:3fb966466a8d | 20 | } |
jump_man | 0:3fb966466a8d | 21 | |
jump_man | 0:3fb966466a8d | 22 | bool GUI::receives(int *survivalSpeed, bool *activeTracking, bool *powerOn) |
jump_man | 0:3fb966466a8d | 23 | { |
jump_man | 0:3fb966466a8d | 24 | char recvSer[500]; |
jump_man | 0:3fb966466a8d | 25 | bool msgReceived = false; |
jump_man | 0:3fb966466a8d | 26 | |
jump_man | 0:3fb966466a8d | 27 | while (ws.read(recvSer)) { |
jump_man | 0:3fb966466a8d | 28 | StaticJsonDocument<128> doc; |
jump_man | 0:3fb966466a8d | 29 | deserializeJson(doc, recvSer, 500); |
jump_man | 0:3fb966466a8d | 30 | |
jump_man | 0:3fb966466a8d | 31 | if (doc.containsKey("survivalSpeed")) { |
jump_man | 0:3fb966466a8d | 32 | *survivalSpeed = doc["survivalSpeed"]; |
jump_man | 0:3fb966466a8d | 33 | msgReceived = true; |
jump_man | 0:3fb966466a8d | 34 | } |
jump_man | 0:3fb966466a8d | 35 | |
jump_man | 0:3fb966466a8d | 36 | if (doc.containsKey("activeTracking")) { |
jump_man | 0:3fb966466a8d | 37 | *activeTracking = doc["activeTracking"]; |
jump_man | 0:3fb966466a8d | 38 | msgReceived = true; |
jump_man | 0:3fb966466a8d | 39 | } |
jump_man | 0:3fb966466a8d | 40 | |
jump_man | 0:3fb966466a8d | 41 | if (doc.containsKey("powerOn")) { |
jump_man | 0:3fb966466a8d | 42 | *powerOn = doc["powerOn"]; |
jump_man | 0:3fb966466a8d | 43 | msgReceived = true; |
jump_man | 0:3fb966466a8d | 44 | } |
jump_man | 0:3fb966466a8d | 45 | } |
jump_man | 0:3fb966466a8d | 46 | |
jump_man | 0:3fb966466a8d | 47 | return msgReceived; |
jump_man | 0:3fb966466a8d | 48 | } |
jump_man | 0:3fb966466a8d | 49 | |
jump_man | 0:3fb966466a8d | 50 | void GUI::windSpeed(float windSpeed) |
jump_man | 0:3fb966466a8d | 51 | { |
jump_man | 0:3fb966466a8d | 52 | char output[32]; |
jump_man | 0:3fb966466a8d | 53 | sprintf(output, "{\"windSpeed\":%d}", (int)windSpeed); |
jump_man | 0:3fb966466a8d | 54 | ws.send((char*)output); |
jump_man | 0:3fb966466a8d | 55 | } |
jump_man | 0:3fb966466a8d | 56 | |
jump_man | 0:3fb966466a8d | 57 | void GUI::state(int state) |
jump_man | 0:3fb966466a8d | 58 | { |
jump_man | 0:3fb966466a8d | 59 | char output[32]; |
jump_man | 0:3fb966466a8d | 60 | sprintf(output, "{\"state\":%d}", state); |
jump_man | 0:3fb966466a8d | 61 | ws.send((char*)output); |
jump_man | 0:3fb966466a8d | 62 | } |
jump_man | 0:3fb966466a8d | 63 | |
jump_man | 0:3fb966466a8d | 64 | void GUI::survivalSpeed(int survivalSpeed) |
jump_man | 0:3fb966466a8d | 65 | { |
jump_man | 0:3fb966466a8d | 66 | char output[32]; |
jump_man | 0:3fb966466a8d | 67 | sprintf(output, "{\"survivalSpeed\":%d}", survivalSpeed); |
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::activeTracking(bool activeTracking) |
jump_man | 0:3fb966466a8d | 72 | { |
jump_man | 0:3fb966466a8d | 73 | char output[32]; |
jump_man | 0:3fb966466a8d | 74 | sprintf(output, "{\"activeTracking\":%s}", activeTracking ? "true" : "false"); |
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::inverterPower(int power) |
jump_man | 0:3fb966466a8d | 79 | { |
jump_man | 0:3fb966466a8d | 80 | char output[32]; |
jump_man | 0:3fb966466a8d | 81 | sprintf(output, "{\"inverterPower\":%d}", power); |
jump_man | 0:3fb966466a8d | 82 | ws.send((char*)output); |
jump_man | 0:3fb966466a8d | 83 | } |
jump_man | 0:3fb966466a8d | 84 |