def main(): #ugfx.init() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) fill_screen_with_crap(ugfx.BLACK) show_names()
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) badge.backlight(255) global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_START, input_run) ugfx.input_attach(ugfx.BTN_B, input_home) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_uninstall) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def __init__(self): self.window = None self.widgets = [] ugfx.input_init() ugfx.set_default_font(self.default_font) ugfx.input_attach(ugfx.BTN_B, self.reload)
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) # Instructions if orientation.isLandscape(): if display.width() > 128: x0 = int(display.width()/2) currentY = 20 display.drawText(x0+((display.width()-x0)//2)-(display.getTextWidth("BADGE.TEAM", "fairlight12")//2), currentY, "BADGE.TEAM\n", 0x000000, "fairlight12") currentY += display.getTextHeight("BADGE.TEAM", "fairlight12") display.drawText(x0+int((display.width()-x0)/2)-int(display.getTextWidth("ESP32 platform", "roboto_regular12")/2), currentY, "ESP32 platform\n", 0x000000, "roboto_regular12") display.drawLine(x0,0,x0,display.height()-1,0x000000) pixHeight = display.getTextHeight(" ", "roboto_regular12") currentY = pixHeight*5 lineY = display.height()-pixHeight*6-pixHeight//2 display.drawLine(x0, lineY, display.width()-1, lineY, 0x000000) display.drawText(x0+5, display.height()-pixHeight*6, "A: Run\n", 0x000000, "roboto_regular12") display.drawText(x0+5, display.height()-pixHeight*5, "START: Return to home\n", 0x000000, "roboto_regular12") display.drawText(x0+5, display.height()-pixHeight*4, "SELECT: Uninstall app\n", 0x000000, "roboto_regular12") lineY = display.height()-pixHeight*2-pixHeight//2 display.drawLine(x0, lineY, display.width()-1, lineY, 0x000000) display.drawText(x0+5, display.height()-pixHeight*2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12") display.drawText(x0+5, display.height()-pixHeight, "Build "+str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12") else: pixHeight = display.getTextHeight(" ", "roboto_regular12") display.drawLine(0, display.height()-18*4, display.width(), display.height()-18*4, ugfx.BLACK) display.drawText(0, display.height()-pixHeight*6, "A: Run\n", 0x000000, "roboto_regular12") display.drawText(0, display.height()-pixHeight*5, "START: Home\n", 0x000000, "roboto_regular12") display.drawText(0, display.height()-pixHeight*4, "SELECT: Uninstall\n", 0x000000, "roboto_regular12") lineY = display.height()-pixHeight*2-pixHeight//2 display.drawLine(0, lineY, display.width()-1, lineY, 0x000000) display.drawText(0, display.height()-pixHeight*2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12") display.drawText(0, display.height()-pixHeight, "Build "+str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12") global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_OK, input_a) ugfx.input_attach(ugfx.BTN_BACK, input_b) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_a) ugfx.input_attach(ugfx.JOY_LEFT, input_select) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def splash_main(): # Battery status cstate = badge.battery_charge_status() vbatt = badge.battery_volt_sense() percent = battery_percent(3800, 4300, vbatt) # Init graphics and show homescreen ugfx.init() # Depending on battery status... if (cstate) or (percent > 9): draw_home(percent, cstate, "Press START!") # Accept input ugfx.input_init() ugfx.input_attach(ugfx.BTN_START, start_launcher) # Start timer global splashTimer splashTimer.init(period=5000, mode=Timer.PERIODIC, callback=splashTimer_callback) else: draw_batterylow(percent) gotosleep()
def main(): c = simple.MQTTClient(clientID, broker, user=user, password=authToken, ssl=True) c.set_callback(sub_cb) c.connect() c.subscribe(colorCommandTopic) c.subscribe(ledCommandTopic) # init input button ugfx.input_attach(ugfx.JOY_UP, lambda pressed: btn_cb(c, 'U', pressed)) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: btn_cb(c, 'D', pressed)) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: btn_cb(c, 'L', pressed)) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: btn_cb(c, 'R', pressed)) ugfx.input_attach(ugfx.BTN_MID, lambda pressed: btn_cb(c, 'M', pressed)) ugfx.input_attach(ugfx.BTN_A, lambda pressed: btn_cb(c, 'A', pressed)) ugfx.input_attach(ugfx.BTN_B, lambda pressed: btn_cb(c, 'B', pressed)) print("Connected, waiting for event") status = {'d': {'sine': {}}} count = 0 try: while True: status['d']['sine'] = sineVal(-1.0, 1.0, 16, count) count += 1 c.publish(statusTopic, json.dumps(status)) time.sleep_ms(1000) #c.wait_msg() c.check_msg() finally: c.disconnect() ugfx.input_init() print("Disonnected")
def main(): c = simple.MQTTClient(clientID, broker, user=user, password=authToken, ssl=True) c.set_callback(sub_cb) c.connect() c.subscribe(colorCommandTopic) c.subscribe(ledCommandTopic) # init input button ugfx.input_attach(ugfx.JOY_UP, lambda pressed: btn_cb(c, 'U', pressed)) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: btn_cb(c, 'D', pressed)) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: btn_cb(c, 'L', pressed)) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: btn_cb(c, 'R', pressed)) ugfx.input_attach(ugfx.BTN_MID, lambda pressed: btn_cb(c, 'M', pressed)) ugfx.input_attach(ugfx.BTN_A, lambda pressed: btn_cb(c, 'A', pressed)) ugfx.input_attach(ugfx.BTN_B, lambda pressed: btn_cb(c, 'B', pressed)) # init BH1750 bh1750 = BH1750(i2c) print("Connected, waiting for event") lumi = {'d': {'luminance': {}}} try: while True: lumi['d']['luminance'] = bh1750.luminance(BH1750.ONCE_HIRES_1) c.publish(lumiTopic, json.dumps(lumi)) time.sleep_ms(300) #c.wait_msg() c.check_msg() finally: c.disconnect() ugfx.input_init() print("Disonnected")
def main(): ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) show_names() sys.stdin.read(1) #Wait for any key action_exit(True)
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) # Instructions if orientation.isLandscape(): ugfx.line(148, 78, 296, 78, ugfx.BLACK) ugfx.string_box(148, 78, 148, 18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148, 78, 148, 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight) ugfx.string_box(148, 92, 148, 18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148, 110, 148, 18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) else: ugfx.line(0, ugfx.height() - 18 * 4, ugfx.width(), ugfx.height() - 18 * 4, ugfx.BLACK) ugfx.string_box(0, ugfx.height() - 18 * 4, ugfx.width(), 18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(0, ugfx.height() - 18 * 3, ugfx.width(), 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(0, ugfx.height() - 18 * 2, ugfx.width(), 18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(0, ugfx.height() - 18 * 1, ugfx.width(), ugfx.height() - 18 * 1, ugfx.BLACK) ugfx.string_box(0, ugfx.height() - 18 * 1, ugfx.width(), 18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def __init__(self): # initialize ugfx ugfx.init() ugfx.clear(ugfx.WHITE) # Buttons ugfx.input_init() self.init_buttons() # Container width = ugfx.width() height = ugfx.height() ind_height = 46 container_height = height - ind_height self.indicator = ugfx.Container(0, 0, width, ind_height, style=styles.ibm_st) self.container = ugfx.Container(0, ind_height, width, container_height, style=styles.ibm_st) self.graph_basepos = container_height - 5 # Sensor SCL = Pin(26) # SCL SDA = Pin(25) # SDA self.sensor = MPU6050(I2C(scl=SCL, sda=SDA)) # Buzzer self.buzzer = Buzzer()
def __init__(self, parent): super().__init__() self.parent = parent self.views = {} self.current_view = None self.previous_view = None # Initialize Input ugfx.input_init() # A/B Button Handler ugfx.input_attach(ugfx.BTN_A, self.select_a_cb) ugfx.input_attach(ugfx.BTN_B, self.select_b_cb) # Title self.set_title('RPS Game') # Message Box self.message_box = ugfx.Label(0, self.container.height() - 88, self.container.width(), 88, '', parent=self.container, style=styles.wb, justification=ugfx.Label.LEFT) # Status box self.create_status_box() # Message Popup self.message_popup_view = MessagePopupView(manager=self)
def main(): # Garbage Collection gc.collect() # init MQTT c = simple.MQTTClient(clientID, broker, user=user, password=authToken, ssl=True) c.set_callback(sub_cb) c.connect() c.subscribe(colorCommandTopic) c.subscribe(ledCommandTopic) # init input button ugfx.input_attach(ugfx.JOY_UP, lambda pressed: btn_cb(c, 'U', pressed)) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: btn_cb(c, 'D', pressed)) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: btn_cb(c, 'L', pressed)) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: btn_cb(c, 'R', pressed)) ugfx.input_attach(ugfx.BTN_MID, lambda pressed: btn_cb(c, 'M', pressed)) ugfx.input_attach(ugfx.BTN_A, lambda pressed: btn_cb(c, 'A', pressed)) ugfx.input_attach(ugfx.BTN_B, lambda pressed: btn_cb(c, 'B', pressed)) # init MPU6050 # i2c = machine.I2C(scl=machine.Pin(26), sda=machine.Pin(25)) mpu = MPU(26, 25) mpu.calibrate() print("Connected, waiting for event") accel = { 'd': { 'acceleration_x': '', 'acceleration_y': '', 'acceleration_z': '', 'temperature': '', 'gyro_x': '', 'gyro_y': '', 'gyro_z': '', } } try: while True: x, y, z, t, dx, dy, dz = mpu.read_sensors_scaled() accel['d']['acceleration_x'] = x accel['d']['acceleration_y'] = y accel['d']['acceleration_z'] = z accel['d']['temperature'] = t / 340 + 36.53 accel['d']['gyro_x'] = dx accel['d']['gyro_y'] = dy accel['d']['gyro_z'] = dz c.publish(accelTopic, json.dumps(accel)) time.sleep_ms(500) #c.wait_msg() c.check_msg() finally: c.disconnect() ugfx.input_init() print("Disonnected")
def list_categories(): global options global text global categories try: categories except: ugfx.input_init() draw_msg('Getting categories') try: f = urequests.get("https://badge.team/eggs/categories/json", timeout=30) categories = f.json() except: draw_msg('Failed!') draw_msg('Returning to launcher :(') appglue.start_app('launcher', False) f.close() draw_msg('Done!') options = ugfx.List(0, 0, int(ugfx.width() / 2), ugfx.height()) text = ugfx.Textbox(int(ugfx.width() / 2), 0, int(ugfx.width() / 2), ugfx.height()) ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else False) ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else False) ugfx.input_attach(ugfx.BTN_A, select_category) ugfx.input_attach( ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) ugfx.input_attach( ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() while options.count() > 0: options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) options.selected_index(0) text.text("Install or update eggs from the hatchery here\n\n\n\n") ugfx.string_box(148, 0, 148, 26, "Hatchery", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.line(148, 78, 296, 78, ugfx.BLACK) ugfx.string_box(148, 78, 148, 18, " A: Open category", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148, 92, 148, 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148, 110, 148, 18, " badge.team", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.flush(ugfx.LUT_FULL) gc.collect()
def splash_input_init(): print("[SPLASH] Inputs attached") ugfx.input_init() ugfx.input_attach(ugfx.BTN_START, splash_input_start) ugfx.input_attach(ugfx.BTN_B, splash_input_other) ugfx.input_attach(ugfx.JOY_UP, splash_input_other) ugfx.input_attach(ugfx.JOY_DOWN, splash_input_other) ugfx.input_attach(ugfx.JOY_LEFT, splash_input_other) ugfx.input_attach(ugfx.JOY_RIGHT, splash_input_other)
def program_main(): ugfx.init() ugfx.clear(ugfx.WHITE) badge.leds_init() try: badge.eink_png(0, 0, logo_path) except: log('+ Failed to load graphics') # Name tag ugfx.string(ugfx.width() - ugfx.get_string_width(name, fonts[1]), ugfx.height() - 36, name, fonts[1], ugfx.BLACK) # Button info ugfx.string(0, ugfx.height() - 13, '[FLASH to update] [B to exit]', fonts[2], ugfx.BLACK) ugfx.flush() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, lambda pressed: exit_app()) ugfx.input_attach(ugfx.BTN_FLASH, lambda pressed: start_self_update()) HOST = "chat.freenode.net" PORT = 6667 NICK = name + "[luv]" REALNAME = name + ' @ SHA2017' log('+ waiting for network...') wifi.init() while not wifi.sta_if.isconnected(): time.sleep(0.1) s = socket.socket() s.connect((HOST, PORT)) s.send(bytes("NICK %s\r\n" % NICK, "UTF-8")) s.send(bytes("USER %s 0 * :%s\r\n" % (NICK, REALNAME), "UTF-8")) s.send(bytes("JOIN #sha2017\r\n", "UTF-8")) # IRC Client while True: line = s.readline().rstrip() parts = line.split() if parts: if (parts[0] == b"PING"): s.send(bytes("PONG %s\r\n" % line[1], "UTF-8")) blink_led(green) if (parts[1] == b"PRIVMSG"): blink_led(red) msg = b' '.join(parts[3:]) rnick = line.split(b'!')[0] log(b'%s: %s' % (rnick, msg))
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.string_box(148, 0, 148, 26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(148, 23, 148, 23, "Hacking", "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(148, 48, 148, 26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) #the line under the text str_len = ugfx.get_string_width("Hacking", "PermanentMarker22") line_begin = 148 + int((148 - str_len) / 2) line_end = str_len + line_begin ugfx.line(line_begin, 46, line_end, 46, ugfx.BLACK) #the cursor past the text cursor_pos = line_end + 5 ugfx.line(cursor_pos, 22, cursor_pos, 44, ugfx.BLACK) # Instructions ugfx.line(148, 78, 296, 78, ugfx.BLACK) ugfx.string_box(148, 78, 148, 18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148, 78, 148, 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight) ugfx.string_box(148, 92, 148, 18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148, 110, 148, 18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() ugfx.flush(ugfx.LUT_FULL)
def prompt_option(options, index=0, text = "Please select one of the following:", title=None, select_text="OK", none_text=None): """Shows a dialog prompting for one of multiple options If none_text is specified the user can use the B or Menu button to skip the selection if title is specified a blue title will be displayed about the text """ global wait_for_interrupt, button_pushed ugfx.set_default_font("Roboto_Regular12") window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10) window.show() list_y = 30 if title: window.text(5, 10, title, ugfxBLACK) window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK) window.text(5, 30, text, ugfx.BLACK) list_y = 50 else: window.text(5, 10, text, ugfx.BLACK) options_list = ugfx.List(5, list_y, ugfx.width() - 25, 180 - list_y, parent = window) for option in options: if isinstance(option, dict) and option["title"]: options_list.add_item(option["title"]) else: options_list.add_item(str(option)) options_list.selected_index(index) select_text = "A: " + select_text if none_text: none_text = "B: " + none_text button_select = ugfx.Button(5, ugfx.height() - 50, 140 if none_text else ugfx.width() - 25, 30 , select_text, parent=window) button_none = ugfx.Button(ugfx.width() - 160, ugfx.height() - 50, 140, 30 , none_text, parent=window) if none_text else None try: ugfx.input_init() wait_for_interrupt = True while wait_for_interrupt: if button_pushed == "A": return options[options_list.selected_index()] if button_pushed == "B": return None if button_none and button_pushed == "START": return None time.sleep(0.2) finally: window.hide() window.destroy() options_list.destroy() button_select.destroy() if button_none: button_none.destroy() ugfx.poll()
def __init__(self): self.x = 30 self.y = 30 self.r = 0 self.size = 1 self.wrapper = Wrapper() ugfx.init() ugfx.input_init() self.select_surface() self.main_loop()
def setup(): global background badge.init() ugfx.init() ugfx.input_init() ugfx.input_attach(ugfx.BTN_SELECT, reboot) ugfx.input_attach(ugfx.BTN_START, reboot) ugfx.input_attach(ugfx.JOY_DOWN, invert) ugfx.input_attach(ugfx.JOY_UP, invert) ugfx.input_attach(ugfx.JOY_RIGHT, invert) ugfx.input_attach(ugfx.JOY_LEFT, invert) ugfx.input_attach(ugfx.BTN_A, invert) ugfx.input_attach(ugfx.BTN_B, invert) ugfx.set_lut(ugfx.LUT_NORMAL) ugfx.clear(background) ugfx.flush() flip()
def badge_init(self): badge.init() ugfx.init() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, lambda pushed: home() if pushed else False) ugfx.input_attach(ugfx.BTN_START, lambda pushed: self.shoot() if pushed else False) ugfx.input_attach(ugfx.JOY_UP, lambda pushed: print("JOY_UP") if pushed else False) ugfx.input_attach( ugfx.JOY_DOWN, lambda pushed: print("JOY_DOWN") if pushed else False) ugfx.input_attach( ugfx.JOY_RIGHT, lambda pushed: self.move(DIRECTION_RIGHT) if pushed else False) ugfx.input_attach( ugfx.JOY_LEFT, lambda pushed: self.move(DIRECTION_LEFT) if pushed else False)
def run_game(): badge.eink_init() ugfx.init() ugfx.clear(ugfx.WHITE) ugfx.flush() badge.init() ugfx.clear(ugfx.WHITE) ugfx.input_init() ugfx.input_attach(ugfx.JOY_UP, lambda pressed: up(pressed, this_game)) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: down(pressed, this_game)) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: left(pressed, this_game)) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: right(pressed, this_game)) ugfx.input_attach(ugfx.BTN_SELECT, lambda pressed: exit_game(pressed, this_game)) ugfx.string(50, 50, "Snake Game", "PermanentMarker22", ugfx.BLACK) ugfx.string(50, 72, "press SELECT to exit", "Roboto_Regular18", ugfx.BLACK) ugfx.flush() time.sleep(5) ugfx.clear(ugfx.WHITE) ugfx.flush() snake = Snake(True, Renderer()) this_game = Game(snake, Border(), [Food.create_random_food(snake)]) ugfx.flush() print("Start Log") while True: if (this_game.game_state == "FAIL"): FailGame(this_game) Step(this_game, 5)
def list_categories(): global options global categories try: categories except: ugfx.input_init() easydraw.msg('Getting categories', "Loading...", True) try: f = urequests.get("https://badge.disobey.fi/eggs/categories/json", timeout=30) categories = f.json() except: easydraw.msg('Failed :(') appglue.start_app('launcher', False) f.close() easydraw.msg('Success :)') options = ugfx.List(0, 0, int(ugfx.width()), ugfx.height()) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, select_category) ugfx.input_attach( ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() while options.count() > 0: options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) options.selected_index(0) ugfx.flush(ugfx.LUT_FULL) gc.collect()
def __init__(self): # initialize ugfx ugfx.init() ugfx.clear(ugfx.WHITE) # Buttons ugfx.input_init() self.init_buttons() # Container width = ugfx.width() height = ugfx.height() ind_height = 46 container_height = height - ind_height self.indicator = ugfx.Container(0, 0, width, ind_height, style=styles.ibm_st) self.container = ugfx.Container(0, ind_height, width, container_height, style=styles.ibm_st) self.graph_basepos = container_height - 5 # Sensor self.gas_sensor = ADC(Pin(34)) self.gas_sensor.atten(ADC.ATTN_11DB) self.gas_sensor.width(ADC.WIDTH_12BIT) # Smooth self.Vos = 0 # Buzzer self.buzzer = Buzzer()
def __init__(self): # initialize ugfx ugfx.init() ugfx.clear(ugfx.WHITE) ugfx.input_init() # Buttons self.init_buttons() # Container width = ugfx.width() height = ugfx.height() ind_height = 40 ind_pos = height - ind_height self.indicator = ugfx.Container(0, ind_pos, width, ind_height, style=styles.ibm_st) self.container = ugfx.Container(0, 0, width, ind_pos, style=styles.ibm_st) self.y_offset = ind_pos - 10 # Sensor #self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32, vo=36, K=0.5, Voc=0.6) self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32, vo=36, K=0.5, Voc=0.0) # Smooth self.Vos = 0.1 # 0.8
def main(): print("> Main") global api_key ugfx.init() ugfx.input_init() ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.input_attach(ugfx.BTN_B, appglue.home) ugfx.input_attach(ugfx.BTN_SELECT, prompt_api_key) wifi.init() while not wifi.sta_if.isconnected(): time.sleep(0.1) pass api_key = badge.nvs_get_str("engel", "key", "") if not api_key: prompt_api_key() show_shift_list()
def __init__(self): # initialize ugfx ugfx.init() ugfx.clear(ugfx.WHITE) # Buttons ugfx.input_init() self.init_buttons() # Container width = ugfx.width() height = ugfx.height() ind_height = 66 container_height = height - ind_height self.indicator = ugfx.Container(0, 0, width, ind_height, style=styles.ibm_st) self.container = ugfx.Container(0, ind_height, width, container_height, style=styles.ibm_st) self.graph_basepos = container_height - 5 # Sensor self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32, vo=36, K=0.5, Voc=0.6) # Smooth self.Vos = 0
def prompt_boolean(text, title=version.dialog_title, true_text="Yes", false_text="No", width=ugfx.width(), height=ugfx.height(), font="Roboto_Regular12", cb=None): global wait_for_interrupt, button_pushed easydraw.msg(text, title, True) easydraw.msg_nosplit("[" + false_text + "/" + true_text + "]") def done(result): ugfx.input_attach(ugfx.JOY_LEFT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_RIGHT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_B, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, dummy_button_cb) if cb: cb(result) return result def syncSuccess(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "A" wait_for_interrupt = False def syncCancel(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "B" wait_for_interrupt = False def asyncSuccess(evt): if evt: done(True) def asyncCancel(evt): if evt: done(False) ugfx.input_init() ugfx.set_lut(ugfx.LUT_NORMAL) ugfx.flush() ugfx.input_attach(ugfx.JOY_LEFT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_RIGHT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_B, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, dummy_button_cb) if false_text != None: ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) ugfx.input_attach(version.btn_ok, asyncSuccess if cb else syncSuccess) if cb: return else: wait_for_interrupt = True while wait_for_interrupt: time.sleep(0.2) if button_pushed == "B": return done(False) return done(True)
def prompt_text(description, init_text="", true_text="OK", false_text="Back", width=ugfx.width(), height=ugfx.height(), font="Roboto_BlackItalic24", cb=None): """Shows a dialog and keyboard that allows the user to input/change a string Calls the 'cb' callback or return None if user aborts with button B. Using a callback is highly recommended as it's not possible to process events inside an event callback. The caller is responsible for flushing the display after processing the response. """ global wait_for_interrupt, button_pushed window = ugfx.Container(int((ugfx.width() - width) / 2), int((ugfx.height() - height) / 2), width, height) window.show() ugfx.set_default_font("Roboto_Regular12") kb_height = int(height / 2) + 30 kb = ugfx.Keyboard(0, height - kb_height, width, kb_height, parent=window) ugfx.set_default_font("Roboto_Regular18") edit_height = 25 edit = ugfx.Textbox(5, height - kb_height - 5 - edit_height, int(width * 4 / 5) - 10, edit_height, text=init_text, parent=window) ugfx.set_default_font("Roboto_Regular12") button_height = 25 def done(result): window.destroy() if cb: cb(result) return result def syncSuccess(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "A" wait_for_interrupt = False def syncCancel(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "B" wait_for_interrupt = False def asyncSuccess(evt): if evt: done(edit.text()) def asyncCancel(evt): if evt: done(None) button_yes = ugfx.Button(int(width * 4 / 5), height - kb_height - button_height, int(width * 1 / 5) - 3, button_height, true_text, parent=window, cb=asyncSuccess if cb else syncSuccess) button_no = ugfx.Button(int(width * 4 / 5), height - kb_height - button_height - button_height, int(width / 5) - 3, button_height, false_text, parent=window) if false_text else None ugfx.set_default_font(font) label = ugfx.Label(5, 1, int(width * 4 / 5), height - kb_height - 5 - edit_height - 5, description, parent=window) def vkey_backspace(): edit.backspace() ugfx.flush() focus = 0 def toggle_focus(pressed): if pressed: if focus == 0: edit.set_focus() kb.enabled(1) ugfx.input_attach( version.btn_cancel, lambda pressed: vkey_backspace() if pressed else 0) ugfx.input_attach( version.btn_ok, lambda pressed: 0 if pressed else ugfx.flush()) focus = 1 elif focus == 1 or not button_no: button_yes.set_focus() kb.enabled(0) ugfx.input_attach(version.btn_ok, asyncSuccess if cb else syncSuccess) ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) focus = (2 if button_no else 0) else: button_no.set_focus() kb.enabled(0) ugfx.input_attach(version.btn_ok, asyncCancel if cb else syncCancel) ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) focus = 0 ugfx.flush() ugfx.input_init() ugfx.input_attach(ugfx.BTN_SELECT, toggle_focus) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_UP, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: ugfx.flush() if pressed else 0) toggle_focus(True) ugfx.set_lut(ugfx.LUT_NORMAL) ugfx.flush() wait_for_interrupt = True if cb: return else: while wait_for_interrupt: time.sleep(0.2) if (focus == 0 and no_button) or button_pushed == "B": return done(False) return done(edit.text())
if self.delay > 10 and button_pressed: self.delay -= 10 def press_up(self, button_pressed): if self.delay < 1000 and button_pressed: self.delay += 10 def press_left(self, button_pressed): if button_pressed: self.change_color(False) def press_right(self, button_pressed): if button_pressed: self.change_color(True) def main(): strobonator = Strobonator() ugfx.input_attach(ugfx.BTN_START, strobonator.press_start) ugfx.input_attach(ugfx.JOY_UP, strobonator.press_up) ugfx.input_attach(ugfx.JOY_DOWN, strobonator.press_down) ugfx.input_attach(ugfx.JOY_LEFT, strobonator.press_left) ugfx.input_attach(ugfx.JOY_RIGHT, strobonator.press_right) ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.home() if pushed else False) _thread.start_new_thread(main, ())
def prompt_text(description, init_text="", true_text="OK", false_text="Back", width=300, height=200, font="Roboto_BlackItalic24"): """Shows a dialog and keyboard that allows the user to input/change a string Returns None if user aborts with button B The caller is responsible for flushing the display after processing the response. """ global wait_for_interrupt, button_pushed window = ugfx.Container(int((ugfx.width() - width) / 2), int((ugfx.height() - height) / 2), width, height) window.show() ugfx.set_default_font("Roboto_Regular12") kb_height = int(height / 2) + 30 kb = ugfx.Keyboard(0, height - kb_height, width, kb_height, parent=window) ugfx.set_default_font("Roboto_Regular18") edit_height = 25 edit = ugfx.Textbox(5, height - kb_height - 5 - edit_height, int(width * 4 / 5) - 10, edit_height, text=init_text, parent=window) ugfx.set_default_font("Roboto_Regular12") button_height = 25 def okay(evt): # We'd like promises here, but for now this should do global wait_for_interrupt button_pushed = "A" wait_for_interrupt = False button_yes = ugfx.Button(int(width * 4 / 5), height - kb_height - button_height, int(width * 1 / 5) - 3, button_height, true_text, parent=window, cb=okay) button_no = ugfx.Button(int(width * 4 / 5), height - kb_height - button_height - button_height, int(width / 5) - 3, button_height, false_text, parent=window) if false_text else None ugfx.set_default_font(font) label = ugfx.Label(5, 1, int(width * 4 / 5), height - kb_height - 5 - edit_height - 5, description, parent=window) def vkey_backspace(): edit.backspace() ugfx.flush() focus = 0 def toggle_focus(pressed): if pressed: if focus == 0: edit.set_focus() kb.enabled(1) ugfx.input_attach( ugfx.BTN_B, lambda pressed: vkey_backspace() if pressed else 0) ugfx.input_attach( ugfx.BTN_A, lambda pressed: 0 if pressed else ugfx.flush()) focus = 1 elif focus == 1 or not button_no: button_yes.set_focus() kb.enabled(0) ugfx.input_attach(ugfx.BTN_A, pressed_a) ugfx.input_attach(ugfx.BTN_B, pressed_b) focus = (2 if button_no else 0) else: button_no.set_focus() kb.enabled(0) ugfx.input_attach(ugfx.BTN_A, pressed_a) ugfx.input_attach(ugfx.BTN_B, pressed_b) focus = 0 ugfx.flush() ugfx.input_init() ugfx.input_attach(ugfx.BTN_SELECT, toggle_focus) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_UP, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: ugfx.flush() if pressed else 0) toggle_focus(True) ugfx.set_lut(ugfx.LUT_NORMAL) ugfx.flush() wait_for_interrupt = True while wait_for_interrupt: time.sleep(0.2) def done(value): window.hide() window.destroy() button_yes.destroy() if button_no: button_no.destroy() label.destroy() kb.destroy() edit.destroy() return value if (focus == 0 and no_button) or button_pushed == "B": return done(False) return done(edit.text())