micropython-micro-gui
micropython-micro-gui copied to clipboard
Adds support for I2CEncoder.
To add to my other comments, these are my thoughts on a driver for an I2C encoder.
- There is no need to use interrupts. Polling is fast enough and avoids the problems of interrupt context. Note that the pushbutton drivers rely on polling.
- The driver should run an async loop which periodically (~100ms?) reads the position of the encoder.
- It subtracts the position from that last read.
- If the difference is positive it signals the GUI for a forward step, if negative a backward step.
- A zero difference has no effect.
Such a driver could be quite simple.
My encoder driver is something of a special case in its use of interrupts. This is to reduce the likelihood of a missed edge (even in the presence of contact bounce). The I2C chip handles all this nasty hardware stuff, meaning that long gaps can occur between reads.