Skip to content

Commit

Permalink
[Software][Cyclope controller] Stopped the robot and turned off its l…
Browse files Browse the repository at this point in the history
…ights when exiting from the manual control page.
  • Loading branch information
RICCIARDI-Adrien committed Dec 8, 2024
1 parent 8b08b46 commit c746c75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ int WebPageManualControl::generateContent(std::string &referenceStringContent)
" handleKeyEvent(false, event);\n"
" };\n"
"\n"
" // Make sure the robot is stopped when leaving the page\n"
" onbeforeunload = (event) =>\n"
" {\n"
" // Stop the robot\n"
" command = CommunicationProtocol.COMMUNICATION_PROTOCOL_COMMAND_SET_MOTION + RobotMotion.ROBOT_MOTION_STOP;\n"
" communicationProtocolSendCommand(command);\n"
"\n"
" // Turn lights off\n"
" command = CommunicationProtocol.COMMUNICATION_PROTOCOL_COMMAND_SET_LIGHT_ENABLED + '0';\n"
" communicationProtocolSendCommand(command);\n"
" }\n"
"\n"
" function setUserInterfaceControlText(htmlElementId, text)\n"
" {\n"
" userInterfaceControl = document.getElementById(htmlElementId);\n"
Expand Down Expand Up @@ -180,7 +192,7 @@ int WebPageManualControl::generateContent(std::string &referenceStringContent)
"<p id=\"label-lights-status\">Lights : disabled</p>\n"
"<p id=\"label-robot-motion-status\">Motion : stopped</p>\n"
"<p class=\"text-center\">\n"
" <a href=\"" + webPageIndex.getBaseUrl() + "\">Back</a>\n" // TODO stop robot movement when clicked
" <a href=\"" + webPageIndex.getBaseUrl() + "\">Back</a>\n"
"</p>\n";

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ namespace WebServer
" <head>\n"
" <title>Cyclope Controller</title>\n"
" <link rel=\"icon\" href=\"data:,\">\n" // Disable the favicon.ico request from the browser
" <meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\">\n" // These 3 meta tags should prevent the browser from caching the page
" <meta http-equiv=\"Pragma\" content=\"no-cache\">\n"
" <meta http-equiv=\"Expires\" content=\"0\">\n"
" <style>\n"
" .text-center\n"
" {\n"
Expand Down Expand Up @@ -81,7 +84,7 @@ namespace WebServer
" async function communicationProtocolSendCommand(stringCommand)\n"
" {\n"
" // Send the POST request\n"
" response = await fetch(\"/api\", { method: \"POST\", body: stringCommand });\n"
" response = await fetch(\"/api\", { method: \"POST\", body: stringCommand, keepalive: true });\n" // The "keepalive" flag tells the brower to continue the fetch calls even if the calling page is unloaded (this is useful to send commands to the robot in the "beforeunload" event handler)
" if (!response.ok) return \"error\";\n"
" // Wait for the server answer\n"
" commandAnswer = await response.text();\n"
Expand Down

0 comments on commit c746c75

Please sign in to comment.