-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathK197PushButtons.h
96 lines (76 loc) · 3.15 KB
/
K197PushButtons.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**************************************************************************/
/*!
@file K197PushButtons.h
Arduino K197Display sketch
Copyright (C) 2022 by ALX2009
License: MIT (see LICENSE)
This file is part of the Arduino K197Display sketch, please see
https://github.com/alx2009/K197Display for more information
This file defines the k197ButtonCluster class, responsible for managing the
push button cluster on the front panel
*/
/**************************************************************************/
#ifndef __ABUTTON_H
#define __ABUTTON_H
#include <Arduino.h>
#include "UIevents.h"
/**************************************************************************/
/*!
@brief Simple class to handle a cluster of buttons.
This class handles a cluster of buttons. The number and PIN mapping are
hardwired in the implementation file.
There are many libraries to handle buttons, but I never found one that
handles debouncing reliably without resulting in a sluggish response... but
feel free to clone the repository and replace with your favorite pushbutton
library!
*/
/**************************************************************************/
class k197ButtonCluster {
public:
k197ButtonCluster(){}; ///< default constructor
typedef void (*buttonCallBack)(
K197UIeventsource eventSource,
K197UIeventType eventType); ///< define the type of the callback function
void setup();
protected:
void checkNew(uint8_t i, uint8_t btnow, unsigned long now);
void checkPressed(uint8_t i, unsigned long now);
static const unsigned long longPressTime =
500000L; ///< long press event will be generated when pressed more than
///< longPressTime us
static const unsigned long holdTime =
200000L; ///< After a LongPress Hold events will be generated every
///< holdTime in us while the button is still pressed
static const unsigned long doubleClicktime =
500000L; ///< double click event when pressed within doubleClicktime us
///< from a previous release
// click generator for REL key
static const uint16_t pulseCount = 750; ///< REL click pulse (750=>32 ms)
static const uint16_t totalCount =
15000; ///< REL click pulse+idle time (15000=>640 ms)
static const uint8_t REL_max_pending_clicks =
4; ///< maximum number of REL button clicks that can be queued
void setupClicktimer();
public:
void setCallback(buttonCallBack clusterCallBack);
void checkNew();
bool isPressed(K197UIeventsource eventSource);
/*!
@brief check if two buttons are pressed simultaneously
@param btn1 the event source value corresponding to the first button
@param btn2 the event source value corresponding to the second button
@return true if the two buttons are pressed simultaneously, false
otherwise
*/
bool isSimultaneousPress(K197UIeventsource btn1, K197UIeventsource btn2) {
if (isPressed(btn1) && isPressed(btn2)) {
return true;
}
return false;
}
static void DebugOut_printEventName(K197UIeventType event);
void clickREL();
void cancelClickREL();
};
extern k197ButtonCluster pushbuttons;
#endif //__ABUTTON_H