|
|
@ -12,12 +12,32 @@ ESP8266WebServer server(80); |
|
|
|
long int lastUpdate = 0; |
|
|
|
int acc = 0; |
|
|
|
|
|
|
|
const int graph_size = 200; |
|
|
|
int graph1[graph_size] = { 200 }; |
|
|
|
int graph1counter = 0; |
|
|
|
int graphUpdate = 50; // Раз в секунду
|
|
|
|
class Graph { |
|
|
|
public: |
|
|
|
int graphSize; |
|
|
|
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; |
|
|
|
this->graphUpdateRate = graphUpdateRate; // Раз в секунду
|
|
|
|
graphArray = new int[graphSize]; |
|
|
|
graphCounter = 0; |
|
|
|
} |
|
|
|
|
|
|
|
Graph () { |
|
|
|
Graph(200, 50); |
|
|
|
} |
|
|
|
|
|
|
|
}; // Раз в секунду
|
|
|
|
|
|
|
|
Graph graphAccelerometer; |
|
|
|
|
|
|
|
void handleAccelerometer() |
|
|
|
{ |
|
|
@ -29,8 +49,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 != graph_size - 1; i++) { |
|
|
|
bias += snprintf((html_code+bias), arr_size - bias, "context.lineTo(%i*2, %i);", i, graph1[i]); |
|
|
|
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]); |
|
|
|
} |
|
|
|
bias += getHtml(SCRIPT_END, *html_code, arr_size, bias); |
|
|
|
//bias += snprintf((html_code+bias), arr_size - bias, "<br />Current accelerometer: %i", acc);
|
|
|
@ -43,17 +63,17 @@ void handleAccelerometer() |
|
|
|
|
|
|
|
void updateAccelerometer() |
|
|
|
{ |
|
|
|
if ((millis() - lastUpdate) > (1000 / graphUpdate)) |
|
|
|
if ((millis() - lastUpdate) > (1000 / graphAccelerometer.graphUpdateRate)) |
|
|
|
{ |
|
|
|
acc = map(analogRead(A0), 512, 768, 200, 0); |
|
|
|
if (graph1counter < graph_size - 1) { |
|
|
|
graph1[graph1counter] = acc; |
|
|
|
graph1counter++; |
|
|
|
if (graphAccelerometer.graphCounter < graphAccelerometer.graphSize - 1) { |
|
|
|
graphAccelerometer.graphArray[graphAccelerometer.graphCounter] = acc; |
|
|
|
graphAccelerometer.graphCounter++; |
|
|
|
} else { |
|
|
|
for(int i = 0; i != graph1counter; i++) { |
|
|
|
graph1[i] = graph1[i + 1]; |
|
|
|
for(int i = 0; i != graphAccelerometer.graphCounter; i++) { |
|
|
|
graphAccelerometer.graphArray[i] = graphAccelerometer.graphArray[i + 1]; |
|
|
|
} |
|
|
|
graph1[graph1counter] = acc; |
|
|
|
graphAccelerometer.graphArray[graphAccelerometer.graphCounter] = acc; |
|
|
|
} |
|
|
|
lastUpdate = millis(); |
|
|
|
} |
|
|
@ -78,6 +98,7 @@ void handleNotFound() |
|
|
|
|
|
|
|
void setup(void) |
|
|
|
{ |
|
|
|
graphAccelerometer = Graph(200, 50); |
|
|
|
pinMode(A0, INPUT); |
|
|
|
Serial.begin(115200); |
|
|
|
WiFi.softAP(ssid); |
|
|
|