def open_and_load_config(): if os.path.exists(CONFIG_FILE): with open(CONFIG_FILE, 'r') as config_file: return json.loads(config_file.read()) else: print "File [%s] doesn't exist, need to authorize." % (CONFIG_FILE) lcd(ser, "| FreeBox | | Authorize |") authorize() lcd_clr(ser) return open_and_load_config()
def signal_handler(signal, frame): lcd().clear() lcd().set_color(0.0, 0.0, 0.0) for port, server in servers.items(): server.shutdown() global threads_running threads_running = False for t in keyThreads: t.join(1000) os._exit(0)
def display_handler(unused_addr, args): try: j = json.loads(args) displayName = j['data'] lcd().clear() newString = lcd_getText() + "\n{name:.16}".format(name=displayName) print("Got name from OSC message: {}".format(newString)) lcd().message(newString) except ValueError: pass
def key_charLCD(): print('Waiting for key press') while threads_running: for action in config()['keyActions']['charLCD']: if lcd().is_pressed(action['keyCode']): lcd().clear() lcd_setText(action['lcdMessage']) c = action['lcdColor'] lcd().set_color(c[0], c[1], c[2]) for oscAction in action['OSC']: send_osc(oscAction) for otherAction, args in action['Actions'].items(): get_function(otherAction)(*args) time.sleep(config()['settings']['debounceTime'])
def get_session(config): lcd(ser, "| FreeBox | | BeeOne |") try: tmp = req('/api/v3/login/') if (tmp['success'] == False): return (False) if (tmp['result']['logged_in'] == False): hashed = hmac.new(str(config['app_token']), str(tmp['result']['challenge']), sha1) password = hashed.hexdigest() data = {} data['app_id'] = APP_ID data['password'] = password session = req('/api/v3/login/session/', data) if (session['success'] == False): return (False) return (session['result']['session_token']) except: return False
def message(client,server,message): allowed = CLIENTAUTH(client["address"][0]) print("Recieved message from " + client["address"][0] + ", allowed: " + str(allowed)) try: if allowed == True: data = json.loads(message) if data["module"] == "lcd": server.send_message(client,json.dumps({'type': 'response', 'return': lcd(data),'invoker': data})) if data["module"] == "backlight": server.send_message(client,json.dumps({'type': 'response', 'return': backlight(data),'invoker': data})) else: server.send_message(client,json.dumps({'type': "forbidden", 'error': True})) except: server.send_message(client,json.dumps({'type': "error", 'error': True})) pass
authorize() lcd_clr(ser) return open_and_load_config() if __name__ == "__main__": config = open_and_load_config() while True: datas = req('/api/v3/connection/') if ((datas != False) and datas.has_key('success') and (datas['success'] == True)): lcd_clr(ser) if (int(datas['result']['rate_up']) > int( datas['result']['rate_down'])): if int(datas['result']['rate_up']) < (1024 * 1024): lcd_dark_blue(ser) else: lcd_blue(ser) else: if int(datas['result']['rate_down']) < (2 * 1024 * 1024): lcd_dark_green(ser) else: lcd_green(ser) lcd(ser, "UP: % 11s " % (sizeof_fmt(datas['result']['rate_up']))) lcd(ser, "DN: % 11s" % (sizeof_fmt(datas['result']['rate_down']))) else: STOK = get_session(config) print STOK time.sleep(1)
except: return False def open_and_load_config(): if os.path.exists(CONFIG_FILE): with open(CONFIG_FILE, 'r') as config_file: return json.loads(config_file.read()) else: print "File [%s] doesn't exist, need to authorize." % (CONFIG_FILE) lcd(ser, "| FreeBox | | Authorize |") authorize() lcd_clr(ser) return open_and_load_config() if __name__ == "__main__": config = open_and_load_config() while True: datas = req('/api/v3/connection/') if ((datas != False) and datas.has_key('success') and (datas['success'] == True)): lcd_clr(ser) if (int(datas['result']['rate_up']) > int(datas['result']['rate_down'])): lcd_blue(ser) else: lcd_green(ser) lcd(ser, "UP: % 11s " % (sizeof_fmt(datas['result']['rate_up']))) lcd(ser, "DN: % 11s" % (sizeof_fmt(datas['result']['rate_down']))) else: STOK = get_session(config) print STOK time.sleep(1)