def gpio_thread(arg): global _state while _state != -1: if BUILDROOT_GPIOD: bulk_event = gpiod.LineBulk([_b1, _b2, _b3]) bulk_event.request(consumer='PiPlayer', type=gpiod.LINE_REQ_EV_FALLING_EDGE) events = bulk_event.event_wait(sec=2) else: bulk_event = gpiod.line_bulk([_b1, _b2, _b3]) config = gpiod.line_request() config.consumer = 'PiPlayer' config.request_type = gpiod.line_request.EVENT_FALLING_EDGE bulk_event.request(config) events = bulk_event.event_wait(timedelta(seconds=2)) if events is None or (not BUILDROOT_GPIOD and events.size == 0): bulk_event.release() continue if BUILDROOT_GPIOD: button = events[0] offset = button.offset() else: button = events.get(0) offset = button.offset sleep(0.5) if button.get_value() == 1: _select_action(offset) bulk_event.release()
def create_empty_line_bulk(): try: lines = gpiod.LineBulk() except TypeError: print('Error as expected') return assert False, 'TypeError expected'
def create_line_bulk_from_lines(): chip = gpiod.Chip('gpio-mockup-A') line1 = chip.get_line(2) line2 = chip.get_line(4) line3 = chip.get_line(6) lines = gpiod.LineBulk([line1, line2, line3]) print('Created LineBulk:') print(lines)
import gpiod import config import event d0 = config.chip.get_line(config.d0) d1 = config.chip.get_line(config.d1) lines = gpiod.LineBulk([d0, d1]) lines.request(consumer=config.name, type=gpiod.LINE_REQ_DIR_IN) # prevent initial interrupt lines.release() lines.request(consumer=config.name, type=gpiod.LINE_REQ_EV_FALLING_EDGE) reading = False data = 0 class Card: def __init__(self, number, facility): self.number = number self.facility = facility def __str__(self): return f'{self.facility}:{self.number}' def parity(datain, p): while datain: p ^= datain & 1 datain >>= 1 return p