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
*/
23
class
ButtonHandler
{
24
private
:
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
38
public
:
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
};
ButtonHandler
Manages button input and state with interrupt support.
Definition
ButtonHandler.h:23
ButtonHandler::holdingToggle
static uint16_t holdingToggle
Time threshold for detecting holding behavior in milliseconds.
Definition
ButtonHandler.h:27
ButtonHandler::previousMillisISR
static long previousMillisISR
Tracks the last interrupt service routine (ISR) trigger time in milliseconds.
Definition
ButtonHandler.h:25
ButtonHandler::Initialize
static void Initialize(uint8_t pin, uint8_t maxValue, uint16_t holdingToggle)
Initializes the ButtonHandler with specified parameters.
Definition
ButtonHandler.cpp:20
ButtonHandler::previousMillisHold
static long previousMillisHold
Tracks the last hold event time in milliseconds.
Definition
ButtonHandler.h:26
ButtonHandler::isr
static void isr()
Interrupt service routine (ISR) for handling button presses.
Definition
ButtonHandler.cpp:11
ButtonHandler::GetHoldingState
static bool GetHoldingState()
Retrieves the holding state of the button.
Definition
ButtonHandler.cpp:29
ButtonHandler::GetValue
static uint8_t GetValue()
Retrieves the current value of the button.
Definition
ButtonHandler.cpp:42
ButtonHandler::pin
static uint8_t pin
The pin number associated with the button.
Definition
ButtonHandler.h:30
ButtonHandler::maxValue
static uint8_t maxValue
The maximum value for the button press count.
Definition
ButtonHandler.h:29
ButtonHandler::holdingState
static bool holdingState
Indicates whether the button is in a holding state.
Definition
ButtonHandler.h:31
ButtonHandler::currentValue
static uint8_t currentValue
The current value of the button (e.g., press count).
Definition
ButtonHandler.h:28
lib
ProtoTracer
ExternalDevices
InputDevices
ButtonHandler.h
Generated by
1.9.8