2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
DebouncedButtonSet.h
Go to the documentation of this file.
1
4
25
26#pragma once
27
28#include <stdint.h>
29
31
32template <size_t N>
34 public:
37 : m_buttonSet(buttons), m_initialized(false), m_numButtons(N) {}
38
40
42
43 void Initialize() {
44 if (!m_initialized) {
45 for (size_t i = 0; i < N; ++i) {
47 }
48 }
49 m_initialized = true;
50 }
51
52 void Update() {
53 if (m_initialized) {
54 for (size_t i = 0; i < N; ++i) {
56 }
57 }
58 }
59
60 bool GetValue(size_t idx) const {
61 bool retVal = false;
62 if (m_initialized && idx < N) {
63 retVal = m_buttonSet[idx].GetValue();
64 }
65 return retVal;
66 }
67
68 bool GetRawValue(size_t idx) const {
69 bool retVal = false;
70 if (m_initialized && idx < N) {
71 retVal = m_buttonSet[idx].GetRawValue();
72 }
73 return retVal;
74 }
75
76 void Reset(bool newValue = false) {
77 if (m_initialized) {
78 for (size_t i = 0; i < N; ++i) {
79 m_buttonSet[i].Reset(newValue);
80 }
81 }
82 }
83 void Reset(size_t idx, bool newValue = false) {
84 if (m_initialized && idx < N) {
85 m_buttonSet[idx].Reset(newValue);
86 }
87 }
88
89 void SetDebounceCount(size_t idx, uint16_t newCount) {
90 if (m_initialized && idx < N) {
91 m_buttonSet[idx].SetDebounceCount(newCount);
92 }
93 }
94 void SetDebounceCount(uint16_t newCount) {
95 if (m_initialized) {
96 for (size_t i = 0; i < N; ++i) {
97 m_buttonSet[i].SetDebounceCount(newCount);
98 }
99 }
100 }
101
102 size_t GetNumButtons() const { return m_numButtons; }
103
104 private:
107 const size_t m_numButtons;
108};
Abstracted digital input with debouncing applied.
Definition DebouncedButtonSet.h:33
DebouncedDigitalInput m_buttonSet[N]
Definition DebouncedButtonSet.h:105
bool GetValue(size_t idx) const
Definition DebouncedButtonSet.h:60
void Update()
Definition DebouncedButtonSet.h:52
DebouncedButtonSet(DebouncedDigitalInput(&&buttons)[N])
Definition DebouncedButtonSet.h:36
void Reset(bool newValue=false)
Definition DebouncedButtonSet.h:76
bool m_initialized
Definition DebouncedButtonSet.h:106
DebouncedButtonSet()=delete
size_t GetNumButtons() const
Definition DebouncedButtonSet.h:102
void SetDebounceCount(uint16_t newCount)
Definition DebouncedButtonSet.h:94
void SetDebounceCount(size_t idx, uint16_t newCount)
Definition DebouncedButtonSet.h:89
bool GetRawValue(size_t idx) const
Definition DebouncedButtonSet.h:68
DebouncedButtonSet(const DebouncedButtonSet &)=delete
const size_t m_numButtons
Definition DebouncedButtonSet.h:107
DebouncedButtonSet & operator=(const DebouncedButtonSet &)=delete
void Reset(size_t idx, bool newValue=false)
Definition DebouncedButtonSet.h:83
void Initialize()
Definition DebouncedButtonSet.h:43
Definition DebouncedDigitalInput.h:32
bool GetValue() const
Definition DebouncedDigitalInput.cpp:88
bool Update()
Definition DebouncedDigitalInput.cpp:68
bool GetRawValue() const
Definition DebouncedDigitalInput.cpp:92
void Initialize()
Definition DebouncedDigitalInput.cpp:55
void SetDebounceCount(uint16_t newCount)
Definition DebouncedDigitalInput.cpp:102
void Reset(bool newValue=false)
Definition DebouncedDigitalInput.cpp:96