static void fetch_data(void) { Tuplet style_tuple = TupletInteger(STYLE_KEY, 0); Tuplet bluetoothvibe_tuple = TupletInteger(BLUETOOTHVIBE_KEY, 0); Tuplet hourlyvibe_tuple = TupletInteger(HOURLYVIBE_KEY, 0); Tuplet blink_tuple = TupletInteger(BLINK_KEY, 0); Tuplet dateformat_tuple = TupletInteger(DATEFORMAT_KEY, 0); Tuplet units_tuple = TupletInteger(WEATHER_UNITS, 0); Tuplet weather_temperature_tuple = TupletInteger(WEATHER_TEMPERATURE_KEY, 0); Tuplet weather_icon_tuple = TupletInteger(WEATHER_ICON_KEY, 0); Tuplet weather_high_tuple = TupletInteger(WEATHER_TEMPERATUREHIGH_KEY, 0); Tuplet weather_low_tuple = TupletInteger(WEATHER_TEMPERATURELOW_KEY, 0); DictionaryIterator *iter; app_message_outbox_begin(&iter); if (iter == NULL) { return; } dict_write_tuplet(iter, &style_tuple); dict_write_tuplet(iter, &bluetoothvibe_tuple); dict_write_tuplet(iter, &hourlyvibe_tuple); dict_write_tuplet(iter, &units_tuple); dict_write_tuplet(iter, &weather_temperature_tuple); dict_write_tuplet(iter, &weather_icon_tuple); dict_write_tuplet(iter, &weather_high_tuple); dict_write_tuplet(iter, &weather_low_tuple); dict_write_tuplet(iter, &blink_tuple); dict_write_tuplet(iter, &dateformat_tuple); dict_write_end(iter); app_message_outbox_send(); }
void send_message(int status) { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_int8(iter, STATUS_KEY, status); dict_write_end(iter); app_message_outbox_send(); }
static void send_message() { APP_LOG(APP_LOG_LEVEL_DEBUG, "Got to sending message."); if (hint_layer) { text_layer_destroy(hint_layer); hint_layer = NULL; } else { DictionaryIterator *iter; app_message_outbox_begin(&iter); if (iter == NULL) { vibes_short_pulse(); APP_LOG(APP_LOG_LEVEL_WARNING, "Can not send request to phone!"); return; } dict_write_uint8(iter, MSG_KEY, message); dict_write_cstring(iter, TEXT1_KEY, s_last_text[0]); dict_write_cstring(iter, TEXT2_KEY, s_last_text[1]); dict_write_cstring(iter, TEXT3_KEY, s_last_text[2]); const uint32_t final_size = dict_write_end(iter); app_message_outbox_send(); APP_LOG(APP_LOG_LEVEL_DEBUG, "Sent message '%d' to phone! (%d bytes)", message, (int) final_size); if (!hint_layer) { Layer *window_layer = window_get_root_layer(window); hint_layer = text_layer_create(hint_layer_size); text_layer_set_font(hint_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(hint_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(hint_layer)); } snprintf(hint_text, sizeof(hint_text), "Sent\nmessage\n'%s'",label[message-1]); text_layer_set_text(hint_layer, hint_text); } }
static void pin_set_handler(ClickRecognizerRef recognizer, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Pin set"); if (hint_layer) { text_layer_destroy(hint_layer); hint_layer = NULL; } else { app_timer_reschedule(locationtimer, 1000 * (nextcall + 10)); strcpy(command, "pin"); DictionaryIterator *iter; app_message_outbox_begin(&iter); if (iter == NULL) { vibes_short_pulse(); APP_LOG(APP_LOG_LEVEL_WARNING, "Can not send command %s to phone!", command); return; } dict_write_cstring(iter, CMD_KEY, command); const uint32_t final_size = dict_write_end(iter); app_message_outbox_send(); APP_LOG(APP_LOG_LEVEL_DEBUG, "Sent command '%s' to phone! (%d bytes)", command, (int) final_size); if (!hint_layer) { Layer *window_layer = window_get_root_layer(window); hint_layer = text_layer_create(hint_layer_size); text_layer_set_font(hint_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(hint_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(hint_layer)); } text_layer_set_text(hint_layer, "\nSetting\ntimeline\npin..."); } }
static void select_click_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Got a click for row %d", cell_index->row); if (hint_layer) { text_layer_destroy(hint_layer); hint_layer = NULL; } if (cell_index->row > 0) { app_timer_reschedule(locationtimer, 1000 * (nextcall + 10)); if (cell_index->row == 1) { strcpy(command, "set"); text_layer_set_text(distance_layer, "0"); } else snprintf(command, sizeof(command), "set%d", (cell_index->row)-2); DictionaryIterator *iter; app_message_outbox_begin(&iter); if (iter == NULL) { vibes_short_pulse(); APP_LOG(APP_LOG_LEVEL_WARNING, "Can not send command %s to phone!", command); return; } dict_write_cstring(iter, CMD_KEY, command); const uint32_t final_size = dict_write_end(iter); app_message_outbox_send(); APP_LOG(APP_LOG_LEVEL_DEBUG, "Sent command '%s' to phone! (%d bytes)", command, (int) final_size); } window_stack_pop(animated); }
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 send_settings_to_phone() { if (!JS_ready) return; DictionaryIterator *iter; app_message_outbox_begin(&iter); int dummy_int; dict_write_cstring(iter, KEY_APP_VERSION, app_version); dummy_int=CURRENT_STORAGE_VERSION; dict_write_int(iter, KEY_VERSION, &dummy_int, sizeof(int), true); dummy_int=data_timestamp; dict_write_int(iter, KEY_TIMESTAMP, &dummy_int, sizeof(int), true); dummy_int=settings.Show_clock; dict_write_int(iter, KEY_SHOW_CLOCK, &dummy_int, sizeof(int), true); dummy_int=settings.Auto_sort; dict_write_int(iter, KEY_AUTO_SORT, &dummy_int, sizeof(int), true); dummy_int=settings.Hrs_day_x10; dict_write_int(iter, KEY_HRS_PER_DAY, &dummy_int, sizeof(int), true); dummy_int=settings.Last_reset; dict_write_int(iter, KEY_LAST_RESET, &dummy_int, sizeof(int), true); if (timer.Active) dict_write_data(iter, KEY_TIMER, (void*) &timer, sizeof(timer)); jobs_list_write_dict(iter, KEY_JOBS); if (export_after_save) { dummy_int=true; dict_write_int(iter, KEY_EXPORT, &dummy_int, sizeof(int), true); export_after_save=false; } dict_write_end(iter); LOG("sending outbox..."); app_message_outbox_send(); }
static void timer_callback(void *data) { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_METHOD, KEY_METHOD_READY); dict_write_end(iter); app_message_outbox_send(); }
static void http_capture_send_buffer() { int len = 64; if (http_capture_sentLen+len > 18*168) len = 18*168 - http_capture_sentLen; if (len <= 0) return; Tuplet start = TupletInteger(0xFFF9, http_capture_sentLen); Tuplet buf = TupletBytes(1000, &http_capture_frameBuffer[http_capture_sentLen], len); DictionaryIterator *iter; app_message_out_get(&iter); if (iter == NULL) return; dict_write_tuplet(iter, &start); dict_write_tuplet(iter, &buf); dict_write_end(iter); http_capture_sentLen += len; app_message_out_send(); app_message_out_release(); }
void sendScore(uint16_t score) { // Begin dictionary DictionaryIterator *iter; app_message_outbox_begin(&iter); // Add a key-value pair DictionaryResult result = dict_write_uint16(iter, 1, score); switch(result) { case DICT_OK: APP_LOG(APP_LOG_LEVEL_INFO, "nothing went wrong in message construction"); break; case DICT_INVALID_ARGS: case DICT_MALLOC_FAILED: case DICT_INTERNAL_INCONSISTENCY: case DICT_NOT_ENOUGH_STORAGE: default: APP_LOG(APP_LOG_LEVEL_INFO, "something went wrong in message construction"); break; } uint32_t size = dict_write_end(iter); APP_LOG(APP_LOG_LEVEL_INFO, "size of dictionary: %u", (unsigned int)size); // Send the message! app_message_outbox_send(); }
void read_presets() { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_CMD_EXECUTED,CMD_GET_PRESETS); dict_write_end(iter); app_message_outbox_send(); }
/** * Sends inbox size to phone as a * little-endian byte array of length 4. */ void broadcast_inbox_size(uint32_t size) { DictionaryIterator *dict; app_message_outbox_begin(&dict); dict_write_data(dict, INBOX_SIZE_KEY, (uint8_t *)&size, 4); dict_write_end(dict); app_message_outbox_send(); }
static void send_cmd(void) { DictionaryIterator *iter; app_message_outbox_begin(&iter); if (iter == NULL) { return; } static char *bgptr = last_bg; static char *bgptr2 = last_bg_2; static char *timeptr = new_time; static char *timeptr_2 = new_time_2; Tuplet alertval = TupletInteger(3, 0); Tuplet bgVal = TupletCString(1, bgptr); Tuplet bgVal2 = TupletCString(4, bgptr2); Tuplet lastTimeVal = TupletCString(2, timeptr); Tuplet lastTimeVal2 = TupletCString(6, timeptr_2); dict_write_tuplet(iter, &alertval); dict_write_tuplet(iter, &bgVal); dict_write_tuplet(iter, &bgVal2); dict_write_tuplet(iter, &lastTimeVal); dict_write_tuplet(iter, &lastTimeVal2); dict_write_end(iter); app_message_outbox_send(); }
static void down_click_handler(ClickRecognizerRef recognizer, void *context) { int raceRoundInt = atoi(raceRoundChar); // APP_LOG(APP_LOG_LEVEL_DEBUG, "raceRoundChar = %s", raceRoundChar); // APP_LOG(APP_LOG_LEVEL_DEBUG, "currently round %d", raceRoundInt); // APP_LOG(APP_LOG_LEVEL_DEBUG, "creating new round %d = current round+1", raceRoundInt + 1); text_layer_set_text(round_layer, "getting race"); raceRoundInt = raceRoundInt + 1; if (raceRoundInt > 19) { raceRoundInt = 19; APP_LOG(APP_LOG_LEVEL_DEBUG, "max round reached"); } //int i; char roundRequestChar[] = "123456"; snprintf(roundRequestChar, sizeof(roundRequestChar), "%d", raceRoundInt); // APP_LOG(APP_LOG_LEVEL_DEBUG, "race round string = %%s %s", roundRequestChar); //text_layer_set_text(&countLayer, buf); //Tuplet request_tuple = TupletCString(REQUEST_KEY, roundRequestChar); // Tuplet request_tuple; DictionaryIterator *iter; app_message_outbox_begin(&iter); if (iter == NULL) { return; } dict_write_cstring(iter, REQUEST_KEY, roundRequestChar); // dict_write_tuplet(iter, &request_tuple); dict_write_end(iter); app_message_outbox_send(); //send_message(); //fetch_msg(); }
void next_track() { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_CMD_EXECUTED,CMD_NEXT_TRACK); dict_write_end(iter); app_message_outbox_send(); }
void play_pause() { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_CMD_EXECUTED,CMD_PLAY_PAUSE); dict_write_end(iter); app_message_outbox_send(); }
void send_requestx(int slot, int command) { AppMessageResult result; DictionaryIterator *dict; result = app_message_outbox_begin(&dict); if (result == APP_MSG_OK) { dict_write_uint8(dict, slot, command); dict_write_end(dict); result = app_message_outbox_send(); if (result == APP_MSG_OK) { app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); } } else { current_slot = slot; current_command = command; if (command_timer == NULL) { command_timer = app_timer_register(250, handle_resend, NULL); } } }
void shut_off() { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_CMD_EXECUTED,CMD_SHUT_OFF); dict_write_end(iter); app_message_outbox_send(); }
static void in_received_handler(DictionaryIterator *iter, void *context) { Tuple *tuple; // send the launch_arg when we receive ready from JS tuple = dict_find(iter, APP_KEY_READY); if (tuple) { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint32(iter, APP_KEY_ACTION, launch_get_args()); dict_write_end(iter); app_message_outbox_send(); } // update text tuple = dict_find(iter, APP_KEY_TEXT); if (tuple) { snprintf(text, sizeof(text), "%s", tuple->value->cstring); text_layer_set_text(text_layer, text); } // quit the app tuple = dict_find(iter, APP_KEY_QUIT); if (tuple) { window_stack_pop_all(false); } }
void messsages_open_send() { // first register callbacks app_message_register_inbox_received(messages_inbox_received); app_message_register_inbox_dropped(messages_inbox_dropped); app_message_register_outbox_sent(messages_outbox_sent); app_message_register_outbox_failed(messages_outbox_failed); if (app_message_open(APP_MESSAGE_INBOX_SIZE_MINIMUM, APP_MESSAGE_OUTBOX_SIZE_MINIMUM) != APP_MSG_OK) { APP_LOG(APP_LOG_LEVEL_ERROR, "Open Message Failed"); return; } DictionaryIterator* dic_iterator; if (app_message_outbox_begin(&dic_iterator) != APP_MSG_OK) { APP_LOG(APP_LOG_LEVEL_ERROR, "Begin Message Outbox Failed"); return; } char buffer[50]; time_t now; time(&now); strftime(buffer, sizeof(buffer),"P: %H:%M %S", localtime(&now)); // write some data dict_write_cstring(dic_iterator, 1, buffer); dict_write_end(dic_iterator); // send app_message_outbox_send(); APP_LOG(APP_LOG_LEVEL_INFO,"Message %s sent",buffer); }
static void category_menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { switch (cell_index->row) { case 0: // Info Sessions info_sessions_window_push(); // Send AppMessage to get info sessions DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_GET_DATA, INFO_SESSION); dict_write_end(iter); app_message_outbox_send(); break; case 1: // Lunch Menus display_food_menus_action_menu(LUNCH_MENU); break; case 2: // Dinner Menus display_food_menus_action_menu(DINNER_MENU); break; } }
void request_weather(WeatherData *weather_data) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Request weather, retry: %i", retry_count); if (retry_count > MAX_RETRY) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Too many retries"); retry_count = 0; return; } if (!bluetooth_connection_service_peek()) { weather_data->error = WEATHER_E_DISCONNECTED; return; } DictionaryIterator *iter; app_message_outbox_begin(&iter); if (iter == NULL) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Null iter"); return; } dict_write_cstring(iter, KEY_SERVICE, weather_data->service); dict_write_cstring(iter, KEY_SCALE, weather_data->scale); dict_write_uint8(iter, KEY_DEBUG, (uint8_t)weather_data->debug); dict_write_uint8(iter, KEY_BATTERY, (uint8_t)weather_data->battery); dict_write_end(iter); app_message_outbox_send(); }
static bool app_msg_RequestLatLong_internal(void) { bool fMyRet = true; #if TESTING_DISABLE_LOCATION_REQUEST return true; #endif Tuplet fetch_tuple = TupletInteger(MSG_KEY_GET_LAT_LONG, 1); DictionaryIterator *iter; AppMessageResult amRet; amRet = app_message_outbox_begin(&iter); if (amRet != APP_MSG_OK) { APP_LOG(APP_LOG_LEVEL_DEBUG, "app_message_outbox_begin failed, ret = %04X", amRet); return false; } if (iter == NULL) { APP_LOG(APP_LOG_LEVEL_DEBUG, "app_message_outbox_begin returned null iter"); return false; } DictionaryResult dRet; dRet = dict_write_tuplet(iter, &fetch_tuple); if (dRet != DICT_OK) { APP_LOG(APP_LOG_LEVEL_DEBUG, "dict_write_tuplet failed, ret = %04X", dRet); fMyRet = false; // fall through to call end anyway } unsigned uRet; uRet = dict_write_end(iter); if (uRet == 0) { fMyRet = false; } if (fMyRet) { amRet = app_message_outbox_send(); if (amRet != APP_MSG_OK) { APP_LOG(APP_LOG_LEVEL_DEBUG, "app_message_outbox_send failed, ret = %04X", amRet); fMyRet = false; } } return fMyRet; } /* end of app_msg_RequestLatLong_internal(void) */
void read_volume() { APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE,"read_volume"); DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_CMD_EXECUTED,CMD_GET_VOLUME); dict_write_end(iter); app_message_outbox_send(); }
void send_request(char *request){ Tuplet request_tuple = TupletCString(DATA, request); DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_tuplet(iter, &request_tuple); dict_write_end(iter); app_message_outbox_send(); }
static void select_single_click_handler(ClickRecognizerRef recognizer, void *window) { // App Messages can be sent while using Pebble Autoconfig DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_cstring(iter, PING_KEY, "Knock, knock!"); dict_write_end(iter); app_message_outbox_send(); }
void read_now_playing() { APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE,"read_now_playing"); DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_CMD_EXECUTED,CMD_GET_NOW_PLAYING); dict_write_end(iter); app_message_outbox_send(); }
void players_request() { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, APP_KEY_METHOD, KEY_METHOD_REQUESTPLAYERS); dict_write_end(iter); app_message_outbox_send(); players_reload_data_and_mark_dirty(); }
void push_button(int buttonId) { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, KEY_CMD_EXECUTED, CMD_PUSH_BUTTON); dict_write_uint8(iter, KEY_BUTTON_ID, buttonId); dict_write_end(iter); app_message_outbox_send(); }
void send_outgoing_message() { if (iter == NULL) { return; } dict_write_end(iter); app_message_outbox_send(); }