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)