コード例 #1
0
void send_protocol_message(ticket_protocol *prt) {
    DictionaryIterator *iterator;

    app_message_outbox_begin(&iterator);

    int8_t value = PROTOCOL_STATE_RUNNING;
    dict_write_int8(iterator, HANDSHAKE_KEY, value);
    dict_write_int8(iterator, SECTION_OFFSET_KEY, prt->curr_section);
    dict_write_int8(iterator, TICKET_OFFSET_KEY, prt->curr_ticket);

    app_message_outbox_send();
}
コード例 #2
0
ファイル: send_message.c プロジェクト: TurplePurtle/PCRemote
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();
}
コード例 #3
0
HTTPResult http_out_get(const char* url, bool use_post, int32_t cookie, DictionaryIterator **iter_out) {
	AppMessageResult app_result = app_message_out_get(iter_out);
	if(app_result != APP_MSG_OK) {
		return app_result;
	}
	DictionaryResult dict_result = dict_write_cstring(*iter_out, HTTP_URL_KEY, url);
	if(dict_result != DICT_OK) {
		return dict_result << 12;
	}
	dict_result = dict_write_int32(*iter_out, HTTP_COOKIE_KEY, cookie);
	if(dict_result != DICT_OK) {
		return dict_result << 12;
	}
	dict_result = dict_write_int32(*iter_out, HTTP_APP_ID_KEY, our_app_id);
	if(dict_result != DICT_OK) {
		return dict_result << 12;
	}
	if(!use_post) {
		dict_result = dict_write_int8(*iter_out, HTTP_USE_GET_KEY, 1);
		if(dict_result != DICT_OK) {
			return dict_result << 12;
		}
	}
	return HTTP_OK;
}
コード例 #4
0
void sendCommandInt(int key, int param) {
	DictionaryIterator* iterout;
	sm_message_out_get(&iterout);
    if(!iterout) return;
	
	dict_write_int8(iterout, key, param);
	app_message_outbox_send();
}
コード例 #5
0
ファイル: main.c プロジェクト: mntnorv/overload
void handle_get_settings() {
  const uint8_t key_count = 1;
  DictionaryIterator *iter;

  app_message_outbox_begin(&iter);
  dict_write_int8(iter, KEY_COLOR, config_color);
  app_message_outbox_send();
}
コード例 #6
0
ファイル: go.c プロジェクト: rakusan2/PebbleToPhoton
static void transmit_to_phone(){
  DictionaryIterator *iterator;
  app_message_outbox_begin(&iterator);
  dict_write_int16(iterator, 0, x);
  dict_write_int16(iterator, 1, y);
  dict_write_int8(iterator, 2, 0); //TCP_Ready
  if(app_message_outbox_send()==APP_MSG_BUSY)delay++;
  else if(delay>0) delay--;
}
コード例 #7
0
ファイル: calendar.c プロジェクト: ShaBP/Revolution-Calendar
/*
 * Make a calendar request
 */
void calendar_request(DictionaryIterator *iter) {
  dict_write_int8(iter, REQUEST_CALENDAR_KEY, -1);
  dict_write_uint8(iter, CLOCK_STYLE_KEY, CLOCK_STYLE_24H);
  count = 0;
  received_rows = 0;
  calendar_request_outstanding = true;
  app_message_outbox_send();
  set_event_status(STATUS_REQUEST);
}
コード例 #8
0
ファイル: simply_msg.c プロジェクト: ericmigi/simplyjs-1
bool simply_msg_accel_tap(AccelAxisType axis, int32_t direction) {
  DictionaryIterator *iter = NULL;
  if (app_message_outbox_begin(&iter) != APP_MSG_OK) {
    return false;
  }
  dict_write_uint8(iter, 0, SimplyACmd_accelTap);
  dict_write_uint8(iter, 1, axis);
  dict_write_int8(iter, 2, direction);
  return (app_message_outbox_send() == APP_MSG_OK);
}
コード例 #9
0
/*
 * Make a calendar request
 */
