def message_receive_loop(self, q, options): # led_framework = LedFramework() with LedFramework(rs_host=options.rs, hwctrl_host=options.ctrl) as led_framework: try: while True: try: self.on_pre_exec_runloop() while True: line = self.read_data() if self.aborted: return if not line: print('') logger.w("line is empty") break if line.startswith('abort'): logger.i('abort canvas') led_framework.abort() elif line.startswith('show:'): logger.i('show by orders') orders = line[len('show:'):].strip() dic_orders = None try: dic_orders = json.loads(orders) except ValueError: logger.w('invalid order:' + str(orders)) continue led_framework.abort() q.put([led_framework.show, dic_orders]) self.on_post_exec_runloop() except Exception as exception: ret = self.on_exception_at_runloop(exception) if (ret == LedRunLoop.CONTINUE): logger.i("continue runloop") continue else: logger.e("Unexpected error:" + str(sys.exc_info()[0])) logger.e(traceback.format_exc()) logger.e("exit runloop by exception") return except: logger.e("Unexpected error:" + str(sys.exc_info()[0])) logger.e(traceback.format_exc()) raise finally: self.run_loop_finished = True SoundInterface.close() logger.i('finish led order loop')
def tearDown(self): SoundInterface.close()
def audio(): volume = float(json.loads(request.data)['volume']) SoundInterface.volume(val=volume/100.0) return ""
def show(self, data): self.is_running = True canvas = self.base_canvas current_order = None try: flatten_data = Queue(flatten_orders(data['orders'])) overlap_time = get_overlap_time(data['orders']) inout_effect = True if not get_inout_effect( data['orders']) is None else False # save order logorder = datetime.now().strftime('%Y%m%d-%H-%M-%S-%f')[:-3] f = open('log/order_history/' + logorder + '.log', 'w') f.write('show:' + json.dumps(data)) f.close() while (True): span = time.time() if self.is_abort: canvas.abort() canvas.clear() break if current_order is None: data = flatten_data.dequeue() if data is None: if canvas.get_object_count() <= 0: break else: pass else: current_order = create_order(data, canvas) if isinstance(current_order, ILedCanvas): canvas = current_order current_order = None elif isinstance(current_order, LedFilterClearCtrl): SoundInterface.stop() canvas = self.base_canvas current_order = None elif isinstance(current_order, LedObject): if inout_effect: current_order = LedFadeinoutOjbectFilter( current_order) canvas.add_object(current_order) else: current_order = None canvas.show() if current_order is not None and current_order.is_expired( overlap_time): current_order = None spanx = (time.time() - span) * 1000 wait = max(0, 70 - spanx) #print('span: ' + str(spanx) + ' wait:' + str(wait)) led.Wait(wait) SoundInterface.stop() led.Clear() led.Show() except KeyError as err: logger.e("error unexpected json : {0}".format(err)) logger.e(traceback.format_exc()) return finally: self.is_abort = False self.is_running = False canvas.clear()