3
3
4
4
#include "core/Button.h"
5
5
#include "core/Encoder.h"
6
-
7
- #include " core/VirtEncButton.h"
8
- #include " core/utils.h"
9
-
10
- // ===================== CLASS =====================
11
- class EncButton : public VirtEncButton {
12
- public:
13
- // настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
14
- EncButton (uint8_t encA = 0 , uint8_t encB = 0 , uint8_t btn = 0 , uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
15
- init (encA, encB, btn, modeEnc, modeBtn);
16
- setButtonLevel (LOW);
17
- }
18
-
19
- // настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
20
- void init (uint8_t encA = 0 , uint8_t encB = 0 , uint8_t btn = 0 , uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
21
- e0 = encA;
22
- e1 = encB;
23
- b = btn;
24
- pinMode (e0 , modeEnc);
25
- pinMode (e1 , modeEnc);
26
- pinMode (b, modeBtn);
27
- initEnc (readEnc ());
28
- }
29
-
30
- // ====================== TICK ======================
31
- // функция обработки для вызова в прерывании энкодера
32
- int8_t tickISR () {
33
- return VirtEncButton::tickISR (readEnc ());
34
- }
35
-
36
- // функция обработки, вызывать в loop
37
- int8_t tick () {
38
- return VirtEncButton::tick (readEnc (), EBread (b));
39
- }
40
-
41
- // ====================== READ ======================
42
- // прочитать значение кнопки
43
- bool readBtn () {
44
- return EBread (b) ^ read_bf (EB_INV);
45
- }
46
-
47
- // прочитать значение энкодера
48
- int8_t readEnc () {
49
- return EBread (e0 ) | (EBread (e1 ) << 1 );
50
- }
51
-
52
- // ===================== PRIVATE =====================
53
- private:
54
- uint8_t e0 , e1 , b;
55
- };
56
-
57
- // ===================== T CLASS =====================
58
- template <uint8_t ENCA, uint8_t ENCB, uint8_t BTN>
59
- class EncButtonT : public VirtEncButton {
60
- public:
61
- // настроить пины (энк, энк, кнопка, pinmode энк, pinmode кнопка)
62
- EncButtonT (uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
63
- init (modeEnc, modeBtn);
64
- setButtonLevel (LOW);
65
- }
66
-
67
- // настроить пины (pinmode энк, pinmode кнопка)
68
- void init (uint8_t modeEnc = INPUT, uint8_t modeBtn = INPUT_PULLUP) {
69
- pinMode (ENCA, modeEnc);
70
- pinMode (ENCB, modeEnc);
71
- pinMode (BTN, modeBtn);
72
- initEnc (readEnc ());
73
- }
74
-
75
- // ====================== TICK ======================
76
- // функция обработки для вызова в прерывании энкодера
77
- int8_t tickISR () {
78
- return VirtEncButton::tickISR (readEnc ());
79
- }
80
-
81
- // функция обработки, вызывать в loop
82
- int8_t tick () {
83
- return VirtEncButton::tick (readEnc (), EBread (BTN));
84
- }
85
-
86
- // ====================== READ ======================
87
- // прочитать значение кнопки
88
- bool readBtn () {
89
- return EBread (BTN) ^ read_bf (EB_INV);
90
- }
91
-
92
- // прочитать значение энкодера
93
- int8_t readEnc () {
94
- return EBread (ENCA) | (EBread (ENCB) << 1 );
95
- }
96
-
97
- // ===================== PRIVATE =====================
98
- private:
99
- };
6
+ #include "core/EncButton.h"
0 commit comments