Skip to content

Commit

Permalink
[Software][Cyclope controller] Allowed to power the robot off from th…
Browse files Browse the repository at this point in the history
…e user interface.
  • Loading branch information
RICCIARDI-Adrien committed Dec 8, 2024
1 parent c746c75 commit e809f48
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @file WebPagePowerOff.hpp
* Cleanly power the robot off.
* @author Adrien RICCIARDI
*/
#ifndef HPP_WEB_PAGE_POWER_OFF_HPP
#define HPP_WEB_PAGE_POWER_OFF_HPP

#include <WebPageBase.hpp>

class WebPagePowerOff : public WebPageBase
{
public:
// See base class documentation for description
WebPagePowerOff();

// See base class documentation for description
virtual int generateContent(std::string &referenceStringContent) override;
};

/** Give global access to the page statically allocated instance. */
extern WebPagePowerOff webPagePowerOff;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
*/
#include <WebPageIndex.hpp>
#include <WebPageManualControl.hpp>
#include <WebPagePowerOff.hpp>

WebPageIndex::WebPageIndex() : WebPageBase("/") {};

int WebPageIndex::generateContent(std::string &referenceStringContent)
{
referenceStringContent =
"<h1>Cyclope Controller main menu</h1>\n"
"<div class=\"text-center\">\n"
" <h1>Cyclope Controller main menu</h1>\n"
"</div>\n"
"<p class=\"text-center\">\n"
" <a href=\"" + webPageManualControl.getBaseUrl() + "\">Manual control</a>\n"
" <a href=\"" + webPageManualControl.getBaseUrl() + "\">Manual control</a><br />\n"
" <a href=\"" + webPagePowerOff.getBaseUrl() + "\">Power the robot off</a><br />\n"
"</p>\n";

return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** @file WebPagePowerOff.cpp
* See WebPagePowerOff.hpp for description.
* @author Adrien RICCIARDI
*/
#include <cstdlib>
#include <Log.hpp>
#include <WebPagePowerOff.hpp>

WebPagePowerOff::WebPagePowerOff() : WebPageBase("/power-off") {};

int WebPagePowerOff::generateContent(std::string &referenceStringContent)
{
referenceStringContent =
"<div class=\"text-center\">\n"
" <h1>The robot has been powered off.</h1>\n"
"</div>\n";

LOG(LOG_INFO, "Received the power off command, shutting the system down.");
system("poweroff");

return 0;
}

// The statically allocated instance of the page
WebPagePowerOff webPagePowerOff{};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unordered_map>
#include <WebPageIndex.hpp>
#include <WebPageManualControl.hpp>
#include <WebPagePowerOff.hpp>
#include <WebServer.hpp>

namespace WebServer
Expand Down Expand Up @@ -318,6 +319,7 @@ namespace WebServer
// Create all pages in alphabetical order
_pagesMap.insert({webPageIndex.getBaseUrl(), &webPageIndex});
_pagesMap.insert({webPageManualControl.getBaseUrl(), &webPageManualControl});
_pagesMap.insert({webPagePowerOff.getBaseUrl(), &webPagePowerOff});

return 0;
}
Expand Down

0 comments on commit e809f48

Please sign in to comment.