Browse Source

added sending code for new html page

master
Никита 7 years ago
parent
commit
20a50bba5b
  1. 36
      src/main.cpp

36
src/main.cpp

@ -49,18 +49,27 @@ void handleAccelerometer()
delete[] html_code; 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 = ∈ String *output = ∈
int *array = in_array; int *array = in_array;
DynamicJsonBuffer jsonBuffer; DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject(); JsonObject& root = jsonBuffer.createObject();
JsonArray& data = root.createNestedArray("data"); JsonArray& data = root.createNestedArray(arrayName);
for (int i = 0; i != array_size; i++) { for (int i = 0; i != array_size; i++) {
data.add(*(array + i)); data.add(*(array + i));
} }
root.printTo(*output); 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) { int lowFreqFilter(int inputValue, int lastFilteredValue, int alpha) {
return (lastFilteredValue + alpha * (inputValue - lastFilteredValue)+100); return (lastFilteredValue + alpha * (inputValue - lastFilteredValue)+100);
} }
@ -105,6 +114,9 @@ void updateAccelerometer()
for (int i = 0; i < graphAcc.size/2; i++) { for (int i = 0; i < graphAcc.size/2; i++) {
graphAcc.fft[i] = map((int) vReal[i], 0, 15000, 200, 0); graphAcc.fft[i] = map((int) vReal[i], 0, 15000, 200, 0);
} }
peakFreq = FFT.MajorPeak(vReal, graphAcc.size, 30);
} }
accelerometer.lastUpdate = millis(); accelerometer.lastUpdate = millis();
@ -129,18 +141,14 @@ void handleNotFound()
} }
void sendAccelerometerData() { void sendAccelerometerData() {
String word1, word2, word3;
int updateRate = 0; cookAccelerometer(word1, graphAcc.array, graphAcc.size, "data");
if (fftMode) updateRate = 200; cookAccelerometer(word2, graphAcc.fft, graphAcc.size/2, "fft");
else updateRate = graphAcc.updateRate; cookInfoToJson(word3, "info");
webSocket.broadcastTXT(word1);
if (millis() - lastDataSend > updateRate) { webSocket.broadcastTXT(word2);
String word; webSocket.broadcastTXT(word3);
cookAccelerometer(word, graphAcc.fft, graphAcc.size/2); webSocket.loop();
webSocket.broadcastTXT(word);
Serial.println(word);
lastDataSend = millis();
}
} }

Loading…
Cancel
Save