void calendar_request(DictionaryIterator *iter) {
  dict_write_int8(iter, REQUEST_CALENDAR_KEY, -1);
  uint8_t clock_style = clock_is_24h_style() ? CLOCK_STYLE_24H : CLOCK_STYLE_12H;
  dict_write_uint8(iter, CLOCK_STYLE_KEY, clock_style);
  bt_status(false);
  count = 0;
  received_rows = 0;
  calendar_request_outstanding = true;
  app_message_out_send();
  app_message_out_release();
}
コード例 #10
0
ファイル: menu.c プロジェクト: nmittu/MNotes
void long_selected(MenuLayer *menu_layer, MenuIndex *cell_index, void *data){
	window_stack_pop(true);
	splash_init("Downloading");
	splash_show(true);
	
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	
	dict_write_int8(iter, TYPE, 1);
	
	dict_write_end(iter);
	app_message_outbox_send();
}
コード例 #11
0
ファイル: menu.c プロジェクト: nmittu/MNotes
void selected(MenuLayer *menu_layer, MenuIndex *cell_index, void *data){
	splash_init("Downloading");
	splash_show(true);
	
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	
	dict_write_cstring(iter, TITLE, titles[cell_index->row]);
	dict_write_int8(iter, TYPE, 0);
	
	dict_write_end(iter);
	app_message_outbox_send();
}
コード例 #12
0
ファイル: refuge.c プロジェクト: cat-haines/refuge-for-pebble
static void on_app_ready(void* context) {
  if (current_window == splash_window_get_base(splash_window)) {
    // Send appReady msg back to JS
    DictionaryIterator *iterator;
    app_message_outbox_begin(&iterator);
    dict_write_int8(iterator, MSG_APP_READY, 1);
    app_message_outbox_send();

    // This is a bad thing to do, don't do this...
    app_message_set_context(menu_window_get_base(menu_window));
    app_message_register_inbox_received(base_window_get_inbox_handler(menu_window_get_base(menu_window)));
  }
}
コード例 #13
0
ファイル: calendar.c プロジェクト: falkobuttler/diaryface20
/*
 * Make a calendar request
 */
