def killer(self): to = Timeout(1) # Initial value is arbitrary while not after(self.tstop): # Might have been retriggered yield to._ussetdelay(microsUntil(self.tstop)) if self._running and self.callback is not None: self.callback(*self.callback_args) self._running = False
def killer(self): to = Timeout(1) # Initial value is arbitrary while not after(self.tstop): # Might have been retriggered yield to._ussetdelay(microsUntil(self.tstop)) if self._running and self.callback: self.callback(*self.callback_args) self._running = False
def buttoncheck( self): # Generator object: thread which tests and debounces wf = Timeout(self.desc['debounce']) state_id = 0 if self.long_func: longdelay = Delay(self.objSched, self.long_func, self.long_func_args) if self.double_func: doubledelay = Delay(self.objSched) while True: state = self.rawstate() if state != self.buttonstate: # State has changed: act on it now. self.buttonstate = state if state: # Button has been pressed if self.long_func and not longdelay.running(): longdelay.trigger(self.desc['long_press_time'] ) # Start long press delay if self.double_func: if doubledelay.running(): self.double_func(*self.double_func_args) else: # First click: start doubleclick timer doubledelay.trigger(self.desc['double_click_time']) if self.true_func: self.true_func(*self.true_func_args) else: # Button release if self.long_func and longdelay.running(): longdelay.stop( ) # Avoid interpreting a second click as a long push if self.false_func: self.false_func(*self.false_func_args) yield wf() # Ignore further state changes until switch has settled
def barometerthread(out_buf): barometer = Barometer(side_str='X') wf = Timeout(6) # Instantiate a Poller with 60 second timeout. while True: barometer.update() out_buf.write(barometer.output) yield wf()
def oscillator(freq_hz=1): # Toggles X7 forever. outpin = pyb.Pin(pyb.Pin.board.X7, pyb.Pin.OUT_PP) # Push pull output pin on X7 wf = Timeout(1 / (2 * freq_hz)) while True: outpin.low() yield wf() # Duration will be imprecise owing to contention outpin.high() yield wf()
def switchcheck(self): wf = Timeout(Button.DEBOUNCETIME) while True: state = self.pin.value() if state != self.switchstate: self.switchstate = state if state == 0 and self.released_func: self.released_func(*self.released_func_args) elif state == 1 and self.pressed_func: self.pressed_func(*self.pressed_func_args) yield wf()
def switchcheck(self): wf = Timeout(Switch.DEBOUNCETIME) while True: state = self.pin.value() if state != self.switchstate: self.switchstate = state if state == 0 and self.close_func: self.close_func(*self.close_func_args) elif state == 1 and self.open_func: self.open_func(*self.open_func_args) yield wf()
def switchcheck( self): # Generator object: thread which tests and debounces wf = Timeout(Switch.DEBOUNCETIME) while True: state = self.pin.value() if state != self.switchstate: # State has changed: act on it now. self.switchstate = state if state == 0 and self.close_func: self.close_func(*self.close_func_args) elif state == 1 and self.open_func: self.open_func(*self.open_func_args) yield wf() # Ignore further state changes until switch has settled
def runlcd( thislcd): # Periodically check for changed text and update LCD if so wf = Timeout(0.02) rr = Roundrobin() while (True): for row in range(thislcd.rows): if thislcd.dirty[row]: msg = thislcd[row] thislcd.lcd_byte(LCD.LCD_LINES[row], LCD.CMD) for thisbyte in msg: thislcd.lcd_byte(ord(thisbyte), LCD.CHR) yield rr # Reshedule ASAP thislcd.dirty[row] = False yield wf() # Give other threads a look-in