示例#1
0
文件: halscript.py 项目: UrLab/hal
def bell_pressed(name, state):
    # Play Funky town on the buzzer
    with SafeBuzzer() as buz:
        buz.looping = False
        buz.upload(funkytown.to_frames() * 2)
        buz.fps = 20

        # Upload glow to the space invader eyes
        hal.animations.bell_eyes.upload(sinusoid(100))

        # Make animations much faster for 5 seconds
        original_fps = {}
        for a in ['bell_eyes', 'red', 'blue', 'green', 'kitchen']:
            original_fps[a] = hal.animations[a].fps
            hal.animations[a].fps = 200

        buz.playing = True

        publish_hal_event('bell', "On sonne à la porte")
        yield from asyncio.sleep(7)

        # Restore original animations
        for a, fps in original_fps.items():
            hal.animations[a].fps = fps
        if hal.triggers.knife_switch.on:
            hal.animations.bell_eyes.upload([1.0])
示例#2
0
文件: halscript.py 项目: UrLab/hal
def passage(*args):
    if hal.triggers.knife_switch.on:
        flash = hal.animations.door_green
        flash.looping = False
        flash.upload(sinusoid(100)[:75])
        flash.playing = True
        flash.fps = 150
    else:
        publish_hal_event('passage', "Tiens, du mouvement à l'intérieur du Hackerspace !?")
示例#3
0
def passage(*args):
    if hal.triggers.knife_switch.on:
        flash = hal.animations.door_green
        flash.looping = False
        flash.upload(sinusoid(100)[:75])
        flash.playing = True
        flash.fps = 150
    else:
        yield from lechbot_event('passage')
示例#4
0
def hal_periodic_tasks(period_seconds=15):
    while True:
        try:
            yield from set_red_fps()
            yield from communicate_sensors()
            temp_heater = hal.sensors.temp_radiator.value
            hal.animations.heater.upload(sinusoid(val_max=temp_heater))
        except Exception as err:
            logger.exception("Error in periodic tasks")
            sentry.captureException()
        finally:
            yield from asyncio.sleep(period_seconds)
示例#5
0
文件: halscript.py 项目: UrLab/hal
def set_urlab_open():
    for sw in ['power', 'ampli', 'leds_stairs']:
        hal.switchs[sw].on = True

    hal.rgbs.knife_leds.css = '#0f0'
    hal.rgbs.roof.css = '#fff'

    # Put fixed animations on
    for a in ['bell_eyes']:
        hal.animations[a].upload([1.0])
        hal.animations[a].playing = True
        hal.animations[a].looping = True

    # Start glowing ledstrips
    for a in ['belgatop', 'blue', 'green', 'heater', 'kitchen', 'red']:
        anim = hal.animations[a]
        anim.upload(sinusoid())
        anim.fps = 40
        anim.looping = True
        anim.playing = True

    heater_changed('heater', hal.triggers.heater.on)
    kitchen_changed('kitchen', hal.triggers.kitchen_move.on)
示例#6
0
def test_sinusoid_with_floats():
    frames = sinusoid(n_frames=4, val_min=0.0, val_max=10.0 / 255.0)
    assert frames == [5, 10, 5, 0]
示例#7
0
def test_sinusoid():
    frames = sinusoid(n_frames=4, val_min=0, val_max=10)
    assert frames == [5, 10, 5, 0]