void calendar_request() {

  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  if (!iter) 
	return;
		
  dict_write_int8(iter, REQUEST_CALENDAR_KEY, -1);
  dict_write_uint8(iter, CLOCK_STYLE_KEY, CLOCK_STYLE_24H);
  dict_write_end(iter);
  g_count = 0;
  g_received_rows = 0;
  app_message_outbox_send();
  set_status(STATUS_REQUEST);
}
コード例 #14
0
void start_protocol(ticket_protocol *prt) {

    DictionaryIterator *iterator;

    app_message_outbox_begin(&iterator);

    int8_t value = PROTOCOL_STATE_INIT;
    dict_write_int8(iterator, HANDSHAKE_KEY, value);

    prt->state = RUNNING;

    if (prt->sections != NULL) {
        free(prt->sections);
    }

    app_message_outbox_send();
}
コード例 #15
0
void handle_minute_tick(struct tm *tick_time, TimeUnits units_changed) {
  // Need to be static because they're used by the system later.
  static char time_text[] = "00:00";
  static char date_text[] = "Xxxxxxxxx 00";

  char *time_format;

  // TODO: Only update the date when it's changed.
  strftime(date_text, sizeof(date_text), "%B %e", tick_time);
  text_layer_set_text(text_date_layer, date_text);

  if (clock_is_24h_style()) {
    time_format = "%R";
  } else {
    time_format = "%I:%M";
  }

  strftime(time_text, sizeof(time_text), time_format, tick_time);

  // Kludge to handle lack of non-padded hour format string
  // for twelve hour clock.
  if (!clock_is_24h_style() && (time_text[0] == '0')) {
    memmove(time_text, &time_text[1], sizeof(time_text) - 1);
  }

  text_layer_set_text(text_time_layer, time_text);

  if (tick_time->tm_min % 10 == 0) {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    if (!iter) return;
    dict_write_int8(iter, REQUEST_CALENDAR_KEY, 0);
    uint8_t clock_style = clock_is_24h_style() ? CLOCK_STYLE_24H : CLOCK_STYLE_12H;
    dict_write_uint8(iter, CLOCK_STYLE_KEY, clock_style);
    app_message_outbox_send();

    app_timer_register(1000, &handle_timer, NULL);
  }
}
コード例 #16
0
void received_message(DictionaryIterator *received, void *context) {
  Tuple *tuple = dict_find(received, RECONNECT_KEY);

  if (tuple) {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    if (!iter) return;
    dict_write_int8(iter, REQUEST_CALENDAR_KEY, 0);
    uint8_t clock_style = clock_is_24h_style() ? CLOCK_STYLE_24H : CLOCK_STYLE_12H;
    dict_write_uint8(iter, CLOCK_STYLE_KEY, clock_style);
    app_message_outbox_send();

    app_timer_register(1000, &handle_timer, NULL);
  } else {
    Tuple *tuple = dict_find(received, CALENDAR_RESPONSE_KEY);

    if (tuple) {
      if (tuple->length % sizeof(Event) == 1) {
        uint8_t count = tuple->value->data[0];

        if (count == 1) {
          memcpy(&event, &tuple->value->data[1], sizeof(Event));

          text_layer_set_text(text_event_title_layer, event.title);
          text_layer_set_text(text_event_start_date_layer, event.start_date);
          text_layer_set_text(text_event_location_layer, event.has_location ? event.location : "");
        }
      }
    } else {
      Tuple *tuple = dict_find(received, BATTERY_RESPONSE_KEY);

      if (tuple) {
        memcpy(&battery_status, &tuple->value->data[0], sizeof(BatteryStatus));
        layer_mark_dirty(battery_layer);
      }
    }
  }
}
コード例 #17
0
static void send_batch(){
	if(!has_stored_data()){
		sending = false;
		return;
	}
	sending = true;

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_int8(iterator, KEY_COMMAND, COMMAND_DATA);
	
	unsigned int batch[CFG_BATCH_SIZE];
	get_batch_from_store(batch);
	for(uint sample = 0; sample < CFG_BATCH_SIZE; sample++){
		/*
		VERTICAL ACCELERATION = 0
		+1 is added to ensure that 0 is always the command.
		*/
		Tuplet t = TupletInteger(NUMBER_PARAMETERS * sample + 0 + 1, batch[sample]);
		dict_write_tuplet(iterator, &t);
	}
	app_message_outbox_send();
}
コード例 #18
0
void init() {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  text_date_layer = text_layer_create(GRect(8, 94, 144-8, 168-94));
  text_layer_set_text_color(text_date_layer, GColorWhite);
  text_layer_set_background_color(text_date_layer, GColorClear);
  text_layer_set_font(text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_date_layer));

  text_time_layer = text_layer_create(GRect(7, 112, 144-7, 168-112));
  text_layer_set_text_color(text_time_layer, GColorWhite);
  text_layer_set_background_color(text_time_layer, GColorClear);
  text_layer_set_font(text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_time_layer));

  line_layer = layer_create(layer_get_bounds(window_get_root_layer(window)));
  layer_set_update_proc(line_layer, line_layer_update_callback);
  layer_add_child(window_get_root_layer(window), line_layer);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);

  // TODO: Update display here to avoid blank display on launch?

  text_event_title_layer = text_layer_create(GRect(5, 18, layer_get_bounds(window_get_root_layer(window)).size.w - 10, 21));
  text_layer_set_text_color(text_event_title_layer, GColorWhite);
  text_layer_set_background_color(text_event_title_layer, GColorClear);
  text_layer_set_font(text_event_title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_event_title_layer));

  text_event_start_date_layer = text_layer_create(GRect(5, 36, layer_get_bounds(window_get_root_layer(window)).size.w - 10, 21));
  text_layer_set_text_color(text_event_start_date_layer, GColorWhite);
  text_layer_set_background_color(text_event_start_date_layer, GColorClear);
  text_layer_set_font(text_event_start_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_event_start_date_layer));

  text_event_location_layer = text_layer_create(GRect(5, 54, layer_get_bounds(window_get_root_layer(window)).size.w - 10, 21));
  text_layer_set_text_color(text_event_location_layer, GColorWhite);
  text_layer_set_background_color(text_event_location_layer, GColorClear);
  text_layer_set_font(text_event_location_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_event_location_layer));

  icon_battery = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_ICON);

  GRect frame;
  frame.origin.x = layer_get_bounds(window_get_root_layer(window)).size.w - 66;
  frame.origin.y = 6;
  frame.size.w = 59;
  frame.size.h = 12;

  battery_layer = layer_create(frame);
  layer_set_update_proc(battery_layer, battery_layer_update_callback);
  layer_add_child(window_get_root_layer(window), battery_layer);

  battery_status.state = 0;
  battery_status.level = -1;

  app_message_open(124, 256);
  app_message_register_inbox_received(received_message);

  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  if (!iter) return;
  dict_write_int8(iter, REQUEST_CALENDAR_KEY, 0);
  uint8_t clock_style = clock_is_24h_style() ? CLOCK_STYLE_24H : CLOCK_STYLE_12H;
  dict_write_uint8(iter, CLOCK_STYLE_KEY, clock_style);
  app_message_outbox_send();

  app_timer_register(1000, &handle_timer, NULL);
}
コード例 #19
0
ファイル: HelloWatchApp.c プロジェクト: jamesmattis/Hello
static void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context)
{
    // Log Error
    
    time_t now = time(NULL);
    struct tm *clock_time = localtime(&now);
    
    char error_time_text[] = "00:00:00";
    
    strftime(error_time_text, sizeof(error_time_text), "%T", clock_time);
    
    if (reason == APP_MSG_OK)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_OK", error_time_text);
    }
    else if (reason == APP_MSG_SEND_TIMEOUT)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_SEND_TIMEOUT", error_time_text);
    }
    else if (reason == APP_MSG_SEND_REJECTED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_SEND_REJECTED", error_time_text);
    }
    else if (reason == APP_MSG_NOT_CONNECTED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_NOT_CONNECTED", error_time_text);
    }
    else if (reason == APP_MSG_APP_NOT_RUNNING)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_APP_NOT_RUNNING", error_time_text);
    }
    else if (reason == APP_MSG_INVALID_ARGS)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_INVALID_ARGS", error_time_text);
    }
    else if (reason == APP_MSG_BUSY)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_BUSY", error_time_text);
    }
    else if (reason == APP_MSG_BUFFER_OVERFLOW)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_BUFFER_OVERFLOW", error_time_text);
    }
    else if (reason == APP_MSG_ALREADY_RELEASED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_ALREADY_RELEASED", error_time_text);
    }
    else if (reason == APP_MSG_CALLBACK_ALREADY_REGISTERED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_CALLBACK_ALREADY_REGISTERED", error_time_text);
    }
    else if (reason == APP_MSG_CALLBACK_NOT_REGISTERED)
    {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "[%s] App Message out_failed_handler: APP_MSG_CALLBACK_NOT_REGISTERED", error_time_text);
    }
    
    // Error Handling
    
    if ((reason == APP_MSG_SEND_TIMEOUT || reason == APP_MSG_BUSY) && bluetooth_connection_service_peek())
    {
        // Try Reseanding Message
        
        // Create New Output Iterator
        
        DictionaryIterator *iterator;
        
        if (app_message_outbox_begin(&iterator) != APP_MSG_OK)
        {
            return;
        }
        
        // For Each Tuple in Failed Dictionary Iterator, Read Value, Classify Value, and Write to New Iterator
        
        Tuple *tuple = dict_read_first(failed);
        
        while (tuple)
        {
            switch (tuple->type)
            {
                case TUPLE_BYTE_ARRAY:
                    dict_write_data	(iterator, tuple->key, tuple->value->data, tuple->length);
                    break;
                case TUPLE_CSTRING:
                    dict_write_cstring(iterator, tuple->key, tuple->value->cstring);
                    break;
                case TUPLE_UINT:
                    if (tuple->length == 1)
                    {
                        dict_write_uint8(iterator, tuple->key, tuple->value->uint8);
                    }
                    else if (tuple->length == 2)
                    {
                        dict_write_uint16(iterator, tuple->key, tuple->value->uint16);
                    }
                    else
                    {
                        dict_write_uint32(iterator, tuple->key, tuple->value->uint32);
                    }
                    break;
                case TUPLE_INT:
                    if (tuple->length == 1)
                    {
                        dict_write_int8(iterator, tuple->key, tuple->value->int8);
                    }
                    else if (tuple->length == 2)
                    {
                        dict_write_int16(iterator, tuple->key, tuple->value->int16);
                    }
                    else
                    {
                        dict_write_int32(iterator, tuple->key, tuple->value->int32);
                    }
                    break;
                default:
                    break;
            }
            
            tuple = dict_read_next(failed);
        }
        
        // Resend App Message
        
        app_message_outbox_send();
    }
}