kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Improve encoder precision.
rodzic
4d98d7aecf
commit
982005736a
|
@ -29,21 +29,19 @@ class Encoder:
|
||||||
yirq = pin_y.irq(trigger=trig, handler=self._y_cb)
|
yirq = pin_y.irq(trigger=trig, handler=self._y_cb)
|
||||||
asyncio.create_task(self._run(vmin, vmax, div, callback, args))
|
asyncio.create_task(self._run(vmin, vmax, div, callback, args))
|
||||||
|
|
||||||
# Hardware IRQ's. Duration 36μs on Pyboard 1.
|
# Hardware IRQ's. Duration 36μs on Pyboard 1 ~50μs on ESP32.
|
||||||
|
# IRQ latency: 2nd edge may have occured by the time ISR runs, in
|
||||||
|
# which case there is no movement.
|
||||||
def _x_cb(self, pin_x):
|
def _x_cb(self, pin_x):
|
||||||
if (x := pin_x()) == self._x: # IRQ latency: if 2nd edge has
|
if (x := pin_x()) != self._x:
|
||||||
return # occurred there is no movement.
|
|
||||||
self._x = x
|
self._x = x
|
||||||
fwd = x ^ self._pin_y()
|
self._v += 1 if x ^ self._pin_y() else -1
|
||||||
self._v += 1 if fwd else -1
|
|
||||||
self._tsf.set()
|
self._tsf.set()
|
||||||
|
|
||||||
def _y_cb(self, pin_y):
|
def _y_cb(self, pin_y):
|
||||||
if (y := pin_y()) == self._y:
|
if (y := pin_y()) != self._y:
|
||||||
return
|
|
||||||
self._y = y
|
self._y = y
|
||||||
fwd = y ^ self._pin_x() ^ 1
|
self._v += 1 if y ^ self._pin_x() ^ 1 else -1
|
||||||
self._v += 1 if fwd else -1
|
|
||||||
self._tsf.set()
|
self._tsf.set()
|
||||||
|
|
||||||
async def _run(self, vmin, vmax, div, cb, args):
|
async def _run(self, vmin, vmax, div, cb, args):
|
||||||
|
|
Ładowanie…
Reference in New Issue