ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
SingleButtonMorseHandler.h
Go to the documentation of this file.
1/**
2 * @file SingleButtonMorseHandler.h
3 * @brief Declares the MenuHandler template class for managing single-button menu interactions with Morse code input.
4 *
5 * This file defines the MenuHandler template class, which provides functionality for handling
6 * single-button menu navigation, Morse code input processing, and persistent settings storage using EEPROM.
7 *
8 * @date 22/12/2024
9 * @author aaronze
10 */
11
12#pragma once
13
14#include <Arduino.h> // Include for Arduino compatibility.
15#include <EEPROM.h> // Include for EEPROM functionality.
16
17/**
18 * @class MenuHandler
19 * @brief Manages single-button menu navigation and settings storage.
20 *
21 * The MenuHandler class provides functionality for navigating through menus and managing settings
22 * using a single button. It supports Morse code input for advanced interaction and persistent storage through EEPROM.
23 *
24 * @tparam menuCount The number of menus to manage.
25 */
26template <uint8_t menuCount>
27class MenuHandler {
28private:
29 static bool previousState; ///< Tracks the previous state of the button.
30 static long previousMillis; ///< Tracks the last button press time in milliseconds.
31 static uint8_t inputCount; ///< Number of Morse code inputs received.
32 static uint16_t inputStream[4]; ///< Buffer for storing Morse code input.
33 static uint8_t currentMenu; ///< Index of the currently active menu.
34 static uint8_t currentValue[menuCount]; ///< Array of current values for each menu.
35 static uint8_t maxValue[menuCount]; ///< Array of maximum values for each menu.
36 static uint8_t pin; ///< The pin number associated with the button.
37
38 /**
39 * @brief Reads a value from EEPROM at the specified index.
40 *
41 * @param index The EEPROM address to read from.
42 * @return The value read from EEPROM.
43 */
44 static uint8_t ReadEEPROM(uint16_t index);
45
46 /**
47 * @brief Writes a value to EEPROM at the specified index.
48 *
49 * @param index The EEPROM address to write to.
50 * @param value The value to write to EEPROM.
51 */
52 static void WriteEEPROM(uint16_t index, uint8_t value);
53
54public:
55 /**
56 * @brief Begins the menu handling process, setting up necessary states.
57 */
58 static void Begin();
59
60 /**
61 * @brief Initializes the MenuHandler with specified parameters.
62 *
63 * @param pin The pin number associated with the button.
64 * @param holdingTime The time threshold for detecting holding behavior in milliseconds.
65 * @return True if initialization was successful, false otherwise.
66 */
67 static bool Initialize(uint8_t pin, uint16_t holdingTime);
68
69 /**
70 * @brief Sets a default value for a specific menu.
71 *
72 * @param menu The menu index to set the default value for.
73 * @param value The default value to set.
74 */
75 static void SetDefaultValue(uint16_t menu, uint8_t value);
76
77 /**
78 * @brief Marks the menu system as initialized.
79 */
80 static void SetInitialized();
81
82 /**
83 * @brief Sets the maximum value for a specific menu.
84 *
85 * @param menu The menu index to set the maximum value for.
86 * @param maxValue The maximum value to set.
87 */
88 static void SetMenuMax(uint8_t menu, uint8_t maxValue);
89
90 /**
91 * @brief Updates the menu system and processes button input.
92 */
93 static void Update();
94
95 /**
96 * @brief Retrieves the current value of a specific menu.
97 *
98 * @param menu The menu index to retrieve the value from.
99 * @return The current value of the menu.
100 */
101 static uint8_t GetMenuValue(uint8_t menu);
102
103 /**
104 * @brief Retrieves the index of the currently active menu.
105 *
106 * @return The index of the active menu.
107 */
108 static uint8_t GetCurrentMenu();
109};
110
111#include "SingleButtonMorseHandler.tpp" // Include the template implementation.
Manages multiple menus and settings using Adafruit NeoTrellis.
static bool Initialize(uint8_t pin, uint16_t holdingTime)
Initializes the MenuHandler with specified parameters.
static long previousMillis
Tracks the last button press time in milliseconds.
static void WriteEEPROM(uint16_t index, uint8_t value)
Writes a value to EEPROM at the specified index.
static void SetInitialized()
Marks the menu system as initialized.
static void SetMenuMax(uint8_t menu, uint8_t maxValue)
Sets the maximum value for a specific menu.
static uint8_t currentMenu
Index of the currently active menu.
static void Update()
Updates the menu system and processes button input.
static uint8_t GetMenuValue(uint8_t menu)
Retrieves the current value of a specific menu.
static uint8_t maxValue[menuCount]
Array of maximum values for each menu.
static uint8_t pin
The pin number associated with the button.
static void Begin()
Begins the menu handling process, setting up necessary states.
static uint8_t inputCount
Number of Morse code inputs received.
static bool previousState
Tracks the previous state of the button.
static uint8_t GetCurrentMenu()
Retrieves the index of the currently active menu.
static uint16_t holdingTime
Time threshold for detecting holding behavior in milliseconds.
static uint16_t inputStream[4]
Buffer for storing Morse code input.
static void SetDefaultValue(uint16_t menu, uint8_t value)
Sets a default value for a specific menu.
static uint8_t currentValue[menuCount]
Array of current values for each menu.
static uint8_t ReadEEPROM(uint16_t index)
Reads a value from EEPROM at the specified index.