kopia lustrzana https://github.com/peterhinch/micropython-samples
Encoders: Rename x_callback to a_callback and y_callback to b_callback
Oops!pull/23/head
rodzic
c2a8a10f15
commit
59ddd7a90c
|
@ -51,11 +51,11 @@ class Encoder:
|
|||
self.a_interrupt = pin_a.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.a_callback)
|
||||
self.b_interrupt = pin_b.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.b_callback)
|
||||
|
||||
def x_callback(self, pin):
|
||||
def a_callback(self, pin):
|
||||
self.forward = pin() ^ self.pin_b()
|
||||
self._pos += 1 if self.forward else -1
|
||||
|
||||
def y_callback(self, pin):
|
||||
def b_callback(self, pin):
|
||||
self.forward = self.pin_a() ^ pin() ^ 1
|
||||
self._pos += 1 if self.forward else -1
|
||||
|
||||
|
|
|
@ -17,11 +17,11 @@ class Encoder:
|
|||
self.a_interrupt = pyb.ExtInt(pin_a, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_NONE, self.a_callback)
|
||||
self.b_interrupt = pyb.ExtInt(pin_b, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_NONE, self.b_callback)
|
||||
|
||||
def x_callback(self, line):
|
||||
def a_callback(self, line):
|
||||
self.forward = self.pin_a.value() ^ self.pin_b.value() ^ self.reverse
|
||||
self._pos += 1 if self.forward else -1
|
||||
|
||||
def y_callback(self, line):
|
||||
def b_callback(self, line):
|
||||
self.forward = self.pin_a.value() ^ self.pin_b.value() ^ self.reverse ^ 1
|
||||
self._pos += 1 if self.forward else -1
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@ class Encoder:
|
|||
self.a_interrupt = pin_a.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.a_callback)
|
||||
self.b_interrupt = pin_b.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.b_callback)
|
||||
|
||||
def x_callback(self, pin):
|
||||
def a_callback(self, pin):
|
||||
self._pos += 1 if (pin() ^ self.pin_b()) else -1
|
||||
|
||||
def y_callback(self, pin):
|
||||
def b_callback(self, pin):
|
||||
self._pos += 1 if (self.pin_a() ^ pin() ^ 1) else -1
|
||||
|
||||
def position(self, value=None):
|
||||
|
|
|
@ -23,13 +23,13 @@ class EncoderTimed:
|
|||
self.a_interrupt = pin_a.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.a_callback)
|
||||
self.b_interrupt = pin_b.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=self.b_callback)
|
||||
|
||||
def x_callback(self, pin):
|
||||
def a_callback(self, pin):
|
||||
self.forward = pin() ^ self.pin_b()
|
||||
self._pos += 1 if self.forward else -1
|
||||
self.tprev = self.tlast
|
||||
self.tlast = utime.ticks_us()
|
||||
|
||||
def y_callback(self, pin):
|
||||
def b_callback(self, pin):
|
||||
self.forward = self.pin_a() ^ pin() ^ 1
|
||||
self._pos += 1 if self.forward else -1
|
||||
self.tprev = self.tlast
|
||||
|
|
Ładowanie…
Reference in New Issue