From 9493d2a0c1aa79a6a96a22c3e7e4df093df6c1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sat, 28 Apr 2018 16:50:32 +0300 Subject: [PATCH] first changes for normall work (current configuration 0-20V) --- src/CpuLoad.h | 2 +- src/html.h | 17 ++++++++--------- src/main.cpp | 27 +++------------------------ 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/CpuLoad.h b/src/CpuLoad.h index f259c47..883fa85 100644 --- a/src/CpuLoad.h +++ b/src/CpuLoad.h @@ -1,4 +1,4 @@ -#include +#include // updateCpuTime отвечает за обновление статистики загрузки Cpu // updateCpuTime(false) - размещается в начале loop() diff --git a/src/html.h b/src/html.h index 3547d70..d4b7b8f 100644 --- a/src/html.h +++ b/src/html.h @@ -48,11 +48,7 @@ const char html_begin[] PROGMEM = R"(
-

Лабораторная работа

-

Акселерометр ADW22035Z - Cемейство ADXL103

-

Акселерометр подает на выход данные по одной оси.

-

Частота обновления графика - 1 раз в секунду. Данные с сенсора снимаются - с частотой в 50Hz.

+

Диагностика

Браузер устарел! @@ -63,7 +59,8 @@ const char html_begin[] PROGMEM = R"( var context = c.getContext("2d"); var maxX = 400, maxY = 200; var biasX = 20, biasY = 20; - + var curVoltage = 20; + var freq = 16; function iY(y) { return maxY + biasY - y; } @@ -74,7 +71,7 @@ const char html_begin[] PROGMEM = R"( context.lineTo(20, iY(i)); context.lineTo(15, iY(i)); context.moveTo(20, iY(i)); - textY = i/200*3.3; + textY = i/200*curVoltage; context.fillText(textY.toFixed(1), 0, iY(i-2.5)); } context.moveTo(20, iY(0)); @@ -82,7 +79,7 @@ const char html_begin[] PROGMEM = R"( context.lineTo(i, iY(0)); context.lineTo(i, iY(-5)); context.moveTo(i, iY(0)); - textX = (i-20)/400*4 ; + textX = (i-20)/400*freq ; context.fillText(textX.toFixed(1), i-10, iY(-20)); } context.stroke(); @@ -103,6 +100,8 @@ const char html_begin[] PROGMEM = R"( for (i = 1; i < 200; i++) { context.lineTo(i*2 + biasX, data.data[i] + biasY); } + voltage = data.data[199]*(-0.1)+20; + context.fillText(voltage + " V", 200,20); context.stroke(); }; function calibrateDevice() { @@ -114,7 +113,7 @@ const char html_begin[] PROGMEM = R"(
-
Тамбовский Государственный Технический Университет 2017-2018 г. +
DEFEND STUDIO | DEFEND.PW | 2018
diff --git a/src/main.cpp b/src/main.cpp index cb0739a..cd9bbda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,19 +8,12 @@ #include #include "CpuLoad.h" -#include "arduinoFFT.h" -bool fftMode = true; -arduinoFFT FFT = arduinoFFT(); - const char *ssid = "LabWork_1"; ESP8266WebServer server(80); Sensor accelerometer = Sensor(); -Graph graphAcc = Graph(256, 50); - -double vReal[256]; -double vImag[256]; +Graph graphAcc = Graph(200, 200); long int lastDataSend = 0; @@ -93,18 +86,6 @@ void updateAccelerometer() } graphAcc.array[graphAcc.counter] = filteredSignal; graphAcc.source[graphAcc.counter] = sourceSignal; - - //start fft - for (int i = 0; i < graphAcc.size; i++) { - vReal[i] = (double) graphAcc.source[i]; - vImag[i] = 0; - } - FFT.Windowing(vReal, graphAcc.size, FFT_WIN_TYP_RECTANGLE, FFT_FORWARD); - FFT.Compute(vReal, vImag, graphAcc.size, FFT_FORWARD); - FFT.ComplexToMagnitude(vReal, vImag, graphAcc.size); - for (int i = 0; i < graphAcc.size/2; i++) { - graphAcc.fft[i] = map((int) vReal[i], 0, 15000, 200, 0); - } } accelerometer.lastUpdate = millis(); @@ -131,14 +112,12 @@ void handleNotFound() void sendAccelerometerData() { int updateRate = 0; - if (fftMode) updateRate = 200; - else updateRate = graphAcc.updateRate; + updateRate = 50; if (millis() - lastDataSend > updateRate) { String word; - cookAccelerometer(word, graphAcc.fft, graphAcc.size/2); + cookAccelerometer(word, graphAcc.array, graphAcc.size); webSocket.broadcastTXT(word); - Serial.println(word); lastDataSend = millis(); } }