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 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(); }
// Data Request // Params- char*:request (location/update/lastStopRequest) static void requestData(char *request) { time(&lastUpdate); DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_cstring(iter, 45, request); app_message_outbox_send(); }
void reset_sequence_number() { DictionaryIterator *iter = NULL; app_message_outbox_begin(&iter); if(!iter) return; dict_write_int32(iter, SM_SEQUENCE_NUMBER_KEY, 0xFFFFFFFF); app_message_outbox_send(); }
// omain init - registers callback functions, reads persistent data, and requests most recent data from // companion app. Sets default timer length to 10 seconds. void main_init(void) { s_reset_app(NULL); // initialize app message app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); // send request for most recent data DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, 0, 42); app_message_outbox_send(); // gather persistent data for timer length and passcode if (persist_exists(TIMERLEN_PERSIST_KEY)) { s_timer_len = persist_read_int(TIMERLEN_PERSIST_KEY); } else { s_timer_len = 10*1000; } if (persist_exists(PASSCODE_PERSIST_KEY)) { s_passcode_defined = true; persist_read_string(PASSCODE_PERSIST_KEY, s_passcode, PASSCODE_LEN + 1); } else { s_passcode_defined = false; } }
static void app_focus_handler(bool in_focus) { // Send App Message Out DictionaryIterator *iterator; if (app_message_outbox_begin(&iterator) != APP_MSG_OK) { return; } if (in_focus) { if (dict_write_cstring(iterator, MESSAGE_KEY, "IN FOCUS") != DICT_OK) { return; } } else { if (dict_write_cstring(iterator, MESSAGE_KEY, "NOT IN FOCUS") != DICT_OK) { return; } } 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(); }
// Menu callback void select_menu_callback(int index, void *context) { app_message_outbox_begin(&iter); static char* select_action; if (strcmp(menu_action, "c") == 0) { select_action = "selClient"; } else if(strcmp(menu_action, "t") == 0) { select_action = "selTask"; snprintf(task_title, 40, "Task:\n%s", list_menu_items[index].title); text_layer_set_text(task_layer, task_title); } else if (strcmp(menu_action, "p") == 0) { select_action = "selProj"; snprintf(project_title, 40, "Project:\n%s", list_menu_items[index].title); text_layer_set_text(task_layer, project_title); } else { // strcmp failed to find a match APP_LOG(APP_LOG_LEVEL_DEBUG, "No match on strcmp, value of menu_action follows"); APP_LOG(APP_LOG_LEVEL_DEBUG, menu_action); } Tuplet action_type = TupletCString(0, select_action); dict_write_tuplet(iter, &action_type); Tuplet selected = TupletInteger(1, index); dict_write_tuplet(iter, &selected); app_message_outbox_send(); // this send is causing crash :S //pop the menu off window_stack_pop(true); }
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(); }
void option_picked(int index, void* context) { DictionaryIterator *iterator; app_message_outbox_begin(&iterator); if(index == 0){ if (vibrateEnabledStatus == 1){ vibrateEnabledStatus = 0; } else { vibrateEnabledStatus = 1; } dict_write_uint8(iterator, 0, 10); dict_write_uint8(iterator, 1, vibrateEnabledStatus); } else if(index == 1){ if (inverterEnabledStatus == 1){ dict_write_uint8(iterator, 0, 11); dict_write_uint8(iterator, 1, 0); } else { dict_write_uint8(iterator, 0, 11); dict_write_uint8(iterator, 1, 1); } } app_message_outbox_send(); app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL); }
uint8_t getLight(Light *light, GetLightCallback callback) { DictionaryIterator *iter = NULL; AppMessageResult result = app_message_outbox_begin(&iter); if (result != APP_MSG_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result); return false; } DictionaryResult result2 = dict_write_data(iter, TAG_LIGHT, (uint8_t *)light, sizeof(Light)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send data, status %d", result2); return false; } uint16_t r = REQUEST_GET; result2 = dict_write_data(iter, TAG_REQUEST_TYPE, (uint8_t *)&r, sizeof(uint16_t)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result2); return false; } result2 = dict_write_data(iter, TAG_ADDRESS, (uint8_t *)&light, sizeof(Light *)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result2); return false; } result2 = dict_write_data(iter, TAG_CALLBACK, (uint8_t *)&callback, sizeof(GetLightCallback)); if (result2 != DICT_OK) { app_log(APP_LOG_LEVEL_WARNING, __FILE__, __LINE__, ",unable to send request, status %d", result2); return false; } app_message_outbox_send(); return true; }
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); } } }
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 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..."); } }
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 request_from_phone() { // Declare the dictionary's iterator DictionaryIterator *out_iter; // Prepare the outbox buffer for this message AppMessageResult result = app_message_outbox_begin(&out_iter); if (result == APP_MSG_OK) { // A dummy value int value = 0; // Add an item to ask for weather data dict_write_int(out_iter, MESSAGE_KEY_phone_battery, &value, sizeof(int), true); } else { // The outbox cannot be used right now APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result); } // Send this message result = app_message_outbox_send(); // Check the result if (result != APP_MSG_OK) { APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result); } }
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(); }
void appmessagecontroller_sendMessage( int key, int value ) { DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint8(iter, key, value); 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(); }
static void select_click_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { switch(cell_index->row){ case 0: finish_init(); DictionaryIterator *iter; app_message_outbox_begin(&iter); char * phone_num = (char*)malloc(11 * sizeof(char)); phone_num[0] = cont_num[0]; phone_num[1] = cont_num[1]; phone_num[2] = cont_num[2]; phone_num[3] = cont_num[4]; phone_num[4] = cont_num[5]; phone_num[5] = cont_num[6]; phone_num[6] = cont_num[8]; phone_num[7] = cont_num[9]; phone_num[8] = cont_num[10]; phone_num[9] = cont_num[11]; phone_num[10] = '\0'; Tuplet value = TupletCString(1, phone_num); dict_write_tuplet(iter, &value); int number = (int)(amount * 10); dict_write_int(iter, 2, &number, sizeof(int), 0); app_message_outbox_send(); break; case 1: amount = 0; was_back = 1; show_home(); break; } }
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(); }
int main() { app_message_register_outbox_sent(data_delivered); app_message_register_inbox_received(received_data); app_message_open(124, 50); DictionaryIterator *iterator; app_message_outbox_begin(&iterator); dict_write_uint8(iterator, 0, 0); dict_write_uint8(iterator, 1, 0); dict_write_uint16(iterator, 2, PROTOCOL_VERSION); #ifdef PBL_PLATFORM_APLITE dict_write_uint8(iterator, 3, 0); #else dict_write_uint8(iterator, 3, 1); #endif app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); app_message_outbox_send(); switchWindow(0); app_event_loop(); window_stack_pop_all(false); return 0; }
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); }
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(); }
void messaging_requestNewWeatherData() { // just send an empty message for now DictionaryIterator *iter; app_message_outbox_begin(&iter); dict_write_uint32(iter, 0, 0); app_message_outbox_send(); }
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(); }
// Next or previous void go_next_or_prev(uint8_t key, uint8_t cmd){ if (current == -1 || max == -1){ //Not all data has been received, unable to determine if you can go next/prev return; } if (current == 1 && cmd == BUTTON_PREVIOUS){ //First already, cannot prev, exit return; } if (current == max && cmd == BUTTON_NEXT){ //Last in list, exit return; } resetData(); if (debugMode) APP_LOG(APP_LOG_LEVEL_INFO, "Sending data to phone"); DictionaryIterator *iter; app_message_outbox_begin(&iter); Tuplet value = TupletInteger(key, cmd); dict_write_tuplet(iter, &value); if (current != -1){ Tuplet page = TupletInteger(MESSAGE_CURRENT_FAV, current); dict_write_tuplet(iter, &page); } app_message_outbox_send(); }
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(); }
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; } }
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); } }