Files
Bachelorarbeit-Rover/src/SpecialMenus/Route/menuRoute.h
T
2023-10-12 19:50:10 +02:00

174 lines
3.7 KiB
C++

/**
* @file menuRoute.h
* @author Alexander Klein (alex@kleiax.de)
* @brief Contains a classes to handles routes with the user input.
* @version 0.1
* @date 2022-12-28
*
* @copyright Copyright (c) 2022
*
*/
#ifndef MENU_ROUTE_H
#define MENU_ROUTE_H
#include <Arduino.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include "route.h"
#include "menu.h"
#include "menuControl.h"
#include "menuIntInput.h"
#include "menuRoutePoints.h"
#define JSON_DOCUMENT_SIZE_ROUTE 4096
class MenuRoute;
typedef void (MenuRoute::*DataFunction)(uint8_t);
/**
* @brief MenuActionWrapper to call DataFunctions
*
* This class should be used to call importRoute,
* exportRoute and clearRoute over the Menu.
*/
class MenuActionRoute : public MenuActionWrapper
{
public:
/**
* @brief Construct a new Menu Action Route object
*
* @param menuRoute
* @param dataFunction like exportRoute
*/
MenuActionRoute(MenuRoute *menuRoute, DataFunction dataFunction);
/**
* @brief Runs the given DataFunction
*/
void action() override;
private:
MenuRoute *menuRoute;
DataFunction dataFunction;
};
/**
* @brief Handles routes
*
* With this menu the user can import, export and delete routes.
*/
class MenuRoute : public MenuControl
{
public:
/**
* @brief Construct a new Menu Route object
*
* @param route
*/
MenuRoute(Route *route);
~MenuRoute();
/**
* @brief Prints the last informations
*
* On first call this function calls the init function.
* On every call this functions call the printMenu function from
* the mainMenu of this class.
*/
void printMenu() override;
/**
* @name User Inputs
* @brief Inputs given by the parentMenu
*/
///@{
void down() override;
void up() override;
void right() override;
void left() override;
void yes() override;
void no() override;
///@}
/**
* @brief Import a Route.
*
* The functions tries to pull the given route id from the RoverApi.
*
* @param routeNumber id
*/
void importRoute(uint8_t routeNumber);
/**
* @brief Export a Route.
*
* The functions tries to push the current route to the RoverApi.
*
* @param routeNumber id
*/
void exportRoute(uint8_t routeNumber);
/**
* @brief Delete a Route
*
* The functions tries to delete the current route from the RoverApi.
*
* @param routeNumber
*/
void deleteRoute(uint8_t routeNumber);
/**
* @brief Delete the current Route.
*
* @param none this param is not be used.
*/
void clearRoute(uint8_t none);
private:
void init();
Route *route;
Menu *mainMenu = nullptr;
bool isInit = false;
bool blockInput = false;
static constexpr uint8_t maxRouteNumber = 100;
static constexpr uint16_t httpValidExport = 201;
static constexpr uint16_t httpValidImport = 202;
static constexpr uint16_t httpValidDelete = 202;
};
/**
* @brief MenuRouteWrapper to call DataFunctions with numeric user input
*
*/
class MenuRouteWrapper : public MenuIntInputWrapper
{
public:
/**
* @brief Construct a new Menu Route Wrapper object.
*
* @param menuRoute
* @param dataFunction
*/
MenuRouteWrapper(MenuRoute *menuRoute, DataFunction dataFunction);
/**
* @brief Calls the given DataFunction.
*
* @param values The value to be given to the DataFunction.
* @param length Number of values, should be 1.
*/
void action(int16_t *values, uint8_t length) override;
private:
MenuRoute *menuRoute;
DataFunction dataFunction = nullptr;
};
#endif // MENU_ROUTE_H