/** * @file menuIntInput.h * @author Alexander Klein (alex@kleiax.de) * @brief Contains a class to get integer inputs from the user * @version 0.1 * @date 2022-09-12 * * @copyright Copyright (c) 2022 * */ #ifndef MENU_INT_INPUT_H #define MENU_INT_INPUT_H #include "menuControl.h" #include #define MAX_NAME_LENGTH 12 /** * @brief Interface to transfer the integer data */ class MenuIntInputWrapper { public: virtual ~MenuIntInputWrapper() {} /** * @brief Transfer function * * This function will be called by MenuIntInput, if the input * are confirmed. * * @param values * @param length amount of integer */ virtual void action(int16_t *values, uint8_t length) = 0; }; /** * @brief A Menu class to make integer inputs */ class MenuIntInput : public MenuControl { public: /** * @brief Construct a new Menu Int Input object * * @param values the integer values * @param names names of the values * @param length amount of values * @param wrapper MenuIntInputWrapper */ MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper *wrapper); MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper); ~MenuIntInput(); /** * @brief Set a specific entry * * @param valueNumber the entry * @param name name of entry * @param startValue default value */ void setEntry(uint8_t valueNumber, const char *name, int16_t startValue = 0); /** * @brief Set the minium for a specific value * * @param valueNumber the entry * @param min */ void setMin(uint8_t valueNumber, int16_t min); /** * @brief Set the minimum for all entries * * @param min */ void setMin(int16_t min); /** * @brief Set the maximum for a specific value * * @param valueNumber the entry * @param max */ void setMax(uint8_t valueNumber, int16_t max); /** * @brief Set the maximum for all entries * * @param max */ void setMax(int16_t max); /** * @brief Set the minium and the maximum for a specific value * * @param valueNumber the entry * @param min * @param max */ void setMinMax(uint8_t valueNumber, int16_t min, int16_t max); /** * @brief Set the minium and the maximum for all entries * * @param min * @param max */ void setMinMax(int16_t min, int16_t max); /** * @brief Set the minium, the maximum and the steps for a specific value * * @param valueNumber the entry * @param min * @param max * @param steps for increment and decrement */ void setMinMaxSteps(uint8_t valueNumber, int16_t min, int16_t max, uint8_t steps); /** * @brief Set the minium, the maximum and the steps for all entries * * @param min * @param max * @param steps for increment and decrement */ void setMinMaxSteps(int16_t min, int16_t max, uint8_t steps); void setPrintParentMenu(bool b) { this->printParentMenu = b; } /** * @brief Set the steps for a specific value * * @param valueNumber the entry * @param steps */ void setStepsPerInput(uint8_t valueNumber, uint8_t steps); /** * @brief Set the steps for all entries * * @param steps */ void setStepsPerInput(uint8_t steps); /** * @brief Decrement selected value */ void down() override; /** * @brief Increment selected value */ void up() override; /** * @brief Select next value */ void right() override; /** * @brief Select previous value */ void left() override; /** * @brief Leave menu without saving */ void no() override; /** * @brief Leave menu with saving */ void yes() override; /** * @brief Prints the Information to display and console * * The informations are only printed to the display if it * set. */ void printMenu() override; private: MenuIntInputWrapper *wrapper; bool printParentMenu = true; uint8_t currentPosition = 0; uint8_t length; uint8_t *stepsPerInput; uint8_t countSameActions = 0; int16_t *values; int16_t *originalValues; int16_t *min; int16_t *max; char *names; }; #endif // MENU_INT_INPUT_H