From 364b0bf33b1ce7de6cb8763f9b467f04b85f10c2 Mon Sep 17 00:00:00 2001 From: Nikita Romanenko Date: Thu, 14 Dec 2017 01:21:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=B8=D0=B5=D0=BC=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BE?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/acc.html | 2 +- src/html.h | 15 ++++++++++++++- src/main.cpp | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/html/acc.html b/html/acc.html index 482e394..44f636d 100644 --- a/html/acc.html +++ b/html/acc.html @@ -63,7 +63,7 @@ function calibrateDevice() { - var calibrating = 5; + var calibrating = 10; socket.send(JSON.stringify(calibrating)); document.getElementById("calibrate_text").innerHTML = "Калибровка в течении 10 секунд - Сделайте несколько оборотов устройством перпендикулярно оси Х"; } diff --git a/src/html.h b/src/html.h index 6d8b085..eb1d4e6 100644 --- a/src/html.h +++ b/src/html.h @@ -5,7 +5,8 @@ enum parts HTML_BEGIN, HTML_END, STYLE, - SCRIPT + SCRIPT, + ACC_CALIBRATE }; const char html_begin[] PROGMEM = { @@ -78,6 +79,11 @@ const char script[] PROGMEM = { }\n\ context.stroke();\n\ };\n\ + function calibrateDevice() {\n\ + var calibrating = 10;\n\ + socket.send(JSON.stringify(calibrating));\n\ + document.getElementById(\"calibrate_text\").innerHTML = \"Калибровка в течении 10 секунд - Сделайте несколько оборотов устройством перпендикулярно оси Х\";\n\ + }\n\ \n\ "}; @@ -89,6 +95,10 @@ const char html_end[] PROGMEM = { \n\ \n"}; +const char acc_calibrate[] PROGMEM = { + "

Устройство не откалибровано.

\n\ + "}; + static int getHtml(parts p, char &adr, uint16_t buf_size, uint16_t bias) { char *buffer = &adr; @@ -108,6 +118,9 @@ static int getHtml(parts p, char &adr, uint16_t buf_size, uint16_t bias) case SCRIPT: html_part = script; break; + case ACC_CALIBRATE: + html_part = acc_calibrate; + break; } length = strlen_P(html_part); for (int i = 0; i != length; i++) diff --git a/src/main.cpp b/src/main.cpp index 5b476b3..e4aa1c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,12 @@ Graph graphAcc = Graph(200, 50); long int lastDataSend = 0; +int timeOfCal = 0; +bool accCalibrated = false; +int accCalRemains = 0; +int accMax1 = 0; +int accMax2 = 0; + WebSocketsServer webSocket = WebSocketsServer(81); void handleAccelerometer() @@ -29,7 +35,7 @@ void handleAccelerometer() 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(SCRIPT, *html_code, arr_size, bias); bias += getHtml(HTML_END, *html_code, arr_size, bias); server.send(200, "text/html", html_code); @@ -112,6 +118,14 @@ void sendAccelerometerData() { } } +void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { + switch(type) { + case WStype_TEXT: + timeOfCal = (int) *payload; + Serial.printf("[%u] get Text: %d\n", num, timeOfCal); + } +} + void setup(void) { @@ -136,6 +150,7 @@ void setup(void) Serial.println("HTTP server started"); webSocket.begin(); + webSocket.onEvent(webSocketEvent); } void loop(void)