From a0c51dcf127b6c338560981aa8a1293b3a87dea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sat, 28 Apr 2018 21:03:49 +0300 Subject: [PATCH] renamed some functions for better presentability of their functionality mean --- src/main.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cd9bbda..db6cfe7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,9 @@ #include "CpuLoad.h" +#define WEBSOCKETS_SERVER_CLIENT_MAX (20) + + const char *ssid = "LabWork_1"; ESP8266WebServer server(80); @@ -25,7 +28,7 @@ int accMax2 = 0; WebSocketsServer webSocket = WebSocketsServer(81); -void handleAccelerometer() +void handleMainPage() { int16_t bias = 0; const int arr_size = 5000; @@ -33,16 +36,13 @@ void handleAccelerometer() memset(html_code, '\0', sizeof(char) * arr_size); bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0); - // bias += getHtml(STYLE, *html_code, arr_size, bias); - // bias += getHtml(SCRIPT, *html_code, arr_size, bias); - // bias += getHtml(HTML_END, *html_code, arr_size, bias); server.send(200, "text/html", html_code); delete[] html_code; } -void cookAccelerometer(String &in, int *in_array, int array_size) { +void cookDataToJson(String &in, int *in_array, int array_size) { String *output = ∈ int *array = in_array; DynamicJsonBuffer jsonBuffer; @@ -58,7 +58,7 @@ int lowFreqFilter(int inputValue, int lastFilteredValue, int alpha) { return (lastFilteredValue + alpha * (inputValue - lastFilteredValue)+100); } -void updateAccelerometer() +void updateSensors() { if ((millis() - accelerometer.lastUpdate) > (1000 / graphAcc.updateRate)) { @@ -109,14 +109,14 @@ void handleNotFound() server.send(404, "text/plain", message); } -void sendAccelerometerData() { +void sendDataToSocket() { int updateRate = 0; updateRate = 50; if (millis() - lastDataSend > updateRate) { String word; - cookAccelerometer(word, graphAcc.array, graphAcc.size); + cookDataToJson(word, graphAcc.array, graphAcc.size); webSocket.broadcastTXT(word); lastDataSend = millis(); } @@ -147,10 +147,7 @@ void setup(void) Serial.print("AP IP address: "); Serial.println(myIP); - server.on("/accelerometer", handleAccelerometer); - server.on("/", []() { - server.send(200, "text/html", "Main Page"); - }); + server.on("/", handleMainPage); server.onNotFound(handleNotFound); server.begin(); @@ -168,8 +165,8 @@ void loop(void) server.handleClient(); webSocket.loop(); - updateAccelerometer(); - sendAccelerometerData(); + updateSensors(); + sendDataToSocket(); updateCpuTime(1); printCpuLoad();