MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / Poll

Method Poll

src/Display/RotaryEncoder.cpp:56–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56void RotaryEncoder::Poll() noexcept
57{
58 // State transition table. Each entry has the following meaning:
59 // 0 - the encoder hasn't moved
60 // 1 or 2 - the encoder has moved 1 or 2 units clockwise
61 // -1 or -2 = the encoder has moved 1 or 2 units anticlockwise
62 static const int8_t tbl[16] =
63 {
64 0, +1, -1, 0, // position 3 = 00 to 11, can't really do anything, so 0
65 -1, 0, 0, +1, // position 2 = 01 to 10, can't really do anything, so 0
66 +1, 0, 0, -1, // position 1 = 10 to 01, can't really do anything, so 0
67 0, -1, +1, 0 // position 0 = 11 to 00, can't really do anything, so 0
68 };
69
70 // Poll the encoder
71 const unsigned int t = ReadEncoderState();
72 const int8_t movement = tbl[(encoderState << 2) | t];
73 if (movement != 0)
74 {
75 encoderChange += (int)movement;
76 encoderState = t;
77 }
78
79 // Poll the button
80 const uint32_t now = millis();
81 const bool b = !digitalRead(pinButton);
82 if (b == buttonState)
83 {
84 whenSame = now;
85 }
86 else if (now - whenSame > DebounceMillis)
87 {
88 buttonState = b;
89 whenSame = now;
90 if (buttonState)
91 {
92 newPress = true;
93 }
94 }
95}
96
97int RotaryEncoder::GetChange() noexcept
98{

Callers 1

SpinMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected