gpiozero
gpiozero copied to clipboard
RotaryEncoder _change_state using invalid state string
In _change_state, you check for new_state == "+1" or "-1" (old values), but the new_state is pulled from TRANSITIONS, which include "cw1" and "ccw1". This causes all of the when_rotated??? functions to not get called.
I think there's some misapprehension here: "+1" and "-1" are the final states in the state-machine that the encoder moves through with each notch (this is illustrated in the comments below the state table). For example, say the encoder is turned clockwise one notch: we expect to transition through the states idle -> cw1 -> cw2 -> cw3 -> +1 -> idle in that single notch, with the "+1" state triggering the necessary events.
Incidentally, those events do fire if that sequence of edges is observed; if they didn't then the corresponding test case should fail (not to mention I tested this with a couple of different encoders from different manufacturers).
If this isn't working on your setup it may be worth trying to treat your encoder as two Button objects and see if they trigger "when_pressed" events in the expected sequence as the encoder is rotated.