uses intIntput for in/export routes
This commit is contained in:
@@ -11,6 +11,18 @@
|
|||||||
|
|
||||||
#include "menuRoute.h"
|
#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) {
|
MenuRoute::MenuRoute(Route* route) {
|
||||||
this->route = route;
|
this->route = route;
|
||||||
}
|
}
|
||||||
@@ -68,9 +80,9 @@ void MenuRoute::no() {
|
|||||||
|
|
||||||
|
|
||||||
void MenuRoute::init() {
|
void MenuRoute::init() {
|
||||||
auto dummy = []() {
|
// auto dummy = []() {
|
||||||
std::cout << "Dummy in Action" <<std::endl;
|
// std::cout << "Dummy in Action" <<std::endl;
|
||||||
};
|
// };
|
||||||
|
|
||||||
this->mainMenu = new Menu;
|
this->mainMenu = new Menu;
|
||||||
MenuRoutePoints* pointsMenu = new MenuRoutePoints(this->route);
|
MenuRoutePoints* pointsMenu = new MenuRoutePoints(this->route);
|
||||||
@@ -82,19 +94,31 @@ void MenuRoute::init() {
|
|||||||
importMenu->setLcd(this->lcd);
|
importMenu->setLcd(this->lcd);
|
||||||
exportMenu->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* pointsAction = new MenuAction("Points", pointsMenu);
|
||||||
MenuAction* importAction = new MenuAction("Import", dummy);
|
MenuAction* importAction = new MenuAction("Import", importWrapper);
|
||||||
MenuAction* exportAction = new MenuAction("Export", dummy);
|
MenuAction* exportAction = new MenuAction("Export", exportWrapper);
|
||||||
|
|
||||||
this->mainMenu->addEntry(pointsAction);
|
this->mainMenu->addEntry(pointsAction);
|
||||||
this->mainMenu->addEntry(importAction);
|
this->mainMenu->addEntry(importAction);
|
||||||
this->mainMenu->addEntry(exportAction);
|
this->mainMenu->addEntry(exportAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuRoute::importRoute() {
|
void MenuRoute::importRoute(uint8_t routeNumber) {
|
||||||
this->blockInput = true;
|
this->blockInput = true;
|
||||||
// ask user for route number!
|
|
||||||
uint8_t routeNumber = 1;
|
|
||||||
|
|
||||||
String lineOne = "";
|
String lineOne = "";
|
||||||
String lineTwo = "";
|
String lineTwo = "";
|
||||||
@@ -119,7 +143,9 @@ void MenuRoute::importRoute() {
|
|||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
DynamicJsonDocument doc(JSON_DOCUMENT_SIZE_ROUTE);
|
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();
|
int httpResponseCode = http.GET();
|
||||||
|
|
||||||
lineOne = "HTTP Response";
|
lineOne = "HTTP Response";
|
||||||
@@ -133,8 +159,10 @@ void MenuRoute::importRoute() {
|
|||||||
lineTwo.concat(httpResponseCode);
|
lineTwo.concat(httpResponseCode);
|
||||||
this->print(lineOne, lineTwo);
|
this->print(lineOne, lineTwo);
|
||||||
|
|
||||||
if (httpResponseCode <= 0)
|
if (httpResponseCode <= 0) {
|
||||||
|
this->blockInput = false;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t totalPoints = doc["amountPoints"];
|
uint16_t totalPoints = doc["amountPoints"];
|
||||||
|
|
||||||
@@ -143,17 +171,15 @@ void MenuRoute::importRoute() {
|
|||||||
Point::Coordinates coords;
|
Point::Coordinates coords;
|
||||||
coords.lat = doc["points"][i][0].as<double>();
|
coords.lat = doc["points"][i][0].as<double>();
|
||||||
coords.lon = doc["points"][i][1].as<double>();
|
coords.lon = doc["points"][i][1].as<double>();
|
||||||
this->route->addPointToRoute(Point(coords));
|
this->route->addPointToRoute(Point(coords, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
this->blockInput = false;
|
this->blockInput = false;
|
||||||
http.end();
|
http.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuRoute::exportRoute() {
|
void MenuRoute::exportRoute(uint8_t routeNumber) {
|
||||||
this->blockInput = true;
|
this->blockInput = true;
|
||||||
// ask user for route number!
|
|
||||||
uint8_t routeNumber = 1;
|
|
||||||
uint16_t totalPoints = this->route->getRouteInfo().totalPoints;
|
uint16_t totalPoints = this->route->getRouteInfo().totalPoints;
|
||||||
|
|
||||||
String lineOne = "";
|
String lineOne = "";
|
||||||
@@ -193,7 +219,7 @@ void MenuRoute::exportRoute() {
|
|||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
http.begin(client, "rover.kleiax.de");
|
http.begin(client, "http://rover.kleiax.de/api/");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
int httpResponseCode = http.POST(jsonData);
|
int httpResponseCode = http.POST(jsonData);
|
||||||
|
|
||||||
@@ -205,3 +231,25 @@ void MenuRoute::exportRoute() {
|
|||||||
|
|
||||||
http.end();
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,28 @@
|
|||||||
#include "route.h"
|
#include "route.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "menuControl.h"
|
#include "menuControl.h"
|
||||||
|
#include "menuIntInput.h"
|
||||||
#include "menuRoutePoints.h"
|
#include "menuRoutePoints.h"
|
||||||
|
|
||||||
#define JSON_DOCUMENT_SIZE_ROUTE 4096
|
#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 {
|
class MenuRoute : public MenuControl {
|
||||||
public:
|
public:
|
||||||
MenuRoute(Route* route);
|
MenuRoute(Route* route);
|
||||||
@@ -37,12 +55,11 @@ class MenuRoute : public MenuControl {
|
|||||||
void yes() override;
|
void yes() override;
|
||||||
void no() override;
|
void no() override;
|
||||||
|
|
||||||
|
void importRoute(uint8_t routeNumber);
|
||||||
|
void exportRoute(uint8_t routeNumber);
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void importRoute();
|
|
||||||
void exportRoute();
|
|
||||||
|
|
||||||
Route* route;
|
Route* route;
|
||||||
Menu* mainMenu;
|
Menu* mainMenu;
|
||||||
|
|
||||||
@@ -50,4 +67,16 @@ class MenuRoute : public MenuControl {
|
|||||||
bool blockInput = false;
|
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
|
#endif // MENU_ROUTE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user