uses intIntput for in/export routes

This commit is contained in:
2023-01-04 00:19:12 +01:00
parent 523c170f56
commit facfd1d045
2 changed files with 95 additions and 18 deletions
+63 -15
View File
@@ -11,6 +11,18 @@
#include "menuRoute.h"
// MenuActionData::MenuActionData(MenuRoute* menuRoute, MenuActionDataChoose choose) {
// this->menuRoute = menuRoute;
// this->choose = choose;
// }
// void MenuActionData::action() {
// if (this->choose == MenuActionDataChoose::importRoute)
// this->menuRoute->importRoute();
// else if (this->choose == MenuActionDataChoose::exportRoute)
// this->menuRoute->exportRoute();
// }
MenuRoute::MenuRoute(Route* route) {
this->route = route;
}
@@ -68,9 +80,9 @@ void MenuRoute::no() {
void MenuRoute::init() {
auto dummy = []() {
std::cout << "Dummy in Action" <<std::endl;
};
// auto dummy = []() {
// std::cout << "Dummy in Action" <<std::endl;
// };
this->mainMenu = new Menu;
MenuRoutePoints* pointsMenu = new MenuRoutePoints(this->route);
@@ -82,19 +94,31 @@ void MenuRoute::init() {
importMenu->setLcd(this->lcd);
exportMenu->setLcd(this->lcd);
// MenuActionData* importWrapper = new MenuActionData(this, MenuActionData::MenuActionDataChoose::importRoute);
// MenuActionData* exportWrapper = new MenuActionData(this, MenuActionData::MenuActionDataChoose::exportRoute);
MenuIntInput* importWrapper = new MenuIntInput(1, new MenuRouteWrapper(this, &MenuRoute::importRoute));
MenuIntInput* exportWrapper = new MenuIntInput(1, new MenuRouteWrapper(this, &MenuRoute::exportRoute));
importWrapper->setLcd(this->lcd);
importWrapper->setMinMax(0, 100);
importWrapper->setEntry(0, "Import Route");
exportWrapper->setLcd(this->lcd);
exportWrapper->setMinMax(0, 100);
exportWrapper->setEntry(0, "Export Route");
MenuAction* pointsAction = new MenuAction("Points", pointsMenu);
MenuAction* importAction = new MenuAction("Import", dummy);
MenuAction* exportAction = new MenuAction("Export", dummy);
MenuAction* importAction = new MenuAction("Import", importWrapper);
MenuAction* exportAction = new MenuAction("Export", exportWrapper);
this->mainMenu->addEntry(pointsAction);
this->mainMenu->addEntry(importAction);
this->mainMenu->addEntry(exportAction);
}
void MenuRoute::importRoute() {
void MenuRoute::importRoute(uint8_t routeNumber) {
this->blockInput = true;
// ask user for route number!
uint8_t routeNumber = 1;
String lineOne = "";
String lineTwo = "";
@@ -119,7 +143,9 @@ void MenuRoute::importRoute() {
HTTPClient http;
DynamicJsonDocument doc(JSON_DOCUMENT_SIZE_ROUTE);
http.begin(client, "rover.kleiax.de");
String host = "http://rover.kleiax.de/api/";
host.concat(routeNumber);
http.begin(client, host);
int httpResponseCode = http.GET();
lineOne = "HTTP Response";
@@ -133,8 +159,10 @@ void MenuRoute::importRoute() {
lineTwo.concat(httpResponseCode);
this->print(lineOne, lineTwo);
if (httpResponseCode <= 0)
if (httpResponseCode <= 0) {
this->blockInput = false;
return;
}
uint16_t totalPoints = doc["amountPoints"];
@@ -143,17 +171,15 @@ void MenuRoute::importRoute() {
Point::Coordinates coords;
coords.lat = doc["points"][i][0].as<double>();
coords.lon = doc["points"][i][1].as<double>();
this->route->addPointToRoute(Point(coords));
this->route->addPointToRoute(Point(coords, true));
}
this->blockInput = false;
http.end();
}
void MenuRoute::exportRoute() {
void MenuRoute::exportRoute(uint8_t routeNumber) {
this->blockInput = true;
// ask user for route number!
uint8_t routeNumber = 1;
uint16_t totalPoints = this->route->getRouteInfo().totalPoints;
String lineOne = "";
@@ -193,7 +219,7 @@ void MenuRoute::exportRoute() {
WiFiClient client;
HTTPClient http;
http.begin(client, "rover.kleiax.de");
http.begin(client, "http://rover.kleiax.de/api/");
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST(jsonData);
@@ -205,3 +231,25 @@ void MenuRoute::exportRoute() {
http.end();
}
MenuRouteWrapper::MenuRouteWrapper(MenuRoute* menuRoute, DataFunction dataFunction) {
this->menuRoute = menuRoute;
this->dataFunction = dataFunction;
}
void MenuRouteWrapper::action(int16_t* values, uint8_t length) {
if (length < 1) {
std::cout << "Error in MenuRouteWrapper::action" << std::endl;
return;
}
if (values[0] < 0)
values[0] = 0;
if (values[0] > UINT8_MAX)
values[0] = UINT8_MAX;
(this->menuRoute->*this->dataFunction)(values[0]);
}
+32 -3
View File
@@ -20,10 +20,28 @@
#include "route.h"
#include "menu.h"
#include "menuControl.h"
#include "menuIntInput.h"
#include "menuRoutePoints.h"
#define JSON_DOCUMENT_SIZE_ROUTE 4096
// class MenuRoute;
//
// class MenuActionData : public MenuActionWrapper {
// public:
// enum MenuActionDataChoose {
// importRoute,
// exportRoute
// };
// MenuActionData(MenuRoute* menuRoute, MenuActionDataChoose choose);
// void action() override;
// private:
// MenuRoute* menuRoute;
// MenuActionDataChoose choose;
// };
class MenuRoute : public MenuControl {
public:
MenuRoute(Route* route);
@@ -37,12 +55,11 @@ class MenuRoute : public MenuControl {
void yes() override;
void no() override;
void importRoute(uint8_t routeNumber);
void exportRoute(uint8_t routeNumber);
private:
void init();
void importRoute();
void exportRoute();
Route* route;
Menu* mainMenu;
@@ -50,4 +67,16 @@ class MenuRoute : public MenuControl {
bool blockInput = false;
};
typedef void (MenuRoute::*DataFunction)(uint8_t);
class MenuRouteWrapper : public MenuIntInputWrapper {
public:
MenuRouteWrapper(MenuRoute* menuRoute, DataFunction dataFunction);
void action(int16_t* values, uint8_t length) override;
private:
MenuRoute* menuRoute;
DataFunction dataFunction = nullptr;
};
#endif // MENU_ROUTE_H