|
|
@ -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(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|