@@ -28,6 +28,7 @@ static constexpr char htmlSourceTemplate[] =
28
28
" <title>Robot Control</title>\n "
29
29
" <meta charset=\" utf-8\" />\n "
30
30
" <meta name=\" viewport\" content=\" width=device-width, initial-scale=1.6\" >\n "
31
+ " <meta http-equiv=\" refresh\" content=\" 5\" >\n "
31
32
" </head>\n "
32
33
" <body>\n "
33
34
" <main>\n "
@@ -58,7 +59,7 @@ void updateHtmlSource()
58
59
char * const backBuffer = (htmlSourceFrontBuffer.load () == htmlSourceBackBufferA) ? htmlSourceBackBufferB : htmlSourceBackBufferA;
59
60
char positionStringBuffer[positionsStringMaxLength] = { 0 };
60
61
std::size_t charPos = 0 ;
61
- for (std::size_t i=0 ; i<positionIndex; i++)
62
+ for (std::size_t i=0 ; i<= positionIndex; i++)
62
63
{
63
64
const int writtenCharacters = snprintf (&(positionStringBuffer[charPos]), maxCharPerPosition+1 , " %i;%i;" , positions[i].x , positions[i].y );
64
65
assert (writtenCharacters>0 );
@@ -100,10 +101,7 @@ static void handleRoot()
100
101
newTarget.isTargetNew = true ;
101
102
Serial.printf (" Got right by %u!\n " , newTarget.newRotate );
102
103
}
103
- else
104
- {
105
- server.send (200 , " text/html" , htmlSourceFrontBuffer.load ());
106
- }
104
+ server.send (200 , " text/html" , htmlSourceFrontBuffer.load ());
107
105
digitalWrite (board::debugLed, HIGH);
108
106
}
109
107
@@ -144,25 +142,33 @@ void setup()
144
142
server.begin ();
145
143
Serial.printf (" webserver has IP %s\n " , WiFi.localIP ().toString ().c_str ());
146
144
server.on (" /" , handleRoot);
145
+ updateHtmlSource ();
147
146
}
148
147
149
148
void loop ()
150
149
{
151
- server.handleClient ();
152
- // Serial.printf("left: \t%3u, right: \t%3u\n", drives::LeftDrive::counter, drives::RightDrive::counter);
153
- if (drives::LeftDrive::isIdle && drives::RightDrive::isIdle && newTarget.isTargetNew )
154
- {
155
- positions[positionIndex++] = drives::flushCurrentPosition ();
156
- positionIndex %= numberOfPositions;
157
- if (newTarget.newDrive !=0 )
158
- {
159
- drives::driveCounter (newTarget.newDrive , drives::cruiseSpeed, !newTarget.forward );
160
- }
161
- else if (newTarget.newRotate !=0 )
162
- {
163
- drives::rotateCounter (newTarget.newRotate , drives::cruiseSpeed, newTarget.clockwise );
164
- }
165
- newTarget = { };
166
- }
167
- updateHtmlSource ();
150
+ server.handleClient ();
151
+ // Serial.printf("left: \t%3u, right: \t%3u\n", drives::LeftDrive::counter, drives::RightDrive::counter);
152
+ if (drives::LeftDrive::isIdle && drives::RightDrive::isIdle)
153
+ {
154
+ const Position newPositionCandidate = drives::flushCurrentPosition ();
155
+ if (positions[positionIndex] != newPositionCandidate)
156
+ {
157
+ positions[++positionIndex] = newPositionCandidate;
158
+ positionIndex %= numberOfPositions;
159
+ updateHtmlSource ();
160
+ }
161
+ if (newTarget.isTargetNew )
162
+ {
163
+ if (newTarget.newDrive !=0 )
164
+ {
165
+ drives::driveCounter (newTarget.newDrive , drives::cruiseSpeed, !newTarget.forward );
166
+ }
167
+ else if (newTarget.newRotate !=0 )
168
+ {
169
+ drives::rotateCounter (newTarget.newRotate , drives::cruiseSpeed, newTarget.clockwise );
170
+ }
171
+ newTarget = { };
172
+ }
173
+ }
168
174
}
0 commit comments