def start(): global lock_rotation set_display_driver(as1115_write_matrix_symbol) badge_start() # We need buttons setPinDir(BUTTON_LEFT, False) setPinPullup(BUTTON_LEFT, True) monitorPin(BUTTON_LEFT, True) setPinDir(BUTTON_RIGHT, False) setPinPullup(BUTTON_RIGHT, True) monitorPin(BUTTON_RIGHT, True) # Reduce radio transmit power, since we only want to socialize with nearby badges # Hold right button on boot to get default higher tx power if readPin(BUTTON_RIGHT): txPwr(0) # approx 0dBm # Hold left button on boot to lock rotation lock_rotation = not readPin(BUTTON_LEFT) # Initialize the app-switching... app_switch_set_exit(enter_top_menu) app_switch_set_background_1s(esc_background_tick) # Initially, default to "show_scroller" app app_switch(show_scroller_context)
def anime(icon_set, rate, loop_count): """Over the air command: display animation using Doodads font""" save_context() app_switch(messaging_context) load_font(Doodads, Doodads_widths) anim_init(icon_set, rate, messaging_resume_prior) anim_begin(loop_count)
def user_message_init(): global user_msg_text user_msg_text = loadNvParam(NV_USER_MSG) if type(user_msg_text) != 2: # Initialize to empty string if not already a string user_msg_text = "" init_index = ord('A') - ord(' ') + 3 # Start on 'A' (compensate for 3 extra chars) menu_define(user_menu_icons, DEF8x8, DEF8x8_widths, user_message_select_hook, init_index) app_switch(menu_context)
def message(message_text, duration): """Over the air command: display message text for specified duration in seconds""" global msg_duration save_context() app_switch(messaging_context) # Set message and switch over load_font(DEF8x8, DEF8x8_widths) msg_duration = duration set_scroll_text(message_text)
def enter_top_menu(): """This is the app_exit() hook for sub-menu scripts - returns execution to top menu""" menu_define(esc_topmenu_icons, Doodads, Doodads_widths, menu_hook, cur_topmenu_selection) # Assorted cleanup as1115_wr(FEATURE, 0) # Disable blinking and other shenanigans # Switch to the "menu_select" app app_switch(menu_context) menu_play_exit_anim()
def pin_event(pin, is_set): global context if not is_set: # Button pressed if context == 0: app_switch(context1) context = 1 elif context == 1: app_switch(snake_context) context = 2 elif context == 2: app_switch(context0) context = 0
def start(): app_switch(context0)
def menu_hook(menu_selected): global cur_topmenu_selection cur_topmenu_selection = menu_selected context = esc_selection_contexts[menu_selected] if context: app_switch(context)
def messaging_resume_prior(): """We now return to your regularly scheduled programming""" if prior_context: app_switch(prior_context)