ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ButtonHandler.h
Go to the documentation of this file.
1/**
2 * @file ButtonHandler.h
3 * @brief Declares the ButtonHandler class for managing button input and state.
4 *
5 * This file defines the ButtonHandler class, which provides static methods for
6 * initializing a button, handling interrupts, and retrieving button states and values.
7 *
8 * @date 22/12/2024
9 * @author Coela Can't
10 */
11
12#pragma once
13
14#include <Arduino.h> // Include for Arduino compatibility.
15
16/**
17 * @class ButtonHandler
18 * @brief Manages button input and state with interrupt support.
19 *
20 * The ButtonHandler class provides static methods for initializing a button,
21 * handling button press and hold logic, and retrieving the current state and value.
22 */
24private:
25 static long previousMillisISR; ///< Tracks the last interrupt service routine (ISR) trigger time in milliseconds.
26 static long previousMillisHold; ///< Tracks the last hold event time in milliseconds.
27 static uint16_t holdingToggle; ///< Time threshold for detecting holding behavior in milliseconds.
28 static uint8_t currentValue; ///< The current value of the button (e.g., press count).
29 static uint8_t maxValue; ///< The maximum value for the button press count.
30 static uint8_t pin; ///< The pin number associated with the button.
31 static bool holdingState; ///< Indicates whether the button is in a holding state.
32
33 /**
34 * @brief Interrupt service routine (ISR) for handling button presses.
35 */
36 static void isr();
37
38public:
39 /**
40 * @brief Initializes the ButtonHandler with specified parameters.
41 *
42 * @param pin The pin number associated with the button.
43 * @param maxValue The maximum value for the button press count.
44 * @param holdingToggle The time threshold for detecting holding behavior in milliseconds.
45 */
46 static void Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle);
47
48 /**
49 * @brief Retrieves the holding state of the button.
50 *
51 * @return True if the button is being held, false otherwise.
52 */
53 static bool GetHoldingState();
54
55 /**
56 * @brief Retrieves the current value of the button.
57 *
58 * @return The current button value (e.g., press count).
59 */
60 static uint8_t GetValue();
61};
Manages button input and state with interrupt support.
static uint16_t holdingToggle
Time threshold for detecting holding behavior in milliseconds.
static long previousMillisISR
Tracks the last interrupt service routine (ISR) trigger time in milliseconds.
static void Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle)
Initializes the ButtonHandler with specified parameters.
static long previousMillisHold
Tracks the last hold event time in milliseconds.
static void isr()
Interrupt service routine (ISR) for handling button presses.
static bool GetHoldingState()
Retrieves the holding state of the button.
static uint8_t GetValue()
Retrieves the current value of the button.
static uint8_t pin
The pin number associated with the button.
static uint8_t maxValue
The maximum value for the button press count.
static bool holdingState
Indicates whether the button is in a holding state.
static uint8_t currentValue
The current value of the button (e.g., press count).