コード例 #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
ファイル: halscript.py プロジェクト: Mixone-FinallyHere/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:
        yield from lechbot_event('passage')
コード例 #4
0
ファイル: halscript.py プロジェクト: Mixone-FinallyHere/hal
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
ファイル: test_generators.py プロジェクト: UrLab/halpy
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
ファイル: test_generators.py プロジェクト: UrLab/halpy
def test_sinusoid():
    frames = sinusoid(n_frames=4, val_min=0, val_max=10)
    assert frames == [5, 10, 5, 0]