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
30
#include "
DebouncedDigitalInput.h
"
31
32
template
<
size_t
N>
33
class
DebouncedButtonSet
{
34
public
:
35
DebouncedButtonSet
() =
delete
;
36
explicit
DebouncedButtonSet
(
DebouncedDigitalInput
(&&buttons)[N])
37
:
m_buttonSet
(buttons),
m_initialized
(false),
m_numButtons
(N) {}
38
39
DebouncedButtonSet
(
const
DebouncedButtonSet
&) =
delete
;
40
41
DebouncedButtonSet
&
operator=
(
const
DebouncedButtonSet
&) =
delete
;
42
43
void
Initialize
() {
44
if
(!
m_initialized
) {
45
for
(
size_t
i = 0; i < N; ++i) {
46
m_buttonSet
[i].
Initialize
();
47
}
48
}
49
m_initialized
=
true
;
50
}
51
52
void
Update
() {
53
if
(
m_initialized
) {
54
for
(
size_t
i = 0; i < N; ++i) {
55
m_buttonSet
[i].
Update
();
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
:
105
DebouncedDigitalInput
m_buttonSet
[N];
106
bool
m_initialized
;
107
const
size_t
m_numButtons
;
108
};
DebouncedDigitalInput.h
Abstracted digital input with debouncing applied.
DebouncedButtonSet
Definition
DebouncedButtonSet.h:33
DebouncedButtonSet::m_buttonSet
DebouncedDigitalInput m_buttonSet[N]
Definition
DebouncedButtonSet.h:105
DebouncedButtonSet::GetValue
bool GetValue(size_t idx) const
Definition
DebouncedButtonSet.h:60
DebouncedButtonSet::Update
void Update()
Definition
DebouncedButtonSet.h:52
DebouncedButtonSet::DebouncedButtonSet
DebouncedButtonSet(DebouncedDigitalInput(&&buttons)[N])
Definition
DebouncedButtonSet.h:36
DebouncedButtonSet::Reset
void Reset(bool newValue=false)
Definition
DebouncedButtonSet.h:76
DebouncedButtonSet::m_initialized
bool m_initialized
Definition
DebouncedButtonSet.h:106
DebouncedButtonSet::DebouncedButtonSet
DebouncedButtonSet()=delete
DebouncedButtonSet::GetNumButtons
size_t GetNumButtons() const
Definition
DebouncedButtonSet.h:102
DebouncedButtonSet::SetDebounceCount
void SetDebounceCount(uint16_t newCount)
Definition
DebouncedButtonSet.h:94
DebouncedButtonSet::SetDebounceCount
void SetDebounceCount(size_t idx, uint16_t newCount)
Definition
DebouncedButtonSet.h:89
DebouncedButtonSet::GetRawValue
bool GetRawValue(size_t idx) const
Definition
DebouncedButtonSet.h:68
DebouncedButtonSet::DebouncedButtonSet
DebouncedButtonSet(const DebouncedButtonSet &)=delete
DebouncedButtonSet::m_numButtons
const size_t m_numButtons
Definition
DebouncedButtonSet.h:107
DebouncedButtonSet::operator=
DebouncedButtonSet & operator=(const DebouncedButtonSet &)=delete
DebouncedButtonSet::Reset
void Reset(size_t idx, bool newValue=false)
Definition
DebouncedButtonSet.h:83
DebouncedButtonSet::Initialize
void Initialize()
Definition
DebouncedButtonSet.h:43
DebouncedDigitalInput
Definition
DebouncedDigitalInput.h:32
DebouncedDigitalInput::GetValue
bool GetValue() const
Definition
DebouncedDigitalInput.cpp:88
DebouncedDigitalInput::Update
bool Update()
Definition
DebouncedDigitalInput.cpp:68
DebouncedDigitalInput::GetRawValue
bool GetRawValue() const
Definition
DebouncedDigitalInput.cpp:92
DebouncedDigitalInput::Initialize
void Initialize()
Definition
DebouncedDigitalInput.cpp:55
DebouncedDigitalInput::SetDebounceCount
void SetDebounceCount(uint16_t newCount)
Definition
DebouncedDigitalInput.cpp:102
DebouncedDigitalInput::Reset
void Reset(bool newValue=false)
Definition
DebouncedDigitalInput.cpp:96
src
OperatorController
DebouncedButtonSet.h
Generated by
1.9.8