From 20a50bba5bb6917831ccecd553d726b07da2abee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Wed, 30 May 2018 12:41:31 +0300 Subject: [PATCH] added sending code for new html page --- src/main.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cb0739a..a197073 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,18 +49,27 @@ void handleAccelerometer() delete[] html_code; } -void cookAccelerometer(String &in, int *in_array, int array_size) { +void cookAccelerometer(String &in, int *in_array, int array_size, String arrayName) { String *output = ∈ int *array = in_array; DynamicJsonBuffer jsonBuffer; JsonObject& root = jsonBuffer.createObject(); - JsonArray& data = root.createNestedArray("data"); + JsonArray& data = root.createNestedArray(arrayName); for (int i = 0; i != array_size; i++) { data.add(*(array + i)); } root.printTo(*output); } +void cookInfoToJson(String &in, String name) { + String *output = ∈ + DynamicJsonBuffer jsonBuffer; + JsonObject& root = jsonBuffer.createObject(); + root["steps"] = steps; + root["peakFreq"] = peakFreq; + root.printTo(*output); +} + int lowFreqFilter(int inputValue, int lastFilteredValue, int alpha) { return (lastFilteredValue + alpha * (inputValue - lastFilteredValue)+100); } @@ -105,6 +114,9 @@ void updateAccelerometer() for (int i = 0; i < graphAcc.size/2; i++) { graphAcc.fft[i] = map((int) vReal[i], 0, 15000, 200, 0); } + + + peakFreq = FFT.MajorPeak(vReal, graphAcc.size, 30); } accelerometer.lastUpdate = millis(); @@ -129,18 +141,14 @@ void handleNotFound() } void sendAccelerometerData() { - - int updateRate = 0; - if (fftMode) updateRate = 200; - else updateRate = graphAcc.updateRate; - - if (millis() - lastDataSend > updateRate) { - String word; - cookAccelerometer(word, graphAcc.fft, graphAcc.size/2); - webSocket.broadcastTXT(word); - Serial.println(word); - lastDataSend = millis(); - } + String word1, word2, word3; + cookAccelerometer(word1, graphAcc.array, graphAcc.size, "data"); + cookAccelerometer(word2, graphAcc.fft, graphAcc.size/2, "fft"); + cookInfoToJson(word3, "info"); + webSocket.broadcastTXT(word1); + webSocket.broadcastTXT(word2); + webSocket.broadcastTXT(word3); + webSocket.loop(); }