|
5 | 5 |
|
6 | 6 | CYD28_TouchR touch(320, 240); |
7 | 7 |
|
| 8 | +#ifdef WAVESENTRY |
| 9 | +#include <RotaryEncoder.h> |
| 10 | +RotaryEncoder *encoder = nullptr; |
| 11 | +IRAM_ATTR void checkPosition() { encoder->tick(); } |
| 12 | +#endif |
| 13 | + |
8 | 14 | /*************************************************************************************** |
9 | 15 | ** Function name: _setup_gpio() |
10 | 16 | ** Location: main.cpp |
11 | 17 | ** Description: initial setup for the device |
12 | 18 | ***************************************************************************************/ |
13 | | -void _setup_gpio() { pinMode(TFT_BL, OUTPUT); } |
| 19 | +void _setup_gpio() { |
| 20 | + pinMode(TFT_BL, OUTPUT); |
| 21 | +#ifdef WAVESENTRY |
| 22 | + pinMode(ENCODER_KEY, INPUT); |
| 23 | + encoder = new RotaryEncoder(ENCODER_INA, ENCODER_INB, RotaryEncoder::LatchMode::TWO03); |
| 24 | + attachInterrupt(digitalPinToInterrupt(ENCODER_INA), checkPosition, CHANGE); |
| 25 | + attachInterrupt(digitalPinToInterrupt(ENCODER_INB), checkPosition, CHANGE); |
| 26 | +#endif |
| 27 | +} |
14 | 28 |
|
15 | 29 | /*************************************************************************************** |
16 | 30 | ** Function name: _post_setup_gpio() |
@@ -59,8 +73,8 @@ void _setBrightness(uint8_t brightval) { |
59 | 73 | ** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress |
60 | 74 | **********************************************************************/ |
61 | 75 | void InputHandler(void) { |
62 | | - static long tm = millis(); |
63 | | - if (millis() - tm > 300 || LongPress) { // don´t allow multiple readings in less than 200ms |
| 76 | + static unsigned long tm = millis(); |
| 77 | + if (millis() - tm > 200 || LongPress) { // don´t allow multiple readings in less than 200ms |
64 | 78 | if (touch.touched()) { |
65 | 79 | auto t = touch.getPointScaled(); |
66 | 80 | t = touch.getPointScaled(); |
@@ -91,6 +105,41 @@ void InputHandler(void) { |
91 | 105 | touchHeatMap(touchPoint); |
92 | 106 | } else touchPoint.pressed = false; |
93 | 107 | } |
| 108 | + |
| 109 | +#ifdef WAVESENTRY |
| 110 | + static int posDifference = 0; |
| 111 | + static int lastPos = 0; |
| 112 | + bool sel = !BTN_ACT; |
| 113 | + |
| 114 | + int newPos = encoder->getPosition(); |
| 115 | + if (newPos != lastPos) { |
| 116 | + posDifference += (newPos - lastPos); |
| 117 | + lastPos = newPos; |
| 118 | + } |
| 119 | + |
| 120 | + if (millis() - tm < 200 && !LongPress) return; |
| 121 | + |
| 122 | + sel = digitalRead(ENCODER_KEY); |
| 123 | + |
| 124 | + if (posDifference != 0 || sel == BTN_ACT) { |
| 125 | + if (!wakeUpScreen()) AnyKeyPress = true; |
| 126 | + else return; |
| 127 | + } |
| 128 | + if (posDifference > 0) { |
| 129 | + PrevPress = true; |
| 130 | + posDifference--; |
| 131 | + } |
| 132 | + if (posDifference < 0) { |
| 133 | + NextPress = true; |
| 134 | + posDifference++; |
| 135 | + } |
| 136 | + |
| 137 | + if (sel == BTN_ACT) { |
| 138 | + posDifference = 0; |
| 139 | + SelPress = true; |
| 140 | + tm = millis(); |
| 141 | + } |
| 142 | +#endif |
94 | 143 | } |
95 | 144 |
|
96 | 145 | /********************************************************************* |
|
0 commit comments