void handle_http_success(int32_t cookie, int http_status, DictionaryIterator* response, void* context){ request_in_progress = 0; if(http_status != 200){ char status[20] = ""; snprintf(status, 20, "H SUC %i", http_status); show_error(status); return; } if(cookie == REQUEST_ROOMS){ Tuple* count_tuple = dict_find(response, HTTP_KEY_COUNT); if(!count_tuple){ show_error("NO COUNT ROOMS"); return; } room_count = count_tuple->value->int16; if(room_count > 9){ room_count = 9; } Tuple* data_tuple = dict_find(response, HTTP_KEY_DATA); if(!data_tuple){ show_error("NO DATA ROOMS"); return; } uint16_t new_rooms = data_tuple->length / sizeof(Room); uint16_t cpyLength = data_tuple->length; if(cpyLength + sizeof(Room) * rooms_loaded > sizeof(rooms)){ cpyLength = sizeof(rooms) - sizeof(Room) * rooms_loaded; } memcpy(&rooms[rooms_loaded], &(data_tuple->value->data[0]), cpyLength); rooms_loaded += new_rooms; menu_layer_reload_data(&homeLayer); }else if(cookie == REQUEST_DEVICES){ Tuple* count_tuple = dict_find(response, HTTP_KEY_COUNT); if(!count_tuple){ show_error("NO COUNT DEVICES"); return; } device_count = count_tuple->value->int16; if(device_count > 9){ device_count = 9; } Tuple* data_tuple = dict_find(response, HTTP_KEY_DATA); if(!data_tuple){ show_error("NO DATA DEVICES"); return; } uint16_t new_devices = data_tuple->length / sizeof(Device); uint16_t cpyLength = data_tuple->length; if(cpyLength + sizeof(Device) * devices_loaded > sizeof(devices)){ cpyLength = sizeof(devices) - sizeof(Device) * devices_loaded; } memcpy(&devices[devices_loaded], &(data_tuple->value->data[0]), cpyLength); devices_loaded += new_devices; menu_layer_reload_data(&groupLayer); } run_next_request(); }
// Here we capture when a user selects a menu item void menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) { // Use the row to specify which item will receive the select action ControlButton* pushedButton = &menuSets[cell_index->section].menu[cell_index->row]; if (pushedButton->action == REMOTE_ACTION) { DictionaryIterator *iter; if (app_message_outbox_begin(&iter) != APP_MSG_OK) { //return; } if (!didSendAddress) { if (dict_write_cstring(iter, DICT_ADDRESS, address) != DICT_OK) { //return; } if (dict_write_cstring(iter, DICT_PAIR_CODE, pairCode) != DICT_OK) { //return; } didSendAddress = true; } if (dict_write_cstring(iter, COMMAND, pushedButton->action) != DICT_OK) { //return; } if (dict_write_cstring(iter, DATA, pushedButton->data) != DICT_OK) { //return; } dict_write_end(iter); app_message_outbox_send(); } if (pushedButton->action == DISPLAY_IP) { // Update subtitle to show IP pushedButton->subtitle = address; menu_layer_reload_data(menu_layer); } if (pushedButton->action == DISPLAY_PAIR_CODE) { // Update subtitle to show Pair code pushedButton->subtitle = pairCode; menu_layer_reload_data(menu_layer); } if (pushedButton->action == SYNC_ACTION) { didSendAddress = false; } }
void process_tuple(Tuple *t){ int key = t->key; if(key == 9000){ app_timer_register(1000, send_initial_request, NULL); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); return; } if(key < 10){ //HOME switch(key){ case 0: strncpy(home_matchup_subtitle, t->value->cstring, sizeof(home_matchup_subtitle)); break; case 1: strncpy(home_league_subtitle, t->value->cstring, sizeof(home_league_subtitle)); break; case 2: strncpy(home_team_subtitle, t->value->cstring, sizeof(home_team_subtitle)); break; } } else if(key < 100){ //MATCHUP switch(key){ case 10: strncpy(matchup_ally_name, t->value->cstring, sizeof(matchup_ally_name)); break; case 11: matchup_ally_score_int = atoi(t->value->cstring); break; case 12: strncpy(matchup_ally_score_char, t->value->cstring, sizeof(matchup_ally_score_char)); break; case 13: strncpy(matchup_enemy_name, t->value->cstring, sizeof(matchup_enemy_name)); break; case 14: matchup_enemy_score_int = atoi(t->value->cstring); break; case 15: strncpy(matchup_enemy_score_char, t->value->cstring, sizeof(matchup_enemy_score_char)); break; } } else if(key < 200){ //LEAGUE strncpy(league_team_names[key-100], t->value->cstring, sizeof(league_team_names[key-100])); if(strcmp(league_team_names[key-100], "") == 0 && key-100 < num_teams){ num_teams = key-100; menu_layer_reload_data(league_menu_layer); } } else if(key < 300){ //TEAM strncpy(team_player_names[key-200], t->value->cstring, sizeof(team_player_names[key-200])); if(strcmp(team_player_names[key-200], "") == 0 && key-200 < num_players){ num_players = key-200; menu_layer_reload_data(team_menu_layer); } } else if(key == 300){ //DRAFT STATUS if(atoi(t->value->cstring) == 1){ #ifdef PBL_COLOR menu_layer_set_normal_colors(home_menu_layer, GColorBlack, GColorLightGray); menu_layer_set_highlight_colors(home_menu_layer, APP_COLOR, GColorLightGray); menu_layer_reload_data(home_menu_layer); #endif text_layer_set_text(home_text_layer, "Status: Pre-Draft"); pre_draft = true; } } }
static void inbox_received_handler(DictionaryIterator *iterator, void *context) { // Get the first pair Tuple *t = dict_read_first(iterator); int key = (int)(t->key / 256); int menu_item_section = (int)((t->key % 256) / 16); int menu_item = (t->key % 16); // Process all pairs present while(t != NULL) { // Process this pair's key switch(key) { case KEY_STATUS: APP_LOG(APP_LOG_LEVEL_INFO, "STATUS for KEY %d is %d", key, (int)t->value->int32); menu_item_statuses[menu_item_section][menu_item] = get_status_text((int)t->value->int32); menu_layer_reload_data(s_menu_layer); break; case KEY_VIBRATE: // Trigger vibration // text_layer_set_text(s_text_layer, "Vibrate!"); APP_LOG(APP_LOG_LEVEL_INFO, "Vibrate!"); vibes_short_pulse(); break; default: APP_LOG(APP_LOG_LEVEL_INFO, "Unknown key: %d", (int)t->key); break; } // Get next pair, if any t = dict_read_next(iterator); } }
void main_menu_set_selected_index(uint16_t section, uint16_t row){ MenuIndex menu_index; menu_index.section = section; menu_index.row = row; menu_layer_reload_data(s_main_menu_layer); menu_layer_set_selected_index(s_main_menu_layer, menu_index, MenuRowAlignTop, false); }
static void connect_letter(char selectLetter){ // If we see that space sign it means we clear that letter // Get the current index if(selectLetter == ' ' ){ // If plugused is 0 or less then set it to 0 so we don't go over the bound if(plugUsed <= 0){ plugUsed = 0; } // decrement else{ plugUsed--; } } else{ // If the plug used is over ten then tell the user that 10 is the limit if(plugUsed +1> 10){ // ----- Show message ------- selectLetter = ' '; } // If if the plug used is not ten then keep incrementing else{ plugUsed++; } } int index = menu_layer_get_selected_index(plug_layer).row; plugConnectLetters[index][0] = selectLetter; menu_layer_reload_data(plug_layer); }
static void ease_menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { if(cell_index->row == 0) { menu_cell_basic_draw(ctx, cell_layer, s_ease_menu_titles[0], NULL, NULL); } switch(s_ease) { case 2: if(cell_index->row == 1) { menu_cell_basic_draw(ctx, cell_layer, s_ease_menu_titles[2], NULL, NULL); } break; case 3: if(cell_index->row == 1) { menu_cell_basic_draw(ctx, cell_layer, s_ease_menu_titles[2], NULL, NULL); } else if(cell_index->row == 2) { menu_cell_basic_draw(ctx, cell_layer, s_ease_menu_titles[3], NULL, NULL); } break; case 4: if(cell_index->row == 1) { menu_cell_basic_draw(ctx, cell_layer, s_ease_menu_titles[1], NULL, NULL); } else if(cell_index->row == 2) { menu_cell_basic_draw(ctx, cell_layer, s_ease_menu_titles[2], NULL, NULL); } else if(cell_index->row == 3) { menu_cell_basic_draw(ctx, cell_layer, s_ease_menu_titles[3], NULL, NULL); } break; } menu_layer_reload_data(s_ease_menu_layer); }
void options_data_received(DictionaryIterator* data) { vibrateEnabledStatus = dict_find(data, 1)->value->uint8; uint8_t oldInverterEnabledStatus = inverterEnabledStatus; inverterEnabledStatus = dict_find(data, 2)->value->uint8; if (vibrateEnabledStatus == 1){ mainMenuOptionItems[0].subtitle = "Enabled"; } else { mainMenuOptionItems[0].subtitle = "Disabled"; } if (inverterEnabledStatus == 1){ mainMenuOptionItems[1].subtitle = "Enabled"; } else { mainMenuOptionItems[1].subtitle = "Disabled"; } if(oldInverterEnabledStatus != inverterEnabledStatus){ if(inverterEnabledStatus == 1){ layer_add_child(topLayer, inverter_layer_get_layer(inverter_layer)); } else{ layer_remove_from_parent(inverter_layer_get_layer(inverter_layer)); } } if(menuLayer != NULL) menu_layer_reload_data((struct MenuLayer *)menuLayer); }
static void send_to_phone() { APP_LOG(APP_LOG_LEVEL_DEBUG, "Preparing data to send to Phone"); if (listSize == 0) return; DictionaryIterator *dict; app_message_outbox_begin(&dict); int indexToSend = (int) menu_layer_get_selected_index(s_menu_layer).row; APP_LOG(APP_LOG_LEVEL_DEBUG, "statusList[indexToSend] set to: %s", statusList[indexToSend]); if (strcmp(statusList[indexToSend],"Ready") != 0 && strcmp(statusList[indexToSend],"Pending...") != 0) { free (statusList[indexToSend]); statusList[indexToSend] = NULL; APP_LOG(APP_LOG_LEVEL_DEBUG, "?Preparing data to send to Phone"); } menu_layer_reload_data(s_menu_layer); statusList[indexToSend] = "Pending..."; APP_LOG(APP_LOG_LEVEL_DEBUG, "statusList[%d] set to Waiting...", indexToSend); APP_LOG(APP_LOG_LEVEL_DEBUG, "Menu index to send: %d", indexToSend); dict_write_uint8(dict,KEY_INDEX,indexToSend); const uint32_t final_size = dict_write_end(dict); APP_LOG(APP_LOG_LEVEL_DEBUG, "Sent message to phone! (%d bytes)", (int) final_size); app_message_outbox_send(); }
static void menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) { switch (cell_index->row) { case 0: next_unit_index(); break; case 1: next_format(); break; case 2: toggle_first_day(); break; case 3: if (!get_has_reminders()) { show_time(); } else { set_has_reminders(0); cancell_all_reminders(); menu_layer_reload_data(menu_layer); } break; case 4: show_welcome(); break; } layer_mark_dirty((Layer *)menu_layer_get_scroll_layer(menu_layer)); }
void settings_changed_callback(int index, void *context) { switch (index) { case MENU_ITEM_VIBRATE: _bpm_settings.vibrate = !_bpm_settings.vibrate; setting_items[MENU_ITEM_VIBRATE].subtitle = (_bpm_settings.vibrate ? "On" : "Off"); break; case MENU_ITEM_ACCELEROMETER: _bpm_settings.accelerometer = !_bpm_settings.accelerometer; setting_items[MENU_ITEM_ACCELEROMETER].subtitle = (_bpm_settings.accelerometer ? "On" : "Off"); break; case MENU_ITEM_DUALMODE: _bpm_settings.dual_mode = !_bpm_settings.dual_mode; setting_items[MENU_ITEM_DUALMODE].subtitle = (_bpm_settings.dual_mode ? "On" : "Off"); break; case MENU_ITEM_LIGHT: _bpm_settings.light = !_bpm_settings.light; setting_items[MENU_ITEM_LIGHT].subtitle = (_bpm_settings.light ? "On" : "Off"); break; default: break; } save_settings(); menu_layer_reload_data(simple_menu_layer_get_menu_layer(menu_layer)); }
void RegisterMenuCellCallbacks(Menu *menu, MenuSectionNameCallback menuSectionNameCallback, MenuSectionCountCallback menuSectionCountCallback, MenuCountCallback countCallback, MenuNameCallback nameCallback, MenuDescriptionCallback descriptionCallback, MenuSelectCallback selectCallback) { DEBUG_LOG("RegisterMenuCellCallbacks"); menu->useCallbackFunctions = true; menu->menuCountCallback = countCallback; menu->menuNameCallback = nameCallback; menu->menuDescriptionCallback = descriptionCallback; menu->menuSelectCallback = selectCallback; menu->menuSectionCountCallback = menuSectionCountCallback; menu->menuSectionNameCallback = menuSectionNameCallback; if(!menu->menuCountCallback) { ClearMenuCellList(menu); return; } menu->cellCount = 0; menu->cellList = NULL; menu->sectionName = NULL; if(menu->mainMenu) { uint16_t totalCells = GetMenuTotalCellCount(menu); if(totalCells > 0) { MenuIndex index = {.section = 0, .row = 0}; menu_layer_set_selected_index(menu->menuLayer, index, MenuRowAlignCenter, false); menu_layer_reload_data(menu->menuLayer); ShowMenuArrow(); } else
void RegisterMenuCellList(Menu *menu, const char *sectionName, MenuCellDescription *list, uint16_t count) { DEBUG_LOG("RegisterMenuCellList"); if(count == 0) { ClearMenuCellList(menu); return; } menu->useCallbackFunctions = false; menu->menuCountCallback = NULL; menu->menuNameCallback = NULL; menu->menuDescriptionCallback = NULL; menu->menuSelectCallback = NULL; menu->menuSectionCountCallback = NULL; menu->menuSectionNameCallback = NULL; menu->cellList = list; menu->cellCount = count; menu->sectionName = sectionName; if(menu->menuLayerInitialized) { menu_layer_reload_data(menu->menuLayer); MenuIndex index = {.section = 0, .row = 0}; menu_layer_set_selected_index(menu->menuLayer, index, MenuRowAlignCenter, false); } if(menu->mainMenu) ShowMenuArrow(); }
static void items_select_long_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) { const int index = menu_layer_get_selected_index(&items_menu_layer).row; items_todo_list_delete(index); send_request(HTTP_CMD_DELETE, current_list, index); menu_layer_reload_data(&items_menu_layer); }
void arrivals_success(int32_t cookie, int http_status, DictionaryIterator* received, void* context) { Tuple *t = dict_find(received, 1); char *v = t->value->cstring; uint16_t index = 0; uint16_t len = t->length; arrivalsCount = 0; int16_t time = 0; MenuIndex top = { 0, 0 }; PblTm now; get_time(&now); if (clock_is_24h_style()) { string_format_time(arrival_time_str, sizeof(arrival_time_str), "Updated: %H:%M", &now); } else { string_format_time(arrival_time_str, sizeof(arrival_time_str), "Updated: %l:%M %p", &now); } for(unsigned char i=0;i<MAX_ARRIVALS && index < len;i++) { //stokenize(char *source, uint16_t index, char delimiter, char *target, uint16_t max_length) index = stokenize(v, index, ':', ARRIVALS[i].route, ARRIVAL_ROUTE_LENGTH, len); index = stokenize(v, index, ':', ARRIVALS[i].actual, sizeof(ARRIVALS[i].actual), len); index = stokenize(v, index, ':', ARRIVALS[i].scheduled, sizeof(ARRIVALS[i].scheduled), len); //TODO: DRY time = satoi(ARRIVALS[i].actual, strlen(ARRIVALS[i].actual)); if(abs(time) > 99*60 + 59) //Maximum displayable value. time = (99*60 + 59) * (time < 0 ? -1 : 1); if(time > 60 || time < -60) { snprintf(ARRIVALS[i].actual, ARRIVAL_TIME_LENGTH, "%d:%02d", time / 60, abs(time % 60)); } else { snprintf(ARRIVALS[i].actual, ARRIVAL_TIME_LENGTH, "%d", time % 60); } time = satoi(ARRIVALS[i].scheduled, strlen(ARRIVALS[i].scheduled)); if(abs(time) > 99*60 + 59) //Maximum displayable value. time = (99*60 + 59) * (time < 0 ? -1 : 1); if(time > 60 || time < -60) { snprintf(ARRIVALS[i].scheduled, ARRIVAL_TIME_LENGTH, "%d:%02d", time / 60, abs(time % 60)); } else { snprintf(ARRIVALS[i].scheduled, ARRIVAL_TIME_LENGTH, "%d", time % 60); } APP_LOG(APP_LOG_LEVEL_INFO, "Received route:%s actual:%s scheduled:%s (index:%d/%d)", ARRIVALS[i].route, ARRIVALS[i].actual, ARRIVALS[i].scheduled, index, len); ++arrivalsCount; } menu_layer_reload_data(&_arrivalsMenu); menu_layer_set_selected_index(&_arrivalsMenu, top, MenuRowAlignBottom, false); }
void ui_refreshItems(int selectPos) { if (selectPos != -1) { MenuIndex idx; idx.section = 0; idx.row = selectPos; menu_layer_set_selected_index(menu, idx, MenuRowAlignTop, false); } menu_layer_reload_data(menu); }
static void select_callback(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { if(cell_index->row == num_rows) { save_setting(); window_stack_pop(true); } else { // Change selection s_current_selection = cell_index->row; menu_layer_reload_data(menu_layer); } }
void toggle_scan(void) { if (s_is_scanning) { ble_scan_stop(); s_is_scanning = false; } else { ble_scan_start(ble_scan_handler); s_is_scanning = true; } menu_layer_reload_data(s_menu_layer); }
void multi_code_window_second_tick(int seconds) { if (refresh_required) { menu_layer_reload_data(multi_code_menu_layer); menu_layer_set_selected_index(multi_code_menu_layer, MenuIndex(0, otp_selected), MenuRowAlignCenter, true); if(fonts_changed) multi_code_set_fonts(); if (colors_changed) multi_code_apply_display_colors(); refresh_required = false; } }
static void menu_select_long_click(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { user_data *ud = callback_context; if (ud->moving.from < 0) { ud->moving = (moving) { (int8_t) cell_index->row, (int8_t) cell_index->row }; menu_layer_reload_data(menu_layer); } else menu_select_click(menu_layer, cell_index, callback_context); }
static void reset_handler(ClickRecognizerRef recognizer, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Reset"); if (hint_layer) { text_layer_destroy(hint_layer); hint_layer = NULL; } else { window_stack_push(menu_window, animated); menu_layer_reload_data(menu_layer); layer_mark_dirty(menu_layer_get_layer(menu_layer)); } }
static void menu_selection_changed(MenuLayer *menu_layer, MenuIndex new_index, MenuIndex old_index, void *callback_context) { user_data *ud = callback_context; if (ud->moving.to == old_index.row) { ud->moving.to = new_index.row; menu_layer_reload_data(menu_layer); } }
static void load_menu(void) { Tuple *t = dict_read_first(&items_iter); while(t != NULL) { char* id = (char*) t->value->cstring; char* name = split_id_name_pair(id); strip_ext(name); basic_menu_model_add_item(s_model, name, NULL, id); t = dict_read_next(&items_iter); } menu_layer_reload_data(s_menu); layer_set_hidden(s_lyr_loading, true); }
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) { if (key == 0) { count = new_tuple->value->uint8; } else { const char* tmp = new_tuple->value->cstring; if (strlen(tmp) > 1) { enableButton = true; strcpy(rows[key - 1], tmp); // this is hex, but as were only using 8 it's okay } } menu_layer_reload_data(menu_layer); }
static void in_received_handler(DictionaryIterator *iter, void *context) { Tuple *type_tuple = dict_find(iter, DEVICE_TYPE_KEY); Tuple *id_tuple = dict_find(iter, DEVICE_ID_KEY); Tuple *label_tuple = dict_find(iter, DEVICE_LABEL_KEY); Tuple *state_tuple = dict_find(iter, DEVICE_STATE_KEY); APP_LOG(APP_LOG_LEVEL_DEBUG, "rcvd: %s", label_tuple->value->cstring); if (type_tuple && id_tuple && label_tuple && state_tuple) { add_or_update_device(type_tuple->value->uint8, id_tuple->value->cstring, label_tuple->value->cstring, state_tuple->value->uint8); } menu_layer_reload_data(menu_layer); }
static void select_click_handler(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *context) { int n = (int)cell_index->row; if (n == SETTINGS_CHECKBOX_NUM_ROWS) { persist_write_data(PKEY_SELECTION, MenuSelection, sizeof(MenuSelection)); const bool animated = true; window_stack_pop(animated); } else { MenuSelection[n] = !MenuSelection[n]; menu_layer_reload_data(menu_layer); } }
/** * Refresh */ void refresh_stops_window(realtime_transport_type_t ttype) { if (!window_stack_contains_window(transport_type_to_window_map[ttype])) { return; } menu_layer_reload_data(transport_type_to_menulayer_map[ttype]); layer_hide(transport_type_to_loadinglayer_map[ttype]); if (command_timeout_timer != NULL) { app_timer_cancel(command_timeout_timer); command_timeout_timer = NULL; } }
static void append_menu(char *stop, char *code) { if (menu_size == NUM_MENU_ITEMS) { return; } stops[menu_size].name = malloc(sizeof(char)*(strlen(stop)+1)); strcpy(stops[menu_size].name, stop); stops[menu_size].code = malloc(sizeof(char)*(strlen(code)+1)); strcpy(stops[menu_size].code, code); menu_size += 1; menu_layer_reload_data(menu_layer); }
static void select_callback(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { if(cell_index->row == CHECKBOX_WINDOW_NUM_ROWS) { // Do something with choices made for(int i = 0; i < CHECKBOX_WINDOW_NUM_ROWS; i++) { APP_LOG(APP_LOG_LEVEL_INFO, "Option %d was %s", i, (s_selections[i] ? "selected" : "not selected")); } window_stack_pop(true); } else { // Check/uncheck int row = cell_index->row; s_selections[row] = !s_selections[row]; menu_layer_reload_data(menu_layer); } }
static void dep_append_menu(char *headsign, char *minutes) { if (dep_menu_size == DEP_NUM_MENU_ITEMS) { return; } departures[dep_menu_size].headsign = malloc(sizeof(char)*(strlen(headsign)+1)); strcpy(departures[dep_menu_size].headsign, headsign); departures[dep_menu_size].time = malloc(sizeof(char)*(strlen(minutes)+1)); strcpy(departures[dep_menu_size].time, minutes); dep_menu_size += 1; menu_layer_reload_data(dep_menu_layer); }