def close_hs(called_on_trigger): log.info("CLOSE the hackerspace") if called_on_trigger: internet.lechbot_event('hs_close') os.system("mpc pause") hal.off("ampli") hal.on("knife_r") hal.off("knife_b") hal.off("knife_g") # Shotdown all leds for anim in ("red", "green", "blue", "heater", "door_green", "kitchen", "roof_g", "roof_b", "roof_r"): hal.stop(anim) sleep(0.0001) if called_on_trigger and internet.spaceapi_isopen(): illuminate_stairs() internet.spaceapi_close() internet.events.send("hs_close", ["close", "status"]) for i in range(3): hal.on("belgaleft") hal.off("belgaright") sleep(1) hal.off("belgaleft") hal.on("belgaright") sleep(1) hal.stop("bell_eyes")
def main(): hal.stop('buzzer') hal.fps('buzzer', 17) hal.upload('buzzer', 2 * funkytown.to_frames()) hal.one_shot('buzzer') hal.fps('bell_eyes', 60) for ev, ev_on in hal.events(): if not ev_on or ev != 'bell': continue logger.info("Spotted someone at the door") hal.upload('bell_eyes', hal.sinusoid(n_frames=20, val_max=255)) hal.play('buzzer') fps = {name: hal.fps(name) for name in BLINK} for name in BLINK: hal.fps(name, 450) internet.lechbot_event('bell') internet.events.send("bell", ["bell"]) sleep(5) for name in BLINK: hal.fps(name, fps[name]) # Reupload fixed light hal.upload('bell_eyes', [255]) # If the hackerspace is closed, dont light eyes if not hal.trig('knife_switch'): hal.stop('bell_eyes')
def main(): hal.upload('door_green', hal.sinusoid(n_frames=100)[:75]) hal.fps('door_green', 75) hal.one_shot('door_green') logger.info('Door flash ready') for ev, ev_on in hal.events(): if ev_on and ev == "passage": hal.play('door_green') logger.info('flash') internet.events.send("passage", ["passage"]) if not hal.trig('knife_switch'): internet.lechbot_event('passage')
def main(): global last_trig for trig_name, trig_active in hal.events(): knife_on = hal.trig('knife_switch') door_open = trig_name == 'door_stairs' and trig_active if door_open and not knife_on and time() - last_trig > 60: last_trig = time() illuminate_stairs() hal.on("knife_b") hal.off("knife_g") hal.off("knife_r") internet.lechbot_event('door_stairs') internet.events.send('door_stairs', ["door_stairs"])
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 yield from lechbot_event('bell') 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])
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')
def open_hs(called_on_trigger): log.info("OPEN the hackerspace") for anim in ("red", "green", "blue", "kitchen", "belgatop"): hal.upload(anim, hal.sinusoid(250, 0, 200)) hal.loop(anim) hal.play(anim) hal.fps(anim, 50) sleep(0.0001) hal.upload("bell_eyes", [255]) hal.play("bell_eyes") hal.one_shot("door_green") hal.play("heater") for switch in ("power", "leds_stairs", "ampli", "belgaleft", "belgaright"): hal.on(switch) hal.off("knife_r") hal.off("knife_b") hal.on("knife_g") if called_on_trigger and not internet.spaceapi_isopen(): internet.lechbot_event('hs_open') internet.spaceapi_open() internet.events.send('hs_open', ["open", "status"])
def passage_stairs(*args): if hal.triggers.knife_switch.on: return hal.switchs.power.on = True hal.switchs.leds_stairs.on = True hal.animations.green.upload([1.0]) hal.animations.green.looping = True hal.animations.green.playing = True hal.rgbs.knife_leds.css = '#00f' yield from lechbot_event('door_stairs') yield from asyncio.sleep(LIGHT_TIMEOUT/2) hal.rgbs.knife_leds.css = '#f0f' yield from asyncio.sleep(LIGHT_TIMEOUT/2) if not hal.triggers.knife_switch.on: hal.rgbs.knife_leds.css = '#000' hal.switchs.power.on = False hal.switchs.leds_stairs.on = False hal.animations.green.looping = False
def passage_kitchen(*args): if not hal.triggers.knife_switch.on: yield from lechbot_event('kitchen_move')
def change_status_lechbot(trigger, state): event = 'hs_open' if state else 'hs_close' yield from lechbot_event(event)