8 A class to read Wiegand codes of an arbitrary length. 10 The code length and value are returned. 22 def callback(bits, code): 23 print("bits={} code={}".format(bits, code)) 27 w = wiegand.decoder(pi, 14, 15, callback) 36 def __init__(self, pi, gpio_0, gpio_1, callback, bit_timeout=5):
39 Instantiate with the pi, gpio for 0 (green wire), the gpio for 1 40 (white wire), the callback function, and the bit timeout in 41 milliseconds which indicates the end of a code. 43 The callback is passed the code length in bits and the value. 56 self.pi.set_mode(gpio_0, pigpio.INPUT)
57 self.pi.set_mode(gpio_1, pigpio.INPUT)
59 self.pi.set_pull_up_down(gpio_0, pigpio.PUD_UP)
60 self.pi.set_pull_up_down(gpio_1, pigpio.PUD_UP)
62 self.
cb_0 = self.pi.callback(gpio_0, pigpio.FALLING_EDGE, self.
_cb)
63 self.
cb_1 = self.pi.callback(gpio_1, pigpio.FALLING_EDGE, self.
_cb)
65 def _cb(self, gpio, level, tick):
68 Accumulate bits until both gpios 0 and 1 timeout. 71 if level < pigpio.TIMEOUT:
101 self.pi.set_watchdog(self.
gpio_0, 0)
102 self.pi.set_watchdog(self.
gpio_1, 0)
109 Cancel the Wiegand decoder. 115 if __name__ ==
"__main__":
124 print(
"bits={} value={}".format(bits, value))
def _cb(self, gpio, level, tick)
def callback(bits, value)
def __init__(self, pi, gpio_0, gpio_1, callback, bit_timeout=5)