def exec_cmd(cli, cmd, rol): d = {'cli': cli, 'loop': (yield GetRunningLoop(None)), 'pyb': pyb } try: v = exec(rol, d) except Exception as e: v = e yield from cli.writeln(repr(v))
def master(self): self.loop = yield GetRunningLoop(None) yield self.manage_brightness() yield self.percolator.keep_leds_current(10) for i in range(7, 63, 7): self.percolator.set_color_of(i, self.percolator.stoichiometric) yield self.percolator.bingo() yield self.rr.integrate_continuously() yield self.spin_feed_rollers() while True: yield from self.flash_LED(self.act_led) yield from sleep(1000)
def keep_leds_current(self, interval): last_check_time = 0 loop = yield GetRunningLoop(None) while True: now = loop.time() if now < last_check_time + interval: yield Sleep(last_check_time + interval - now) last_check_time = loop.time() if self.leds_need_sync: #self.leds.sync() self.render() self.leds.sync() self.leds_sync_last_done = loop.time() self.leds_need_sync = False
def info_cmd(cli, cmd, rol): yield from cli.write('mem_alloc %s, mem_free %s' \ % (gc.mem_alloc(), gc.mem_free())) loop = yield GetRunningLoop(None) yield from cli.write(', qlen %d' % len(loop.q)) yield from cli.writeln('')