def init_buttons(self): # init button callbacks buttons.register(self.UP, self.input_up) buttons.register(self.DOWN, self.input_down) buttons.register(self.LEFT, self.input_left) buttons.register(self.RIGHT, self.input_right) buttons.register(self.A, self.input_a)
def next_check(): if(len(checklist) == 0): rgb.clear() rgb.background((0, 50, 0)) rgb.text("Done!", CYAN, (4, 1)) machine.nvs_setint('system', 'factory_checked', 3) return background, textcolor, x_pos, text, gpio = checklist.pop(0) rgb.clear() rgb.background(background) rgb.text(text, textcolor, (x_pos, 1)) buttons.register(gpio, lambda pressed, gpio=gpio: (buttons.unassign(gpio), next_check()) if not pressed else None)
def skippabletext(text, color=(255, 255, 255), pos=None, width=rgb.PANEL_WIDTH): buttons.init_button_mapping() buttons.register(defines.BTN_A, _abort_scroll) buttons.register(defines.BTN_B, _abort_scroll) rgb.scrolltext(text,color,pos,width) framerate = rgb.current_framerate #scroll time per pixel length_text_pixels = rgb.textwidth(text) delay_loop = (1 / framerate) * (length_text_pixels+10) * 10 global abort abort = False while (not abort) and (delay_loop >= 0): time.sleep(0.1) delay_loop -= 1 buttons.clear_button_mapping()
def __init__(self, width, height, xPos, yPos, color): super().__init__(width, height, xPos, yPos, color) buttons.register(defines.BTN_A, self._up) buttons.register(defines.BTN_LEFT, self._left) buttons.register(defines.BTN_RIGHT, self._right)
def input_right(pressed): global direction global can_move if direction != LEFT and can_move: direction = RIGHT can_move = False def input_B(pressed): global direction direction = defines.BTN_B buttons.register(UP, input_up) buttons.register(DOWN, input_down) buttons.register(LEFT, input_left) buttons.register(RIGHT, input_right) buttons.register(defines.BTN_B, input_B) while direction != defines.BTN_B: cur_x, cur_y = snake[0] new_x, new_y = (cur_x + (1 if direction == RIGHT else (-1 if direction == LEFT else 0)), cur_y + (1 if direction == DOWN else (-1 if direction == UP else 0))) # Make snake loop from one border to the other new_x %= rgb.PANEL_WIDTH
server.network_type = gameservices.GAME_HOST_NETWORK_TYPE_HOTSPOT server.start() print("Waiting for connection...") server.wait_for_connection() connected = True print("Done.") if badgehelper.on_badge(): rgb.clear() rgb.background((0, 0, 0)) rgb.scrolltext("(host) running...", (255, 255, 255)) import buttons, defines buttons.register(defines.BTN_LEFT, on_left) buttons.register(defines.BTN_RIGHT, on_right) print("(host) running...") row_send = 0 lastping = time.ticks_ms() while True: time.sleep(0.1) data = server.read_data() if data: if data == "row" or data == "row\r\n" or data == "'row'" or data == "'row\\r\\n'": host_on_row()
## Taken from Bas' PrettyClock. ## Get your timezone from ## https://remotemonitoringsystems.ca/time-zone-abbreviations.php rtc = machine.RTC() timezone = machine.nvs_getstr('system', 'timezone') if timezone is None: timezone = 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00' machine.RTC().timezone(timezone) def input_B(pressed): global direction direction = defines.BTN_B buttons.register(defines.BTN_B, input_B) gifd = [0, 0x00FFFFFF, 0, 0, 0, 0x00FFFFFF, 0, 0, 0, 0, 0, 0, 0, 0] tmold = 70 rgb.background((0, 0, 0)) rgb.clear() rgb.framerate(1) while direction != defines.BTN_B: th = '%02d' % rtc.now()[3] tm = '%02d' % rtc.now()[4] if tm != tmold: rgb.clear() rgb.text(th, (255, 255, 255), (3, 0)) rgb.text(tm, (255, 255, 255), (18, 0))
def main(): buttons.register(defines.BTN_A, action_exit) buttons.register(defines.BTN_B, action_exit) show_names()
def _confirmation_dialog_register_callbacks(): buttons.init_button_mapping() buttons.register(defines.BTN_A, _confirmation_dialog_yes_callback) buttons.register(defines.BTN_B, _confirmation_dialog_no_callback)
def _text_input_register_callbacks(): buttons.init_button_mapping() buttons.register(defines.BTN_A, _text_input_confirm_callback) buttons.register(defines.BTN_B, _text_input_cancel_callback) buttons.register(defines.BTN_UP, _text_input_up_callback) buttons.register(defines.BTN_DOWN, _text_input_down_callback) buttons.register(defines.BTN_LEFT, _text_input_left_callback) buttons.register(defines.BTN_RIGHT, _text_input_right_callback)
def _menu_register_callbacks(): buttons.init_button_mapping() buttons.register(defines.BTN_A, _menu_select_callback) buttons.register(defines.BTN_B, _menu_back_callback) buttons.register(defines.BTN_UP, _menu_up_callback) buttons.register(defines.BTN_DOWN, _menu_down_callback) buttons.register(defines.BTN_LEFT, _menu_left_callback) buttons.register(defines.BTN_RIGHT, _menu_right_callback)
import machine, system, term_menu, virtualtimers, tasks.powermanagement as pm, buttons, defines, woezel import rgb saplings = [0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x51feb2ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x000000ff, 0x51feb2ff, 0x000000ff, 0x000000ff] def input_left(pressed): pm.feed() if pressed: rgb.setbrightness(rgb.getbrightness() - 2) def input_right(pressed): pm.feed() if pressed: rgb.setbrightness(rgb.getbrightness() + 2) buttons.register(defines.BTN_LEFT, input_left) buttons.register(defines.BTN_RIGHT, input_right) rgb.clear() rgb.framerate(2) rgb.gif(saplings, (0, 0), (32, 8), 3)
def __init__(self, mode="singleplayer", role="host", hostsettings="survivor"): defs = Defs() rgb.clear() self.MULTIPLAYER_LINES_SURVIVOR = 0 self.MULTIPLAYER_LINES_RANDOM = 1 self.mode = mode self.role = role self.hostsettings = hostsettings self.multiplayer_lines = self.MULTIPLAYER_LINES_SURVIVOR self.font = "fixed_10x20" self.board_height = 8 self.board_width = 32 self.board_rotated = True self.board_color_background = defs.gray self.game_default_step_time = 500 self.game_step_time = self.game_default_step_time self.game_step_speed_increase = 10 self.game_width = 8 self.game_height = self.board_width - 5 self.game_blockedlines = 0 self.game_won = False self.game_over = False self.receive_row = 0 # self.game_height = 10 # self.game_color_piece = defs.white self.game_color_filledline = defs.blue self.game_color_addedline = defs.red self.game_color_blockedlines = defs.orange self.game_color_background = defs.black self.game_color_piece = [ defs.white, defs.blue, defs.red, defs.yellow, defs.green, defs.purple, defs.cyan ] # self.game_linecolor = defs.white self.frame = [] for i in range(256): self.frame += [0] # nr of unique rotations per piece self.piece_rotations = [1, 2, 2, 2, 4, 4, 4] # Piece data: [piece_nr * 32 + rot_nr * 8 + brick_nr * 2 + j] # with rot_nr between 0 and 4 # with the brick number between 0 and 4 # and j == 0 for X coord, j == 1 for Y coord self.piece_data = [ # pixel block 0, 0, -1, 0, -1, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # line block 0, 0, -2, 0, -1, 0, 1, 0, 0, 0, 0, 1, 0, -1, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # S-block 0, 0, -1, -1, 0, -1, 1, 0, 0, 0, 0, 1, 1, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # Z-block 0, 0, -1, 0, 0, -1, 1, -1, 0, 0, 1, 1, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # L-block 0, 0, -1, 0, -1, -1, 1, 0, 0, 0, 0, 1, 0, -1, 1, -1, 0, 0, -1, 0, 1, 0, 1, 1, 0, 0, -1, 1, 0, 1, 0, -1, # J-block 0, 0, -1, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, -1, 1, 1, 0, 0, -1, 1, -1, 0, 1, 0, 0, 0, 0, 1, 0, -1, -1, -1, # T-block 0, 0, -1, 0, 0, -1, 1, 0, 0, 0, 0, 1, 0, -1, 1, 0, 0, 0, -1, 0, 0, 1, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1 ] buttons.register(defines.BTN_A, self.btn_a) buttons.register(defines.BTN_UP, self.btn_up) buttons.register(defines.BTN_DOWN, self.btn_down) buttons.register(defines.BTN_LEFT, self.btn_left) buttons.register(defines.BTN_RIGHT, self.btn_right) self.client = None self.host = None self.connected = False
def start(): global options global install_path options = None install_path = None buttons.init_button_mapping() buttons.register(defines.BTN_A, input_A) buttons.register(defines.BTN_B, input_B) buttons.register(defines.BTN_UP, input_up) buttons.register(defines.BTN_DOWN, input_down) buttons.register(defines.BTN_LEFT, input_left) buttons.register(defines.BTN_RIGHT, input_right) populate_apps() render_current_app()
new_name = uinterface.text_input() if new_name is not None and new_name != '': machine.nvs_setstr('badge', 'nickname', new_name) system.start('nickname') def render(): rgb.clear() rgb.scrolltext(nickname) def reset_nickname(_): global should_set should_set = True if nickname is None or nickname == '': should_set = True buttons.register(defines.BTN_A, reset_nickname) if not should_set: render() # Because we can't use uinterface from within interrupt handlers while True: if should_set: set_nickname() render() should_set = False time.sleep(0.1)
action = defines.BTN_B def input_up(pressed): global action if pressed: action = defines.BTN_UP def input_down(pressed): global action if pressed: action = defines.BTN_DOWN buttons.register(defines.BTN_B, input_B) buttons.register(defines.BTN_UP, input_up) buttons.register(defines.BTN_DOWN, input_down) gc.collect() while True: if tick < REFRESH_RATE: gc.collect() sleep(0.1) rgb.pixel((150, 150, 0), (int(round(tick)), 7)) tick += 1 continue else: tick = 0
rgb.text('E {}'.format(e)) def draw_text(): global l, color rgb.clear() if l: rgb.pixel((0, 150, 0), (REFRESH_RATE, 7)) # green for new data for i, d in enumerate(l): rgb.text(d, colors[color][i], (ceil(31 / len(l)) * i, 0)) else: rgb.text('E Data') # init buttons.register(UP, input_up) buttons.register(DOWN, input_down) buttons.register(LEFT, input_left) buttons.register(RIGHT, input_right) buttons.register(B, input_B) buttons.register(A, input_A) rgb.setfont(rgb.FONT_6x3) rgb.framerate(10) # second updates REFRESH_RATE = 31 # times framerate updates. # wifi connect if not wifi.status(): if not uinterface.connect_wifi(): system.reboot() rgb.text('Hi!')