From 952b61e90ae20ac4ff083955174e75fa695c60ee Mon Sep 17 00:00:00 2001 From: Defend Date: Sun, 26 Nov 2017 22:54:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=20=D0=B4=D0=BE=D0=B3=D0=BE=D0=BD=D0=BA?= =?UTF-8?q?=D1=83=20=D0=BA=20=D0=BF=D1=80=D0=B5=D0=B4=D1=8B=D0=B4=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=BC=D1=83=20-=5F-?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2c5eedd..876ab3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,11 +18,6 @@ class Graph { int graphUpdateRate; int * graphArray; int graphCounter; - // int graph_size = 200; - // int graph1[graph_size] = { 200 }; - // int graph1counter = 0; - // int graphUpdate = 50; - Graph (int graphSize, int graphUpdateRate) { this->graphSize = graphSize; @@ -30,14 +25,9 @@ class Graph { graphArray = new int[graphSize]; graphCounter = 0; } - - Graph () { - Graph(200, 50); - } - }; // Раз в секунду -Graph graphAccelerometer; +Graph graphAcc; void handleAccelerometer() { @@ -49,8 +39,8 @@ void handleAccelerometer() bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0); bias += getHtml(STYLE, *html_code, arr_size, bias); bias += getHtml(SCRIPT_BEGIN, *html_code, arr_size, bias); - for (int i = 0; i != graphAccelerometer.graphSize - 1; i++) { - bias += snprintf((html_code+bias), arr_size - bias, "context.lineTo(%i*2, %i);", i, graphAccelerometer.graphArray[i]); + for (int i = 0; i != graphAcc.graphSize - 1; i++) { + bias += snprintf((html_code+bias), arr_size - bias, "context.lineTo(%i*2, %i);", i, graphAcc.graphArray[i]); } bias += getHtml(SCRIPT_END, *html_code, arr_size, bias); //bias += snprintf((html_code+bias), arr_size - bias, "
Current accelerometer: %i", acc); @@ -63,17 +53,17 @@ void handleAccelerometer() void updateAccelerometer() { - if ((millis() - lastUpdate) > (1000 / graphAccelerometer.graphUpdateRate)) + if ((millis() - lastUpdate) > (1000 / graphAcc.graphUpdateRate)) { acc = map(analogRead(A0), 512, 768, 200, 0); - if (graphAccelerometer.graphCounter < graphAccelerometer.graphSize - 1) { - graphAccelerometer.graphArray[graphAccelerometer.graphCounter] = acc; - graphAccelerometer.graphCounter++; + if (graphAcc.graphCounter < graphAcc.graphSize - 1) { + graphAcc.graphArray[graphAcc.graphCounter] = acc; + graphAcc.graphCounter++; } else { - for(int i = 0; i != graphAccelerometer.graphCounter; i++) { - graphAccelerometer.graphArray[i] = graphAccelerometer.graphArray[i + 1]; + for(int i = 0; i != graphAcc.graphCounter; i++) { + graphAcc.graphArray[i] = graphAcc.graphArray[i + 1]; } - graphAccelerometer.graphArray[graphAccelerometer.graphCounter] = acc; + graphAcc.graphArray[graphAcc.graphCounter] = acc; } lastUpdate = millis(); } @@ -98,7 +88,7 @@ void handleNotFound() void setup(void) { - graphAccelerometer = Graph(200, 50); + graphAcc = Graph(200, 50); // Класс графики для акселерометра pinMode(A0, INPUT); Serial.begin(115200); WiFi.softAP(ssid);