Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
static void update_time() {
  // Get a tm structure
  time_t temp = time(NULL); 
  struct tm *tick_time = localtime(&temp);

  // Create a long-lived buffer
  static char buffer[] = "00:00";

  // Write the current hours and minutes into the buffer
  if(clock_is_24h_style() == true) {
    // Use 24 hour format
    strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);
  } else {
    // Use 12 hour format
    strftime(buffer, sizeof("00:00"), "%I:%M", tick_time);
  }

  // Display this time on the TextLayer
  text_layer_set_text(s_time_layer, buffer);

  // Get weather update every 30 minutes
  if(tick_time->tm_min % 30 == 0) {
    // Begin dictionary
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);

    // Add a key-value pair
    dict_write_uint8(iter, 0, 0);
    dict_write_uint8(iter, 1, 1);

    // Send the message!
    app_message_outbox_send();
  }
}
Ejemplo n.º 4
0
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();
}
Ejemplo n.º 5
0
void change_volume() {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    dict_write_uint8(iter, KEY_CMD_EXECUTED,CMD_SET_VOLUME);
    dict_write_uint8(iter, KEY_NEW_VOLUME,volume);
    dict_write_end(iter);
    app_message_outbox_send();
    win_now_playing_refresh_data();
}
Ejemplo n.º 6
0
bool simply_msg_long_click(ButtonId button) {
  DictionaryIterator *iter = NULL;
  if (app_message_outbox_begin(&iter) != APP_MSG_OK) {
    return false;
  }
  dict_write_uint8(iter, 0, SimplyACmd_longClick);
  dict_write_uint8(iter, 1, button);
  return (app_message_outbox_send() == APP_MSG_OK);
}
Ejemplo n.º 7
0
// Write message to buffer & send
void send_message(void){
	DictionaryIterator *iter;
	
	app_message_outbox_begin(&iter);
	dict_write_uint8(iter, STATUS_KEY, 0x1);
  dict_write_uint8(iter, GET_UPDATE_KEY, 0x2);
	
	dict_write_end(iter);
  	app_message_outbox_send();
}
Ejemplo n.º 8
0
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);
}
static void send_initial_packet() {
	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);
	dict_write_uint32(iterator, 3, getCapabilities(appmessage_max_size));

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();
}
Ejemplo n.º 10
0
static void requestNumbers(uint16_t pos)
{
	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 2);
	dict_write_uint8(iterator, 1, 0);
	dict_write_uint16(iterator, 2, pos);

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();
}
Ejemplo n.º 11
0
// Write message to buffer & send
void send_message(int d)
{
	DictionaryIterator *iter;
	
	app_message_outbox_begin(&iter);
	dict_write_uint8(iter, STATUS_KEY, 0x1);
     dict_write_uint8(iter, MESSAGE_KEY, d);

     dict_write_end(iter);
     app_message_outbox_send();
}
Ejemplo n.º 12
0
void closeApp(void)
{
	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);
	dict_write_uint8(iterator, 0, 0);
	dict_write_uint8(iterator, 1, 2);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_message_outbox_send();

	closingMode = true;
}
Ejemplo n.º 13
0
void sendAction(int buttonId)
{
    DictionaryIterator *iterator;
    app_message_outbox_begin(&iterator);

    dict_write_uint8(iterator, 0, 7);
    dict_write_uint8(iterator, 1, buttonId);

    app_message_outbox_send();

    busy = true;
    vibes_cancel();
}
void menu_picked(int index, void* context)
{
	show_loading();

	DictionaryIterator *iterator;
	app_message_outbox_begin(&iterator);

	dict_write_uint8(iterator, 0, 6);
	dict_write_uint8(iterator, 1, index);

	app_message_outbox_send();

	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_NORMAL);
}
Ejemplo n.º 15
0
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();
}
Ejemplo n.º 16
0
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);   
  }
}
Ejemplo n.º 17
0
// TIME-RECURSIVE FUNCTIONS
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  // UPDATED THE TIME AND DATE
  update_time();
  
  // CALCULATES PEBBLE UPTIME
  // Use a long-lived buffer
  static char s_uptime_buffer[32];

  // Get time since launch
  int seconds = s_uptime % 60;
  int minutes = (s_uptime % 3600) / 60;
  int hours = s_uptime / 3600;

  // Update the TextLayer
  snprintf(s_uptime_buffer, sizeof(s_uptime_buffer), "LOG UPTIME: %dh %dm %ds", hours, minutes, seconds);
  text_layer_set_text(s_uptime_layer, s_uptime_buffer);
  
  // Increment s_uptime
  s_uptime++;
  
  // Get weather updates every 30 minutes
  if(tick_time->tm_min % 30 == 0) {
    // Begin dictionary
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);

    // Add a key-value pair
    dict_write_uint8(iter, 0, 0);

    // Send the message!
    app_message_outbox_send();
  }
}
Ejemplo n.º 18
0
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;
  }
}
Ejemplo n.º 19
0
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);
		}
	}
}
Ejemplo n.º 20
0
// 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;
  }
}
Ejemplo n.º 21
0
Archivo: light.c Proyecto: Neal/OpalX
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();
}
Ejemplo n.º 22
0
static void get_weather() {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    dict_write_uint8(iter, JS_KEY_IS_MINUTELY, settings.is_minutely);
    dict_write_cstring(iter, JS_KEY_API_KEY, settings.api_key);
    app_message_outbox_send();
}
Ejemplo n.º 23
0
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();
}
Ejemplo n.º 24
0
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();
}
Ejemplo n.º 25
0
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();
}
void appmessagecontroller_sendMessage( int key, int value )
{
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_uint8(iter, key, value);
  app_message_outbox_send();
}
Ejemplo n.º 27
0
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();
}
Ejemplo n.º 28
0
static void update_travel_time() {
  // Prepare dictionary
  DictionaryIterator *iterator;
  app_message_outbox_begin(&iterator);
  dict_write_uint8(iterator, 0, 0);
  // Send the message!
  app_message_outbox_send();
}
Ejemplo n.º 29
0
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();
}
Ejemplo n.º 30
0
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();
}