Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit 357ec31

Browse files
committed
Added automatic refresh.
HTML source is converted to C/C++ string using this online converter: https://tomeko.net/online_tools/cpp_text_escape.php
1 parent 3651a65 commit 357ec31

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

robot-control-src/Drives.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ using Distance = std::int16_t; //!< in [mm]
1010
struct Position
1111
{
1212
Distance x, y;
13+
bool operator==(const Position& rhs) const
14+
{
15+
return x == rhs.x && y == rhs.y;
16+
}
17+
bool operator!=(const Position& rhs) const
18+
{
19+
return !(*this == rhs);
20+
}
1321
};
1422

1523
namespace drives

robot-control-src/control-mask.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<title>Robot Control</title>
55
<meta charset="utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.6">
7+
<meta http-equiv="refresh" content="5">
78
</head>
89
<body>
910
<main>

robot-control-src/robot-control-src.ino

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static constexpr char htmlSourceTemplate[] =
2828
" <title>Robot Control</title>\n"
2929
" <meta charset=\"utf-8\" />\n"
3030
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.6\">\n"
31+
" <meta http-equiv=\"refresh\" content=\"5\">\n"
3132
" </head>\n"
3233
" <body>\n"
3334
" <main>\n"
@@ -58,7 +59,7 @@ void updateHtmlSource()
5859
char * const backBuffer = (htmlSourceFrontBuffer.load() == htmlSourceBackBufferA) ? htmlSourceBackBufferB : htmlSourceBackBufferA;
5960
char positionStringBuffer[positionsStringMaxLength] = { 0 };
6061
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++)
6263
{
6364
const int writtenCharacters = snprintf(&(positionStringBuffer[charPos]), maxCharPerPosition+1, "%i;%i;", positions[i].x, positions[i].y);
6465
assert(writtenCharacters>0);
@@ -100,10 +101,7 @@ static void handleRoot()
100101
newTarget.isTargetNew = true;
101102
Serial.printf("Got right by %u!\n", newTarget.newRotate);
102103
}
103-
else
104-
{
105-
server.send(200, "text/html", htmlSourceFrontBuffer.load());
106-
}
104+
server.send(200, "text/html", htmlSourceFrontBuffer.load());
107105
digitalWrite(board::debugLed, HIGH);
108106
}
109107

@@ -144,25 +142,33 @@ void setup()
144142
server.begin();
145143
Serial.printf("webserver has IP %s\n", WiFi.localIP().toString().c_str());
146144
server.on("/", handleRoot);
145+
updateHtmlSource();
147146
}
148147

149148
void loop()
150149
{
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+
}
168174
}

0 commit comments

Comments
 (0)