def __init__(self, channelA, channelB, bounceTime=150): IO.setup(channelA, IO.IN, pull_up_down=IO.PUD_UP) IO.setup(channelB, IO.IN, pull_up_down=IO.PUD_UP) self._Channels = (channelA, channelB) self._InterObsLeft = Common.MemObservable() self._InterObsRight = Common.MemObservable() def rising(chn): time.sleep(0.002) inA = IO.input(self._Channels[0]) inB = IO.input(self._Channels[1]) if inA == 1 and inB == 0: self._InterObsRight.emit(True) return elif inA == 1 and inB == 1: self._InterObsLeft.emit(True) return IO.add_event_detect(self._Channels[0], IO.RISING, callback=rising, bouncetime=bounceTime)
def __init__(self, channel, bounceTime=300, hasPullDown=True): if hasPullDown: IO.setup(channel, IO.IN, pull_up_down=IO.PUD_DOWN) else: IO.setup(channel, IO.IN) self._Channel = channel self._InterObs = Common.MemObservable() def emit(channel): self._InterObs.emit(True) IO.add_event_detect(channel, IO.RISING, callback=emit, bouncetime=bounceTime)
def __init__(self, inCh, outCh, bounceTime=500): self._InterObs = Common.MemObservable() if len(inCh) != 3 or len(outCh) != 4: raise ValueError("wron number of chnals") for i in inCh: IO.setup(i, IO.IN, pull_up_down=IO.PUD_DOWN) for i in outCh: IO.setup(i, IO.OUT) def setAllOut(value): for i in outCh: IO.output(i, value) def _interupt(chan): table = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["*", "0", "#"]] setAllOut(0) countFound = 0 foundCor = None for oChannelId in range(len(outCh)): IO.output(outCh[oChannelId], 1) for iChannelId in range(len(inCh)): if IO.input(inCh[iChannelId]): countFound += 1 foundCor = (oChannelId, iChannelId) IO.output(outCh[oChannelId], 0) setAllOut(1) if countFound > 1: # connot detect corect button print("WARNING: pres only one button!") sys.stdout.flush() return if countFound == 0: return self._InterObs.emit(table[foundCor[0]][foundCor[1]]) setAllOut(1) for i in inCh: IO.add_event_detect(i, IO.RISING, callback=_interupt, bouncetime=bounceTime)
def clearAllSubscriptions(self): self._InterObsLeft = Common.MemObservable() self._InterObsRight = Common.MemObservable()
def clearAllSubscriptions(self): self._InterObs = Common.MemObservable()
def clear(self): self._InterObs = Common.MemObservable()