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.
Diff: GUI.cpp
- Revision:
- 0:3fb966466a8d
- Child:
- 1:1912637769a0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GUI.cpp Wed Mar 17 16:12:07 2021 +0000 @@ -0,0 +1,84 @@ +#include "GUI.h" + +//Constructor +GUI::GUI(char *GUI_URL, EthernetInterface *eth):ws(GUI_URL, eth) +{ + if(ws.connect()) { + printf("WS connected\r\n"); + } else { + printf("WS failed\r\n"); + } + + ws.send("{\"topic\":\"FRDM\"}"); + ws.send("{\"topic\":\"update\"}"); + +} + +void GUI::refreshConnection() +{ + ws.connect(); +} + +bool GUI::receives(int *survivalSpeed, bool *activeTracking, bool *powerOn) +{ + char recvSer[500]; + bool msgReceived = false; + + while (ws.read(recvSer)) { + StaticJsonDocument<128> doc; + deserializeJson(doc, recvSer, 500); + + if (doc.containsKey("survivalSpeed")) { + *survivalSpeed = doc["survivalSpeed"]; + msgReceived = true; + } + + if (doc.containsKey("activeTracking")) { + *activeTracking = doc["activeTracking"]; + msgReceived = true; + } + + if (doc.containsKey("powerOn")) { + *powerOn = doc["powerOn"]; + msgReceived = true; + } + } + + return msgReceived; +} + +void GUI::windSpeed(float windSpeed) +{ + char output[32]; + sprintf(output, "{\"windSpeed\":%d}", (int)windSpeed); + ws.send((char*)output); +} + +void GUI::state(int state) +{ + char output[32]; + sprintf(output, "{\"state\":%d}", state); + ws.send((char*)output); +} + +void GUI::survivalSpeed(int survivalSpeed) +{ + char output[32]; + sprintf(output, "{\"survivalSpeed\":%d}", survivalSpeed); + ws.send((char*)output); +} + +void GUI::activeTracking(bool activeTracking) +{ + char output[32]; + sprintf(output, "{\"activeTracking\":%s}", activeTracking ? "true" : "false"); + ws.send((char*)output); +} + +void GUI::inverterPower(int power) +{ + char output[32]; + sprintf(output, "{\"inverterPower\":%d}", power); + ws.send((char*)output); +} +