def setUp(self): logging.basicConfig(level=logging.INFO) global _test_EventLoop self.loop = new_event_loop() assert self.loop is not _test_EventLoop _test_EventLoop = self.loop set_event_loop(None)
def interact(role=None): cli = CoroCLI('pre-alpha') inject_standard_commands(cli) loop = new_event_loop() set_event_loop(loop) loop.run_until_complete(cli.repl())
def main(): @coroutine def show_config(cli, cmd, rol): yield from cli.writeln(repr(config)) config = eval(open('lightshow.cfg').read()) if config.get('record'): exec('from wsrec import WS2812') print('recording') else: exec('from ws2812 import WS2812') @coroutine def fuzzle(cli, cmd, rol): args = rol.split() try: n = int(args[0]) except: n = 1 for i in range(n): yield lightshow.fuzzle('a_flag') @coroutine def fuzzkill(cli, cmd, rol): args = rol.split() try: n = int(args[0]) except: n = 1 lightshow.a_flag = n yield @coroutine def test(cli, cmd, rol): yield from cli.write(b'\x1b[s\x1b[1;40H\x1b[2K') yield from cli.write(b'Hey there!') yield from cli.write('\x1b[u') rr = lightshow.rr rr.supertitle = lightshow.supertitle #yield from rr.timer_keep_leds_current() #rr.balls.append(Ball(ω=2.1, Fd=0.01, color=(64,0,0))) #rr.balls.append(Ball(ω=2.08, Fd=0.01, color=(0,64,0))) #rr.balls.append(Ball(θ=3.1, Fd=0.0025, color=(0,0,255))) #rr.balls.append(Ball(θ=-0.733, ω=0, Fd=0.01, color=(64, 64, 64))) #for i in range(8): # rr.balls.append(Ball(θ=-0.733, ω=rand.uniform(0.0, -0.3), Fd=0.01, color=(8,8,8))) leds = lightshow.percolator.leds for i in range(7, 63, 7): leds[i] = lightshow.percolator.stoichiometric #leds[28].off() #rr.balls.append(Ball(θ=-0.733, ω=rand.uniform(0.0, -0.3), Fd=0.01, color=(8,8,8))) yield lightshow.percolator.bingo() #print(rr.balls) yield rr.integrate_continuously() @coroutine def eval_cmd(cli, cmd, rol): d = { 'cli': cli, 'loop': (yield GetRunningLoop(None)), 'l': lightshow, 'pyb': pyb } try: v = eval(rol, d) except Exception as e: v = e yield from cli.writeln(repr(v)) @coroutine def exec_cmd(cli, cmd, rol): d = { 'cli': cli, 'loop': (yield GetRunningLoop(None)), 'l': lightshow, 'pyb': pyb } try: exec(rol, d) except Exception as e: yield from cli.writeln(repr(e)) cli = CoroCLI(config.get('role')) inject_standard_commands(cli) cli.command_dispatch['conf'] = show_config cli.command_dispatch['fuzzle'] = fuzzle cli.command_dispatch['fuzzoff'] = fuzzkill cli.command_dispatch['test'] = test lightshow = Lightshow(write_fun=cli.write, config=config) lightshow.a_flag = 0 cli.command_dispatch['perk'] = lightshow.perk cli.command_dispatch['play'] = lightshow.play cli.command_dispatch['stop'] = lightshow.stop cli.command_dispatch['exec'] = exec_cmd cli.command_dispatch['eval'] = eval_cmd #loop = new_event_loop(64) # Pre-allocate space for 64 delayed send/call loop = new_event_loop() # Pre-allocate space for 64 delayed send/call set_event_loop(loop) loop.run_until_complete(run(cli, lightshow, config))
def main(): @coroutine def show_config(cli, cmd, rol): yield from cli.writeln(repr(config)) config = eval(open('lightshow.cfg').read()) if config.get('record'): exec('from wsrec import WS2812') print('recording') else: exec('from ws2812 import WS2812') @coroutine def fuzzle(cli, cmd, rol): args = rol.split() try: n = int(args[0]) except: n = 1 for i in range(n): yield lightshow.fuzzle('a_flag') @coroutine def fuzzkill(cli, cmd, rol): args = rol.split() try: n = int(args[0]) except: n = 1 lightshow.a_flag = n yield @coroutine def test(cli, cmd, rol): yield from cli.write(b'\x1b[s\x1b[1;40H\x1b[2K') yield from cli.write(b'Hey there!') yield from cli.write('\x1b[u') rr = lightshow.rr rr.supertitle = lightshow.supertitle #yield from rr.timer_keep_leds_current() #rr.balls.append(Ball(ω=2.1, Fd=0.01, color=(64,0,0))) #rr.balls.append(Ball(ω=2.08, Fd=0.01, color=(0,64,0))) #rr.balls.append(Ball(θ=3.1, Fd=0.0025, color=(0,0,255))) #rr.balls.append(Ball(θ=-0.733, ω=0, Fd=0.01, color=(64, 64, 64))) #for i in range(8): # rr.balls.append(Ball(θ=-0.733, ω=rand.uniform(0.0, -0.3), Fd=0.01, color=(8,8,8))) leds = lightshow.percolator.leds for i in range(7, 63, 7): leds[i] = lightshow.percolator.stoichiometric #leds[28].off() #rr.balls.append(Ball(θ=-0.733, ω=rand.uniform(0.0, -0.3), Fd=0.01, color=(8,8,8))) yield lightshow.percolator.bingo() #print(rr.balls) yield rr.integrate_continuously() @coroutine def eval_cmd(cli, cmd, rol): d = {'cli': cli, 'loop': (yield GetRunningLoop(None)), 'l': lightshow, 'pyb': pyb } try: v = eval(rol, d) except Exception as e: v = e yield from cli.writeln(repr(v)) @coroutine def exec_cmd(cli, cmd, rol): d = {'cli': cli, 'loop': (yield GetRunningLoop(None)), 'l': lightshow, 'pyb': pyb } try: exec(rol, d) except Exception as e: yield from cli.writeln(repr(e)) cli = CoroCLI(config.get('role')) inject_standard_commands(cli) cli.command_dispatch['conf'] = show_config cli.command_dispatch['fuzzle'] = fuzzle cli.command_dispatch['fuzzoff'] = fuzzkill cli.command_dispatch['test'] = test lightshow = Lightshow(write_fun=cli.write, config=config) lightshow.a_flag = 0 cli.command_dispatch['perk'] = lightshow.perk cli.command_dispatch['play'] = lightshow.play cli.command_dispatch['stop'] = lightshow.stop cli.command_dispatch['exec'] = exec_cmd cli.command_dispatch['eval'] = eval_cmd #loop = new_event_loop(64) # Pre-allocate space for 64 delayed send/call loop = new_event_loop() # Pre-allocate space for 64 delayed send/call set_event_loop(loop) loop.run_until_complete(run(cli, lightshow, config))