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
- Committer:
- jump_man
- Date:
- 2021-03-17
- Revision:
- 1:1912637769a0
- Parent:
- 0:3fb966466a8d
- Child:
- 2:3232132ce1ea
File content as of revision 1:1912637769a0:
#include "GUI.h" //#include "Defs_Sett.h" //Constructor GUI::GUI(char *GUI_URL, EthernetInterface *eth, bool* flag):ws(GUI_URL, eth) { if(ws.connect()) { printf("WS connected\r\n"); *flag = true; } else { printf("WS failed\r\n"); *flag = false; } 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"]; //*mode = (*powerOn) ? 1 : *mode; // OP_POWER_OFF //*mode = (*mode == 1 && *powerOn) ? 1 : *mode; // OP_POWER_OFF, OP_NORMAL 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); }