lazy_entry const* lazy_entry::dict_find_list(char const* name) const { lazy_entry const* e = dict_find(name); if (e == 0 || e->type() != lazy_entry::list_t) return 0; return e; }
lazy_entry const* lazy_entry::dict_find_string(char const* name) const { lazy_entry const* e = dict_find(name); if (e == 0 || e->type() != lazy_entry::string_t) return 0; return e; }
lazy_entry const* lazy_entry::dict_find_dict(std::string const& name) const { lazy_entry const* e = dict_find(name); if (e == 0 || e->type() != lazy_entry::dict_t) return 0; return e; }
void dashboard_update(DictionaryIterator *received){ Tuple *tuple; tuple = dict_find(received, CAPTION1_KEY); if(tuple) { text_layer_set_text(c1_text_layer, tuple->value->cstring); } else{ text_layer_set_text(c1_text_layer,""); } tuple = dict_find(received, VALUE1_KEY); if(tuple) { text_layer_set_text(v1_text_layer, tuple->value->cstring); } else{ text_layer_set_text(v1_text_layer,""); } tuple = dict_find(received, CAPTION2_KEY); if(tuple) { text_layer_set_text(c2_text_layer, tuple->value->cstring); } else{ text_layer_set_text(c2_text_layer,""); } tuple = dict_find(received, VALUE2_KEY); if(tuple) { text_layer_set_text(v2_text_layer, tuple->value->cstring); } else{ text_layer_set_text(v2_text_layer,""); } tuple = dict_find(received, CAPTION3_KEY); if(tuple) { text_layer_set_text(c3_text_layer, tuple->value->cstring); } else{ text_layer_set_text(c3_text_layer,""); } tuple = dict_find(received, VALUE3_KEY); if(tuple) { text_layer_set_text(v3_text_layer, tuple->value->cstring); } else{ text_layer_set_text(v3_text_layer,""); } tuple = dict_find(received, MESSAGE_KEY); if(tuple && strlen(tuple->value->cstring)>0) { text_layer_set_text(m_text_layer, tuple->value->cstring); text_layer_set_background_color(m_text_layer,GColorWhite); text_layer_set_text_color(m_text_layer,GColorBlack); } else{ text_layer_set_text(m_text_layer,""); text_layer_set_background_color(m_text_layer,GColorBlack); } if(!app_timer_reschedule(clear_timer,5000)){ clear_timer = app_timer_register(5000,dashboard_clear,dashboard_window); } }
pascal_string lazy_entry::dict_find_pstr(char const* name) const { lazy_entry const* e = dict_find(name); if (e == 0 || e->type() != lazy_entry::string_t) return pascal_string(0, 0); return e->string_pstr(); }
/* * Allocate a variable for a Dictionary and fill it from "*arg". * Return OK or FAIL. Returns NOTDONE for {expr}. */ int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate) { dict_T *d = NULL; typval_T tvkey; typval_T tv; char_u *key = NULL; dictitem_T *item; char_u *start = skipwhite(*arg + 1); char_u buf[NUMBUFLEN]; /* * First check if it's not a curly-braces thing: {expr}. * Must do this without evaluating, otherwise a function may be called * twice. Unfortunately this means we need to call eval1() twice for the * first item. * But {} is an empty Dictionary. */ if (*start != '}') { if (eval1(&start, &tv, FALSE) == FAIL) /* recursive! */ return FAIL; if (*start == '}') return NOTDONE; } if (evaluate) { d = dict_alloc(); if (d == NULL) return FAIL; } tvkey.v_type = VAR_UNKNOWN; tv.v_type = VAR_UNKNOWN; *arg = skipwhite(*arg + 1); while (**arg != '}' && **arg != NUL) { if (eval1(arg, &tvkey, evaluate) == FAIL) /* recursive! */ goto failret; if (**arg != ':') { EMSG2(_("E720: Missing colon in Dictionary: %s"), *arg); clear_tv(&tvkey); goto failret; } if (evaluate) { key = get_tv_string_buf_chk(&tvkey, buf); if (key == NULL) { /* "key" is NULL when get_tv_string_buf_chk() gave an errmsg */ clear_tv(&tvkey); goto failret; } } *arg = skipwhite(*arg + 1); if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */ { if (evaluate) clear_tv(&tvkey); goto failret; } if (evaluate) { item = dict_find(d, key, -1); if (item != NULL) { EMSG2(_("E721: Duplicate key in Dictionary: \"%s\""), key); clear_tv(&tvkey); clear_tv(&tv); goto failret; } item = dictitem_alloc(key); clear_tv(&tvkey); if (item != NULL) { item->di_tv = tv; item->di_tv.v_lock = 0; if (dict_add(d, item) == FAIL) dictitem_free(item); } } if (**arg == '}') break; if (**arg != ',') { EMSG2(_("E722: Missing comma in Dictionary: %s"), *arg); goto failret; } *arg = skipwhite(*arg + 1); } if (**arg != '}') { EMSG2(_("E723: Missing end of Dictionary '}': %s"), *arg); failret: if (evaluate) dict_free(d); return FAIL; } *arg = skipwhite(*arg + 1); if (evaluate) { rettv->v_type = VAR_DICT; rettv->vval.v_dict = d; ++d->dv_refcount; } return OK; }
static void in_received_handler(DictionaryIterator *received, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Received a message!"); Tuple *tuple; /** * Put stops */ if ( (tuple = dict_find(received, PUT_STOPS)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_STOPS"); handle_put_stops(tuple); } /** * Location status */ else if ( (tuple = dict_find(received, PUT_STOPS_LOCATION_SUCCESS)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_STOPS_LOCATION_SUCCESS"); handle_put_stops_location_success(tuple); } else if ( (tuple = dict_find(received, PUT_STOPS_LOCATION_ERROR)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_STOPS_LOCATION_ERROR"); handle_put_stops_location_error(tuple); } /** * Put stops status */ else if ( (tuple = dict_find(received, PUT_STOPS_EMPTY)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_STOPS_EMPTY"); handle_put_stops_empty(tuple); } else if ( (tuple = dict_find(received, PUT_STOPS_ERROR)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_STOPS_ERROR"); handle_put_stops_error(tuple); } /** * Put Departure */ else if ( (tuple = dict_find(received, PUT_DEPARTURE)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_DEPARTURE"); handle_put_departure(received); } /** * Put departure status */ else if ( (tuple = dict_find(received, PUT_DEPARTURE_EMPTY)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_DEPARTURE_EMPTY"); handle_put_departure_empty(tuple); } else if ( (tuple = dict_find(received, PUT_DEPARTURE_ERROR)) ) { APP_LOG(APP_LOG_LEVEL_DEBUG, "PUT_DEPARTURE_ERROR"); handle_put_departure_error(tuple); } /** * Invalid message */ else { APP_LOG(APP_LOG_LEVEL_DEBUG, "Invalid message!"); } }
boost::int64_t lazy_entry::dict_find_int_value(char const* name, boost::int64_t default_val) const { lazy_entry const* e = dict_find(name); if (e == 0 || e->type() != lazy_entry::int_t) return default_val; return e->int_value(); }
void rcv(DictionaryIterator *received, void *context) { // Got a message callback Tuple *t; int *val; t=dict_find(received, SM_WEATHER_COND_KEY); if (t!=NULL) { memcpy(weather_cond_str, t->value->cstring, strlen(t->value->cstring)); weather_cond_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(text_weather_cond_layer, weather_cond_str); } t=dict_find(received, SM_WEATHER_TEMP_KEY); if (t!=NULL) { memcpy(weather_temp_str, t->value->cstring, strlen(t->value->cstring)); APP_LOG(APP_LOG_LEVEL_DEBUG, "STRING LENGTH: %d", strlen(t->value->cstring)); weather_temp_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(text_weather_temp_layer, weather_temp_str); } t=dict_find(received, SM_COUNT_MAIL_KEY); if (t!=NULL) { memcpy(mail_count_str, t->value->cstring, strlen(t->value->cstring)); mail_count_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(text_mail_layer, mail_count_str); } t=dict_find(received, SM_COUNT_SMS_KEY); if (t!=NULL) { memcpy(sms_count_str, t->value->cstring, strlen(t->value->cstring)); sms_count_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(text_sms_layer, sms_count_str); } t=dict_find(received, SM_COUNT_PHONE_KEY); if (t!=NULL) { memcpy(phone_count_str, t->value->cstring, strlen(t->value->cstring)); phone_count_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(text_phone_layer, phone_count_str); } t=dict_find(received, SM_WEATHER_ICON_KEY); if (t!=NULL) { bitmap_layer_set_bitmap(weather_image, weather_status_imgs[t->value->uint8]); } t=dict_find(received, SM_COUNT_BATTERY_KEY); if (t!=NULL) { batteryPercent = t->value->uint8; layer_mark_dirty(battery_layer); snprintf(string_buffer, sizeof(string_buffer), "%d", batteryPercent); text_layer_set_text(text_battery_layer, string_buffer); } t=dict_find(received, SM_STATUS_CAL_TIME_KEY); if (t!=NULL) { memcpy(calendar_date_str, t->value->cstring, strlen(t->value->cstring)); calendar_date_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(calendar_date_layer, calendar_date_str); } t=dict_find(received, SM_STATUS_CAL_TEXT_KEY); if (t!=NULL) { memcpy(calendar_text_str, t->value->cstring, strlen(t->value->cstring)); calendar_text_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(calendar_text_layer, calendar_text_str); } t=dict_find(received, SM_STATUS_MUS_ARTIST_KEY); if (t!=NULL) { memcpy(music_artist_str, t->value->cstring, strlen(t->value->cstring)); music_artist_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(music_artist_layer, music_artist_str); } t=dict_find(received, SM_STATUS_MUS_TITLE_KEY); if (t!=NULL) { memcpy(music_title_str, t->value->cstring, strlen(t->value->cstring)); music_title_str[strlen(t->value->cstring)] = '\0'; text_layer_set_text(music_song_layer, music_title_str); } }
static void received_data(DictionaryIterator *received, void *context) { app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); uint8_t destModule = dict_find(received, 0)->value->uint8; uint8_t packetId = dict_find(received, 1)->value->uint8; bool autoSwitch = dict_find(received, 999) != NULL; if (destModule == 0 && packetId == 0) { received_config(received); return; } if (!gotConfig) //Do not react to anything until we got config return; if (destModule == 0) { if (packetId == 1) { closingMode = true; window_stack_pop_all(false); switchWindow(0); return; } if (curWindow != 0) { if (autoSwitch) switchWindow(0); else return; } main_menu_data_received(packetId, received); } else if (destModule == 1) { if (curWindow != 1) { if (autoSwitch) switchWindow(1); else return; } call_window_data_received(packetId, received); } else if (destModule == 2) { if (curWindow != 2) { if (autoSwitch) switchWindow(2); else return; } call_log_window_data_received(packetId, received); } else if (destModule == 3) { if (curWindow != 3) { if (autoSwitch) switchWindow(3); else return; } contacts_window_data_received(packetId, received); } else if (destModule == 4) { if (curWindow != 4) { if (autoSwitch) switchWindow(4); else return; } number_picker_window_data_received(packetId, received); } }
/// Set a value in a dict. Objects are recursively expanded into their /// vimscript equivalents. Passing 'nil' as value deletes the key. /// /// @param dict The vimscript dict /// @param key The key /// @param value The new value /// @param[out] err Details of an error that may have occurred /// @return the old value, if any Object dict_set_value(dict_T *dict, String key, Object value, Error *err) { Object rv = OBJECT_INIT; if (dict->dv_lock) { api_set_error(err, Exception, _("Dictionary is locked")); return rv; } if (key.size == 0) { api_set_error(err, Validation, _("Empty dictionary keys aren't allowed")); return rv; } if (key.size > INT_MAX) { api_set_error(err, Validation, _("Key length is too high")); return rv; } dictitem_T *di = dict_find(dict, (uint8_t *)key.data, (int)key.size); if (value.type == kObjectTypeNil) { // Delete the key if (di == NULL) { // Doesn't exist, fail api_set_error(err, Validation, _("Key \"%s\" doesn't exist"), key.data); } else { // Return the old value rv = vim_to_object(&di->di_tv); // Delete the entry hashitem_T *hi = hash_find(&dict->dv_hashtab, di->di_key); hash_remove(&dict->dv_hashtab, hi); dictitem_free(di); } } else { // Update the key typval_T tv; // Convert the object to a vimscript type in the temporary variable if (!object_to_vim(value, &tv, err)) { return rv; } if (di == NULL) { // Need to create an entry di = dictitem_alloc((uint8_t *) key.data); dict_add(dict, di); } else { // Return the old value rv = vim_to_object(&di->di_tv); clear_tv(&di->di_tv); } // Update the value copy_tv(&tv, &di->di_tv); // Clear the temporary variable clear_tv(&tv); } return rv; }
static void inbox_received_callback(DictionaryIterator *iterator, void *context) { // Weather ------------------------------------------------------------------- static char temperature_buffer[8]; static char weather_layer_buffer[8]; int temperature = 0; Tuple *temp_tuple = dict_find(iterator, KEY_TEMPERATURE); static int temp_in_c; if( temp_tuple ) { temp_in_c = (int)temp_tuple->value->int32; if( persist_read_bool(KEY_WEATHER_UNIT) == true ) { temperature = convert_to_fahrenheit(temp_in_c); } else { temperature = temp_in_c; } } Tuple *unit_tuple = dict_find(iterator, KEY_WEATHER_UNIT); if( unit_tuple && unit_tuple->value->int8 > 0 ) { // USE CELCIOUS UNITS persist_write_bool(KEY_WEATHER_UNIT, false); APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Units are C\n"); temperature = temp_in_c; } else if( unit_tuple && unit_tuple->value->int8 <= 0 ) { // USEFARIENHEIT persist_write_bool(KEY_WEATHER_UNIT, true); APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Units are F\n"); temperature = convert_to_fahrenheit(temp_in_c); } snprintf(temperature_buffer, sizeof(temperature_buffer), "%d", temperature); snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s°", temperature_buffer); text_layer_set_text(s_weather_textLayer, weather_layer_buffer); // End Weather --------------------------------------------------------------- // Configuration ------------------------------------------------------------- // Color =================== #if defined(PBL_COLOR) Tuple *color_red_accent = dict_find(iterator, KEY_COLOR_RED_ACCENT); Tuple *color_green_accent = dict_find(iterator, KEY_COLOR_GREEN_ACCENT); Tuple *color_blue_accent = dict_find(iterator, KEY_COLOR_BLUE_ACCENT); Tuple *color_red_time = dict_find(iterator, KEY_COLOR_RED_TIME); Tuple *color_green_time = dict_find(iterator, KEY_COLOR_GREEN_TIME); Tuple *color_blue_time = dict_find(iterator, KEY_COLOR_BLUE_TIME); if(color_red_accent && color_green_accent && color_blue_accent) { // Apply the color if available int red_accent = color_red_accent->value->int32; int green_accent = color_green_accent->value->int32; int blue_accent = color_blue_accent->value->int32; // Persist values persist_write_int(KEY_COLOR_RED_ACCENT, red_accent); persist_write_int(KEY_COLOR_GREEN_ACCENT, green_accent); persist_write_int(KEY_COLOR_BLUE_ACCENT, blue_accent); GColor bg_color_accent = GColorFromRGB(red_accent, green_accent, blue_accent); text_layer_set_background_color(s_ui_top, bg_color_accent); text_layer_set_background_color(s_ui_bottom, bg_color_accent); text_layer_set_text_color(s_dayOfWeek_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack); text_layer_set_text_color(s_date_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack); text_layer_set_text_color(s_weather_textLayer, gcolor_is_dark(bg_color_accent) ? GColorWhite : GColorBlack); } if(color_red_time && color_green_time && color_blue_time) { // Apply the color if available int red_time = color_red_time->value->int32; int green_time = color_green_time->value->int32; int blue_time = color_blue_time->value->int32; // Persist values persist_write_int(KEY_COLOR_RED_TIME, red_time); persist_write_int(KEY_COLOR_GREEN_TIME, green_time); persist_write_int(KEY_COLOR_BLUE_TIME, blue_time); GColor bg_color_time = GColorFromRGB(red_time, green_time, blue_time); window_set_background_color(s_main_window, bg_color_time); text_layer_set_text_color(s_time_textLayer, gcolor_is_dark(bg_color_time) ? GColorWhite : GColorBlack); } #endif // End Color =============== // Date Format static char temporary_date_holder_callback[32]; Tuple *date_format_tuple = dict_find(iterator, KEY_DATE_FORMAT); if( date_format_tuple ) { APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date Tuple Worked!\n"); APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Value Recieved from Date Tuple: %d\n", (int)date_format_tuple->value->int8); } else { APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date Tuple Failed\n"); } if( date_format_tuple && date_format_tuple->value->int8 == 49 ) { snprintf(temporary_date_holder_callback, sizeof(temporary_date_holder_callback), "%s.%s", day_tickTime, month_tickTime); // snprintf(dateWithoutYear, sizeof(dateWithoutYear), "\0"); snprintf(ddmm_dateWithoutYear, sizeof(ddmm_dateWithoutYear), "%s", temporary_date_holder_callback); persist_write_int(KEY_DATE_FORMAT, 1); text_layer_set_text(s_date_textLayer, temporary_date_holder_callback); APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date was updated as DD-MM 1\n"); } else if( date_format_tuple && date_format_tuple->value->int8 == 48 ){ snprintf(temporary_date_holder_callback, sizeof(temporary_date_holder_callback), "%s.%s", month_tickTime, day_tickTime); // snprintf(dateWithoutYear, sizeof(dateWithoutYear), "\0"); snprintf(dateWithoutYear, sizeof(dateWithoutYear), "%s", temporary_date_holder_callback); persist_write_int(KEY_DATE_FORMAT, 0); text_layer_set_text(s_date_textLayer, temporary_date_holder_callback); APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Date was updated as MM-DD 1\n"); } // Add year or not static char temporary_dateWithoutYear_holder_update[32]; Tuple *year_is_displayed_tuple = dict_find(iterator, KEY_DATE_ADD_YEAR); if( year_is_displayed_tuple && year_is_displayed_tuple->value->int8 > 0 ) { if( persist_read_int(KEY_DATE_FORMAT) == 1 ) { strcpy(temporary_dateWithoutYear_holder_update, ddmm_dateWithoutYear); } else if( persist_read_int(KEY_DATE_FORMAT) == 0 ) { strcpy(temporary_dateWithoutYear_holder_update, dateWithoutYear); } strcat(temporary_dateWithoutYear_holder_update, year_tickTime); persist_write_bool(KEY_DATE_ADD_YEAR, true); text_layer_set_text(s_date_textLayer, temporary_dateWithoutYear_holder_update); } else if( year_is_displayed_tuple && year_is_displayed_tuple->value->int8 <= 0 ) { persist_write_bool(KEY_DATE_ADD_YEAR, false); if( persist_read_int(KEY_DATE_FORMAT) == 1 ) text_layer_set_text(s_date_textLayer, ddmm_dateWithoutYear); else text_layer_set_text(s_date_textLayer, dateWithoutYear); } // Language Handing On Callback Tuple *lang_is_eng_tuple = dict_find(iterator, KEY_LANGUAGE); if( lang_is_eng_tuple ) { APP_LOG(APP_LOG_LEVEL_INFO, "Callback: lang Tuple Worked!\n"); APP_LOG(APP_LOG_LEVEL_INFO, "Callback: Value Recieved from lang Tuple: %d\n", (int)lang_is_eng_tuple->value->int8); } else { APP_LOG(APP_LOG_LEVEL_INFO, "Callback: lang Tuple Failed\n"); } if( lang_is_eng_tuple && lang_is_eng_tuple->value->int8 == 49 ) { // Time to convert this to spanish int dayOfWeekInt = atoi(dayOfWeekNumber_tickTime); static char temporary_day_of_week_holder_callback[8]; switch(dayOfWeekInt) { case 0: snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Dom"); break; case 1: snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Lun"); break; case 2: snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Mar"); break; case 3: snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Mie"); break; case 4: snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Jue"); break; case 5: snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Vie"); break; case 6: snprintf(temporary_day_of_week_holder_callback, sizeof(temporary_day_of_week_holder_callback), "%s", "Sab"); break; default: text_layer_set_text(s_dayOfWeek_textLayer, temporary_day_of_week_holder_callback); break; } persist_write_int(KEY_LANGUAGE, 1); text_layer_set_text(s_dayOfWeek_textLayer, temporary_day_of_week_holder_callback); } else if( lang_is_eng_tuple && lang_is_eng_tuple->value->int8 == 48 ) { persist_write_int(KEY_LANGUAGE, 0); // English text_layer_set_text(s_dayOfWeek_textLayer, engDayOfWeek_tickTime); } // End Configuration --------------------------------------------------------- }
static void inbox_received_handler(DictionaryIterator *iter, void *context) { Tuple *result = dict_find(iter, RESULT); Tuple *showType = dict_find(iter, SHOW_TYPE); if(result) { APP_LOG(APP_LOG_LEVEL_INFO, "Phone sent: %d", (int)result->value->int32); if((int)result->value->int32 == RESULT_DONE) { isDone = true; APP_LOG(APP_LOG_LEVEL_INFO, "Phone sent done"); if(indexCur < NUM_ITEMS) { APP_LOG(APP_LOG_LEVEL_INFO, "All messages sent!"); send(SEND_DONE, 0); if (showType) { int type = (int)showType->value->int32; if (type == SHOW_ING) { APP_LOG(APP_LOG_LEVEL_INFO, "message: %s", ingredients); wdwScrollSetText(window_stack_get_top_window(), ingredients); } if (type == SHOW_STEP) { //char *message[NUM_ITEMS * MAX_LENGTH]; for(int i = 0; i < NUM_ITEMS; i++) { if (dataItems[i][0] != '\0') { wdwScrollSetText(window_stack_get_top_window(), dataItems[i]); APP_LOG(APP_LOG_LEVEL_INFO, "dataitem[%d]: %s", i, dataItems[i]); } } } } } indexCur = 0; } else if((int)result->value->int32 == RESULT_SENDING) { isDone = false; int index = 0; Tuple *item = dict_find(iter, INDEX); Tuple *ingredient = dict_find(iter, TYPE_INGREDIENT); Tuple *step = dict_find(iter, TYPE_STEP); if(item) { index = (int)item->value->int32; APP_LOG(APP_LOG_LEVEL_INFO, "Found item %d", index); } if (item || ingredient || step) { Tuple *title = dict_find(iter, TYPE_TITLE); static char buffer[NUM_ITEMS*MAX_LENGTH]; if (title && item) { snprintf(buffer, sizeof(buffer), "#%d: %s", index, title->value->cstring); strcpy(dataItems[index], buffer); APP_LOG(APP_LOG_LEVEL_INFO, "%s", buffer); } if (ingredient) { //snprintf(buffer, sizeof(buffer), "#%d: %s", index, ingredient->value->cstring); //strcpy(dataItems[index], buffer); memset(&ingredients[0], 0, sizeof(ingredients)); snprintf(buffer, sizeof(buffer), "%s", ingredient->value->cstring); strcpy(ingredients, buffer); APP_LOG(APP_LOG_LEVEL_INFO, "%s", buffer); } if (step) { //memset(&ingredients[0], 0, sizeof(ingredients)); memset(&dataItems[0], 0, sizeof(dataItems)); snprintf(buffer, sizeof(buffer), "%s", step->value->cstring); char copyBuffer[NUM_ITEMS*MAX_LENGTH]; strcpy(copyBuffer, buffer); dataItemsIndex = -1; char *split = strtokC(copyBuffer, DELIMITER); APP_LOG(APP_LOG_LEVEL_INFO, "split %s", split); while (split != NULL && dataItemsIndex < NUM_ITEMS) { dataItemsIndex++; strcpy(dataItems[dataItemsIndex], split); APP_LOG(APP_LOG_LEVEL_INFO, "copied %s", dataItems[dataItemsIndex]); split = strtokC (NULL, DELIMITER); } APP_LOG(APP_LOG_LEVEL_INFO, "%s", buffer); } indexCur = index + 1; APP_LOG(APP_LOG_LEVEL_INFO, "set indexCurr to %d", index); if (indexCur < NUM_ITEMS && !isDone) { send(SEND_NEXT, indexCur); APP_LOG(APP_LOG_LEVEL_INFO, "Send next message: %d", indexCur); } } } } }
void dict_set( Dict *d, Value key, Value val ) { DictEntry *entry = dict_find( d, key, true ); entry->val = val; }
void process_eventsmenu_message(DictionaryIterator *received) { Tuple *tuple; tuple = dict_find(received, KEY_INIT); if (tuple) { if (tuple->value->int8 == 0) { eventsmenu_firstload(); } else { if (!persist_exists(PERSIST_KEY_VERSION)) { if(persist_exists(PERSIST_EVENT_TITLE)) persist_write_int(PERSIST_KEY_VERSION, 21); else persist_write_int(PERSIST_KEY_VERSION, APP_VERSION); } if (persist_read_int(PERSIST_KEY_VERSION) < 22) { ui_messagebox_show("What's new", "Version 2.2: Added event reminders. To enable, visit app settings on phone."); } if (persist_read_int(PERSIST_KEY_VERSION) < 25) { ui_messagebox_show("What's new", "Version 2.5: Added auto refresh. To enable, visit app settings on phone."); } if (persist_read_int(PERSIST_KEY_VERSION) < APP_VERSION) { persist_write_int(PERSIST_KEY_VERSION, APP_VERSION); } } send_client_secret(); wakeup_schedule_sync(); } tuple = dict_find(received, KEY_SHOW_LOADING); if(tuple) { eventsmenu_loading(); } tuple = dict_find(received, KEY_EVENT_ID); if(tuple) { current_event_id = tuple->value->uint8; if (persist_exists((current_event_id + 1) * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE)) persist_delete((current_event_id + 1) * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE); } tuple = dict_find(received, KEY_EVENT_TITLE); if(tuple) { persist_write_string(PERSIST_EVENT_TITLE + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_START_DATE); if(tuple) { persist_write_int(PERSIST_EVENT_START_DATE + current_event_id*PERSIST_EVENT_FIELDCOUNT, tuple->value->uint32); } tuple = dict_find(received, KEY_EVENT_END_DATE); if(tuple) { persist_write_int(PERSIST_EVENT_END_DATE + current_event_id*PERSIST_EVENT_FIELDCOUNT, tuple->value->uint32); } tuple = dict_find(received, KEY_EVENT_LOCATION); if(tuple) { persist_write_string(PERSIST_EVENT_LOCATION + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_ATTENDEES); if(tuple) { persist_write_string(PERSIST_EVENT_ATTENDEES + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_BODY); if(tuple) { persist_write_string(PERSIST_EVENT_BODY + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_REFRESH_UI); if(tuple) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Refreshing events menu"); menu_layer_reload_data(s_menu_layer); text_layer_set_text(s_title_layer, "Events (online)"); wakeup_schedule_event_reminder(); if (layer_get_hidden(menu_layer_get_layer(s_menu_layer))) { layer_set_hidden(text_layer_get_layer(s_message_layer), true); layer_set_hidden(menu_layer_get_layer(s_menu_layer), false); } } }
void process_weather_app_message(DictionaryIterator *iterator, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "do weather update"); Tuple *t; t = dict_find(iterator, MESSAGE_KEY_WEATHER_TEMPERATURE); if (t) { APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "temperature %d", (int)t->value->int32); weather_data.temperature = t->value->int32; } t = dict_find(iterator, MESSAGE_KEY_WEATHER_TEMPERATURE_MIN); if (t) { APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "temperature min %d", (int)t->value->int32); weather_data.temperature_min = t->value->int32; } t = dict_find(iterator, MESSAGE_KEY_WEATHER_TEMPERATURE_MAX); if (t) { APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "temperature max %d", (int)t->value->int32); weather_data.temperature_max = t->value->int32; } t = dict_find(iterator, MESSAGE_KEY_WEATHER_CONDITIONS_ID); if (t) { APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "condition id %d", (int)t->value->int32); weather_data.condition_id = t->value->int32; } /* // Read first item Tuple *t = dict_read_first(iterator); // For all items while(t != NULL) { // Which key was received? switch(t->key) { case MESSAGE_KEY_WEATHER_TEMPERATURE: APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "temperature %d", (int)t->value->int32); weather_data.temperature = t->value->int32; break; case MESSAGE_KEY_WEATHER_TEMPERATURE_MIN: APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "temperature %d", (int)t->value->int32); weather_data.temperature_min = t->value->int32; break; case MESSAGE_KEY_WEATHER_TEMPERATURE_MAX: APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "temperature %d", (int)t->value->int32); weather_data.temperature_max = t->value->int32; break; case MESSAGE_KEY_WEATHER_CONDITIONS_ID: //APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "%s", t->value->cstring); //snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring); APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "condition id %d", (int)t->value->int32); weather_data.condition_id = t->value->int32; break; case MESSAGE_KEY_WEATHER_ICON_ID: APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "icon id %s", t->value->cstring); snprintf(weather_data.icon_id, sizeof(weather_data.icon_id), "%s", t->value->cstring); break; case MESSAGE_KEY_WEATHER: // just identifier break; default: APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key); break; } // Look for next item t = dict_read_next(iterator); } */ weather_data.fetch_time = time(NULL); weather_display_refresh(); }
static void handle_set_scrollable(DictionaryIterator *iter, SimplyData *simply) { Tuple *tuple; if ((tuple = dict_find(iter, 1))) { simply_set_scrollable(simply, tuple->value->int32); } }
static void in_received_handler(DictionaryIterator *iter, void *context) { bool setHighLow = false; Tuple *style_tuple = dict_find(iter, STYLE_KEY); if (style_tuple && style_tuple->value->uint8 != mConfigStyle) { mConfigStyle = style_tuple->value->uint8; setStyle(); } Tuple *bluetoothvibe_tuple = dict_find(iter, BLUETOOTHVIBE_KEY); if (bluetoothvibe_tuple) { mConfigBluetoothVibe = bluetoothvibe_tuple->value->uint8; } Tuple *hourlyvibe_tuple = dict_find(iter, HOURLYVIBE_KEY); if (hourlyvibe_tuple) { mConfigHourlyVibe = hourlyvibe_tuple->value->uint8; } Tuple *blink_tuple = dict_find(iter, BLINK_KEY); if (blink_tuple) { mConfigBlink = blink_tuple->value->uint8; tick_timer_service_unsubscribe(); if(mConfigBlink) { tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } else { tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); } } Tuple *dateformat_tuple = dict_find(iter, DATEFORMAT_KEY); if (dateformat_tuple && dateformat_tuple->value->uint8 != mConfigDateFormat) { mConfigDateFormat = dateformat_tuple->value->uint8; time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_tick(tick_time, DAY_UNIT); } Tuple *units_tuple = dict_find(iter, WEATHER_UNITS); if (units_tuple) { if(units_tuple->value->uint8 != mConfigWeatherUnit) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "UNIT! %d, %d", mConfigWeatherUnit, units_tuple->value->uint8); mConfigWeatherUnit = units_tuple->value->uint8; fetch_data(); return; } } Tuple *weather_temperature_tuple = dict_find(iter, WEATHER_TEMPERATURE_KEY); if (weather_temperature_tuple && weather_temperature_tuple->value->int16 != mTemperatureDegrees) { mTemperatureDegrees = weather_temperature_tuple->value->int16; weather_set_temperature(mTemperatureDegrees); } Tuple *weather_icon_tuple = dict_find(iter, WEATHER_ICON_KEY); if (weather_icon_tuple && weather_icon_tuple->value->uint8 != mTemperatureIcon) { mTemperatureIcon = weather_icon_tuple->value->uint8; weather_set_icon(mTemperatureIcon); } Tuple *weather_high_tuple = dict_find(iter, WEATHER_TEMPERATUREHIGH_KEY); if (weather_high_tuple && weather_high_tuple->value->int16 != mTemperatureHigh) { mTemperatureHigh = weather_high_tuple->value->int16; setHighLow = true; } Tuple *weather_low_tuple = dict_find(iter, WEATHER_TEMPERATURELOW_KEY); if (weather_low_tuple && weather_low_tuple->value->int16 != mTemperatureLow) { mTemperatureLow = weather_low_tuple->value->int16; setHighLow = true; } if(setHighLow) { weather_set_highlow(mTemperatureHigh, mTemperatureLow); } }
static void inbox_received_handler(DictionaryIterator *iter, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler"); Tuple *top_bar_color_t = dict_find(iter, KEY_TOP_BAR_COLOR); Tuple *middle_bar_color_t = dict_find(iter, KEY_MIDDLE_BAR_COLOR); Tuple *bottom_bar_color_t = dict_find(iter, KEY_BOTTOM_BAR_COLOR); Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR); Tuple *temp_t = dict_find(iter, KEY_TEMPERATURE); Tuple *conditions_t = dict_find(iter, KEY_CONDITIONS); Tuple *degreeOption_t = dict_find(iter, KEY_DEGREEOPTION); //Store incoming information static char temperature_buffer[8]; static char conditions_buffer[32]; static char weather_layer_buffer[42]; if (degreeOption_t) { degreeOption = degreeOption_t->value->uint32; APP_LOG(APP_LOG_LEVEL_DEBUG, "degree Option : %d", degreeOption); persist_write_int(KEY_DEGREEOPTION, degreeOption); } if (temp_t) { int kelvin = (int) temp_t->value->int32; if (degreeOption == 0) { //celsius int celsius = kelvin - 273.15; snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) celsius); APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Celsius: %d", degreeOption); } else { //fahrenheit int fahrenheit = (kelvin - 273.15) * 1.8 + 32; snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) fahrenheit); APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Fahrenheit: %d", degreeOption); } } if (conditions_t) { snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_t->value->cstring); } if (conditions_t && temp_t) { snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer); text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color)); text_layer_set_text(s_weather_layer, weather_layer_buffer); } if (top_bar_color_t) { int top_bar_color = top_bar_color_t->value->int32; if (top_bar_color == 0) { //quick fix so that black colour persists top_bar_color++; } persist_write_int(KEY_TOP_BAR_COLOR, top_bar_color); //set_background_and_text_color(background_color); s_top_bar_color = GColorFromHEX(top_bar_color); APP_LOG(APP_LOG_LEVEL_DEBUG, "top bar color: %d", top_bar_color); } if (middle_bar_color_t) { int middle_bar_color = middle_bar_color_t->value->int32; if (middle_bar_color == 0) { //quick fix so that black colour persists middle_bar_color++; } persist_write_int(KEY_MIDDLE_BAR_COLOR, middle_bar_color); s_middle_bar_color = GColorFromHEX(middle_bar_color); APP_LOG(APP_LOG_LEVEL_DEBUG, "middle bar color: %d", middle_bar_color); } if (bottom_bar_color_t) { int bottom_bar_color = bottom_bar_color_t->value->int32; if (bottom_bar_color == 0) { //quick fix so that black colour persists bottom_bar_color++; } persist_write_int(KEY_BOTTOM_BAR_COLOR, bottom_bar_color); s_bottom_bar_color = GColorFromHEX(bottom_bar_color); APP_LOG(APP_LOG_LEVEL_DEBUG, "bottom bar color: %d", bottom_bar_color); } if (background_color_t) { int background_color = background_color_t->value->int32; if (background_color == 0) { //quick fix so that black colour persists background_color++; } persist_write_int(KEY_BACKGROUND_COLOR, background_color); APP_LOG(APP_LOG_LEVEL_DEBUG, "background color: %d", background_color); set_background_and_text_color(background_color); } time_t start_time = time(NULL); update_time(localtime(&start_time)); }
std::string lazy_entry::dict_find_string_value(char const* name) const { lazy_entry const* e = dict_find(name); if (e == 0 || e->type() != lazy_entry::string_t) return std::string(); return e->string_value(); }
// ----------------------------------------------------- // Getter for 'url' const char* enamel_get_url(){ Tuple* tuple = dict_find(&s_dict, 1453210600); return tuple ? tuple->value->cstring : "http://lorempixel.com/144/168/"; }
void locale_init(void) { //hard-coded for testing // const char* locale_str = "es"; // Detect system locale const char* locale_str = i18n_get_system_locale(); ResHandle locale_handle = NULL; int locale_size = 0; if (strncmp(locale_str, "fr", 2) == 0) { locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_FRENCH); locale_size = resource_size(locale_handle); } else if (strncmp(locale_str, "es", 2) == 0) { locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_SPANISH); locale_size = resource_size(locale_handle); } else if (strncmp(locale_str, "de", 2) == 0) { locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_GERMAN); locale_size = resource_size(locale_handle); } // Fallback to English for unlocalized languages (0 byte files) if (locale_size == 0) { locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_ENGLISH); locale_size = resource_size(locale_handle); } int resource_offset = 0; int locale_entries = 0; resource_offset += resource_load_byte_range(locale_handle, resource_offset, (uint8_t*)&locale_entries, sizeof(locale_entries)); struct locale { int32_t hashval; int32_t strlen; } locale_info; int dict_buffer_size = locale_size + 7 * locale_entries; //7 byte header per item char *dict_buffer = malloc(dict_buffer_size); dict_write_begin(&s_locale_dict, (uint8_t*)dict_buffer, dict_buffer_size); for (int i = 0; i < locale_entries; i++) { resource_offset += resource_load_byte_range(locale_handle, resource_offset, (uint8_t*)&locale_info, sizeof(struct locale)); struct Tuplet tupl = { .type = TUPLE_CSTRING, .key = locale_info.hashval, .cstring.length = locale_info.strlen}; tupl.cstring.data = malloc(tupl.cstring.length); resource_offset += resource_load_byte_range(locale_handle, resource_offset, (uint8_t*)tupl.cstring.data, tupl.cstring.length); dict_write_tuplet(&s_locale_dict, &tupl); } dict_write_end(&s_locale_dict); } char *locale_str(int hashval) { Tuple *tupl = dict_find(&s_locale_dict, hashval); if (tupl && tupl->value->cstring) { return tupl->value->cstring; } return "\7"; //return blank character }