Exemplo n.º 1
0
def switchable_filter(chan, orig_chan, fn):
    select_ch = select(get_switch(), chan)
    enabled = False
    while True:
        result_ch, val = yield select_ch.get()
        if result_ch == chan:
            if not enabled or fn(val):
                yield orig_chan.put(val)
        else:
            enabled = not enabled
Exemplo n.º 2
0
def servo_coroutine():
    servo, _ = get_servo(1)
    accel = get_accel()
    switch = get_switch()
    on = False
    x = 0
    accel_or_switch = select(switch, accel)
    while True:
        chan, val = yield accel_or_switch.get()
        if chan == accel:
            x, *_ = val
        elif chan == switch:
            on = not on

        if on:
            yield servo.put(x)
        yield Delay(0)