mFrame
載入中...
搜尋中...
無符合項目
SimpleButton.h
1
7#ifndef MFRAME_FBF90B99_35F5_429B_B9EF_6AFB9BF6C331
8#define MFRAME_FBF90B99_35F5_429B_B9EF_6AFB9BF6C331
9
10/* ***************************************************************************************
11 * Include
12 */
13
14//----------------------------------------------------------------------------------------
15#include "./../hw/PulseTimer.h"
16#include "./../lang/Object.h"
17#include "./../lang/Updatable.h"
18
19//----------------------------------------------------------------------------------------
20
21/* ***************************************************************************************
22 * Namespace
23 */
24namespace ufm::hw {
25 class SimpleButton;
26} // namespace ufm::hw
27
28/* ***************************************************************************************
29 * Class/Interface/Struct/Enum
30 */
34 /* *************************************************************************************
35 * Class/Interface/Struct/Enum - PressType
36 */
37 public:
43 union Flag {
44 struct {
45 bool first : 1;
46 bool firstRelease : 1;
47 bool second : 1;
48 bool handle : 1;
49 } bits;
50 uint8 value;
51 };
52
53 /* *************************************************************************************
54 * Class/Interface/Struct/Enum - State
55 */
56 public:
62 enum class State : uint8 {
67 NONE
68 };
69
70 /* *************************************************************************************
71 * Class/Interface/Struct/Enum - Event
72 */
73 public:
79 struct Event {
80 /* ***********************************************************************************
81 * Method
82 */
83
90 virtual void onPress(State state) abstract;
91 };
92
93 /* *************************************************************************************
94 * Variable
95 */
96 public:
97 ufm::hw::PulseTimer vPulseTimer;
104 /* *************************************************************************************
105 * Abstract Method
106 */
107
108 /* *************************************************************************************
109 * Construct Method
110 */
111 public:
121 SimpleButton(Event* event = nullptr,
122 uint32 debounce = 10000UL,
123 uint32 shortPress = 100000UL,
124 uint32 longPress = 2000000UL);
125
130 virtual ~SimpleButton(void) override;
131
132 /* *************************************************************************************
133 * Operator Method
134 */
135
136 /* *************************************************************************************
137 * Override - ufm::hw::PulseTimer::Event
138 */
139 public:
147 virtual void onHighDuration(uint32 microscronds) override;
148
156 virtual void onLowDuration(uint32 microscronds) override;
157
158 /* *************************************************************************************
159 * Override - ufm::lang::Updatable
160 */
161 public:
168 virtual void update(void) override;
169
170 /* *************************************************************************************
171 * Public Method
172 */
173 public:
179 inline void setLongPress(uint32 micros) {
180 this->vLongPressThreshold = micros; // 設定長按時間
181 }
182
188 inline void setShortPress(uint32 micros) {
189 this->vShortPressThreshold = micros; // 設定短按時間
190 }
191
197 inline void setNagetive(bool nagetive) {
198 this->vNagetive = nagetive;
199 return;
200 }
201
207 inline void setEvent(Event* event) {
208 this->vEvent = event; // 設定按鈕事件處理物件
209 return;
210 }
211
218 return this->vPulseTimer;
219 }
220
221 /* *************************************************************************************
222 * Protected Method
223 */
224
225 /* *************************************************************************************
226 * Private Method
227 */
228 private:
229 void handleRise(uint32 micros);
230
231 void handleFall(uint32 micros);
232
233 /* *************************************************************************************
234 * Static Variable
235 */
236
237 /* *************************************************************************************
238 * Static Method
239 */
240};
241
242/* ***************************************************************************************
243 * End of file
244 */
245
246#endif /* MFRAME_FBF90B99_35F5_429B_B9EF_6AFB9BF6C331 */
脈衝計時器類
Definition PulseTimer.h:41
Definition SimpleButton.h:33
virtual void onHighDuration(uint32 microscronds) override
處理高電平持續時間事件。
void setLongPress(uint32 micros)
設定長按時間。
Definition SimpleButton.h:179
void setShortPress(uint32 micros)
設定短按時間。
Definition SimpleButton.h:188
hal::digital::EdgeTrigger::Event & getEdgeTriggerEvent(void)
取得邊緣觸發事件物件。
Definition SimpleButton.h:217
SimpleButton(Event *event=nullptr, uint32 debounce=10000UL, uint32 shortPress=100000UL, uint32 longPress=2000000UL)
Construct a new Simple Button object.
virtual ~SimpleButton(void) override
Destroy the object.
Flag vFlag
Definition SimpleButton.h:101
void setNagetive(bool nagetive)
設定是否為反向按鈕。
Definition SimpleButton.h:197
Event * vEvent
Definition SimpleButton.h:98
State
按鈕按壓類型枚舉。
Definition SimpleButton.h:62
uint32 vShortPressThreshold
Definition SimpleButton.h:99
virtual void update(void) override
更新方法
bool vNagetive
Definition SimpleButton.h:102
virtual void onLowDuration(uint32 microscronds) override
處理低電平持續時間事件。
uint32 vLongPressThreshold
Definition SimpleButton.h:100
void setEvent(Event *event)
設定按鈕事件處理物件。
Definition SimpleButton.h:207
物件基底類別
Definition Object.h:63
Definition Ammeter.h:22
[Interface] 邊緣觸發事件處理介面。
Definition EdgeTrigger.h:102
[Interface] 高低電平持續時間事件處理介面。
Definition PulseTimer.h:64
[Interface] 按鈕事件處理介面。
Definition SimpleButton.h:79
virtual void onPress(State state) override
處理按鈕按壓事件。
[Interface] 定義可更新的物件介面
Definition Updatable.h:38
[Union] 按鈕狀態標誌。
Definition SimpleButton.h:43
bool handle
Definition SimpleButton.h:48
bool second
Definition SimpleButton.h:47
bool first
Definition SimpleButton.h:45
bool firstRelease
Definition SimpleButton.h:46
uint8 value
Definition SimpleButton.h:50