8
8
9
9
RotaryEncoderImpl *rotaryEncoderImpl;
10
10
11
- RotaryEncoderImpl::RotaryEncoderImpl () : concurrency::OSThread(ORIGIN_NAME), originName(ORIGIN_NAME)
11
+ RotaryEncoderImpl::RotaryEncoderImpl ()
12
12
{
13
13
rotary = nullptr ;
14
14
}
@@ -18,7 +18,6 @@ bool RotaryEncoderImpl::init()
18
18
if (!moduleConfig.canned_message .updown1_enabled || moduleConfig.canned_message .inputbroker_pin_a == 0 ||
19
19
moduleConfig.canned_message .inputbroker_pin_b == 0 ) {
20
20
// Input device is disabled.
21
- disable ();
22
21
return false ;
23
22
}
24
23
@@ -30,44 +29,48 @@ bool RotaryEncoderImpl::init()
30
29
moduleConfig.canned_message .inputbroker_pin_press );
31
30
rotary->resetButton ();
32
31
33
- inputBroker->registerSource (this );
32
+ interruptInstance = this ;
33
+ auto interruptHandler = []() { inputBroker->requestPollSoon (interruptInstance); };
34
+ attachInterrupt (moduleConfig.canned_message .inputbroker_pin_a , interruptHandler, CHANGE);
35
+ attachInterrupt (moduleConfig.canned_message .inputbroker_pin_b , interruptHandler, CHANGE);
36
+ attachInterrupt (moduleConfig.canned_message .inputbroker_pin_press , interruptHandler, CHANGE);
34
37
35
38
LOG_INFO (" RotaryEncoder initialized pins(%d, %d, %d), events(%d, %d, %d)" , moduleConfig.canned_message .inputbroker_pin_a ,
36
39
moduleConfig.canned_message .inputbroker_pin_b , moduleConfig.canned_message .inputbroker_pin_press , eventCw, eventCcw,
37
40
eventPressed);
38
41
return true ;
39
42
}
40
43
41
- int32_t RotaryEncoderImpl::runOnce ()
44
+ void RotaryEncoderImpl::pollOnce ()
42
45
{
43
- InputEvent e{originName, INPUT_BROKER_NONE, 0 , 0 , 0 };
46
+ InputEvent e{ORIGIN_NAME, INPUT_BROKER_NONE, 0 , 0 , 0 };
47
+
44
48
static uint32_t lastPressed = millis ();
45
49
if (rotary->readButton () == RotaryEncoder::ButtonState::BUTTON_PRESSED) {
46
50
if (lastPressed + 200 < millis ()) {
47
51
LOG_DEBUG (" Rotary event Press" );
48
52
lastPressed = millis ();
49
53
e.inputEvent = this ->eventPressed ;
50
- }
51
- } else {
52
- switch (rotary->process ()) {
53
- case RotaryEncoder::DIRECTION_CW:
54
- LOG_DEBUG (" Rotary event CW" );
55
- e.inputEvent = this ->eventCw ;
56
- break ;
57
- case RotaryEncoder::DIRECTION_CCW:
58
- LOG_DEBUG (" Rotary event CCW" );
59
- e.inputEvent = this ->eventCcw ;
60
- break ;
61
- default :
62
- break ;
54
+ inputBroker->queueInputEvent (&e);
63
55
}
64
56
}
65
57
66
- if (e.inputEvent != INPUT_BROKER_NONE) {
67
- this ->notifyObservers (&e);
58
+ switch (rotary->process ()) {
59
+ case RotaryEncoder::DIRECTION_CW:
60
+ LOG_DEBUG (" Rotary event CW" );
61
+ e.inputEvent = this ->eventCw ;
62
+ inputBroker->queueInputEvent (&e);
63
+ break ;
64
+ case RotaryEncoder::DIRECTION_CCW:
65
+ LOG_DEBUG (" Rotary event CCW" );
66
+ e.inputEvent = this ->eventCcw ;
67
+ inputBroker->queueInputEvent (&e);
68
+ break ;
69
+ default :
70
+ break ;
68
71
}
69
-
70
- return 10 ;
71
72
}
72
73
74
+ RotaryEncoderImpl *RotaryEncoderImpl::interruptInstance;
75
+
73
76
#endif
0 commit comments