ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
NeoTrellisMenuHandler.h
Go to the documentation of this file.
1/**
2 * @file NeoTrellisMenuHandler.h
3 * @brief Declares the MenuHandler template class for managing menu interactions using Adafruit NeoTrellis.
4 *
5 * This file defines the MenuHandler template class, which provides functionality for managing
6 * multiple menus and settings through an Adafruit NeoTrellis keypad interface, including EEPROM
7 * storage for persistent settings.
8 *
9 * @date 22/12/2024
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include <Arduino.h> // Include for Arduino compatibility.
16#include <EEPROM.h> // Include for EEPROM functionality.
17#include "Adafruit_NeoTrellis.h" // Include for Adafruit NeoTrellis keypad support.
18
19/**
20 * @class MenuHandler
21 * @brief Manages multiple menus and settings using Adafruit NeoTrellis.
22 *
23 * The MenuHandler class provides functionality for navigating and managing settings across
24 * multiple menus, including support for EEPROM storage, custom settings, and dynamic updates.
25 *
26 * @tparam menuCount The number of menus to manage.
27 */
28template <uint8_t menuCount>
30private:
31 static Adafruit_NeoTrellis trellis; ///< Instance of the Adafruit NeoTrellis keypad.
32 static uint8_t currentMenu; ///< Index of the currently active menu.
33 static uint8_t currentSetting; ///< Index of the currently active setting within the 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 faceChoices; ///< Number of face choices available.
37 static bool menuActive; ///< Flag indicating whether the menu is active.
38 static bool isReady; ///< Flag indicating whether the menu system is ready for interaction.
39 static bool didBegin; ///< Flag indicating whether the initialization process has been completed.
40
41 /**
42 * @brief Generates a color value based on a position on a color wheel.
43 *
44 * @param WheelPos The position on the color wheel (0-255).
45 * @return The corresponding 32-bit color value.
46 */
47 static uint32_t Wheel(byte WheelPos);
48
49 /**
50 * @brief Callback function for handling key events on the NeoTrellis keypad.
51 *
52 * @param evt The key event to process.
53 * @return True if the event was handled successfully, false otherwise.
54 */
55 static TrellisCallback blink(keyEvent evt);
56
57 /**
58 * @brief Reads a value from EEPROM at the specified index.
59 *
60 * @param index The EEPROM address to read from.
61 * @return The value read from EEPROM.
62 */
63 static uint8_t ReadEEPROM(uint16_t index);
64
65 /**
66 * @brief Writes a value to EEPROM at the specified index.
67 *
68 * @param index The EEPROM address to write to.
69 * @param value The value to write to EEPROM.
70 */
71 static void WriteEEPROM(uint16_t index, uint8_t value);
72
73 /**
74 * @brief Resets the I2C bus to recover from communication issues.
75 */
76 static void ResetI2CBus();
77
78public:
79 /**
80 * @brief Updates the menu state and processes user interactions.
81 */
82 static void Update();
83
84 /**
85 * @brief Initializes the MenuHandler and sets up the NeoTrellis keypad.
86 *
87 * @return True if initialization was successful, false otherwise.
88 */
89 static bool Initialize();
90
91 /**
92 * @brief Sets a default value for a specific menu.
93 *
94 * @param menu The menu index to set the default value for.
95 * @param value The default value to set.
96 */
97 static void SetDefaultValue(uint16_t menu, uint8_t value);
98
99 /**
100 * @brief Marks the menu system as initialized.
101 */
102 static void SetInitialized();
103
104 /**
105 * @brief Sets the maximum value for a specific menu.
106 *
107 * @param menu The menu index to set the maximum value for.
108 * @param maxValue The maximum value to set.
109 */
110 static void SetMenuMax(uint8_t menu, uint8_t maxValue);
111
112 /**
113 * @brief Retrieves the current value of a specific menu.
114 *
115 * @param menu The menu index to retrieve the value from.
116 * @return The current value of the menu.
117 */
118 static uint8_t GetMenuValue(uint8_t menu);
119
120 /**
121 * @brief Retrieves the index of the currently active menu.
122 *
123 * @return The index of the active menu.
124 */
125 static uint8_t GetCurrentMenu();
126};
127
128#include "NeoTrellisMenuHandler.tpp" // Include the template implementation.
Manages multiple menus and settings using Adafruit NeoTrellis.
static uint32_t Wheel(byte WheelPos)
Generates a color value based on a position on a color wheel.
static bool isReady
Flag indicating whether the menu system is ready for interaction.
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 TrellisCallback blink(keyEvent evt)
Callback function for handling key events on the NeoTrellis keypad.
static uint8_t currentMenu
Index of the currently active menu.
static void Update()
Updates the menu state and processes user interactions.
static uint8_t GetMenuValue(uint8_t menu)
Retrieves the current value of a specific menu.
static bool menuActive
Flag indicating whether the menu is active.
static uint8_t maxValue[menuCount]
Array of maximum values for each menu.
static void ResetI2CBus()
Resets the I2C bus to recover from communication issues.
static uint8_t faceChoices
Number of face choices available.
static Adafruit_NeoTrellis trellis
Instance of the Adafruit NeoTrellis keypad.
static uint8_t currentSetting
Index of the currently active setting within the menu.
static uint8_t GetCurrentMenu()
Retrieves the index of the currently active menu.
static bool Initialize()
Initializes the MenuHandler and sets up the NeoTrellis keypad.
static bool didBegin
Flag indicating whether the initialization process has been completed.
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.