Exemple #1
0
/*
 * Tick-Handler - executes once every second using watch's internal clock.
 * Switched every other second between getting most recent temp (if desired) and checking for tripped alarm.
 */
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  if (tickTimerMod % 2 == 0){
      if (wantAverage && !standbyEngaged && !tripped){
        DictionaryIterator *iter;
        app_message_outbox_begin(&iter);
        int key = 0;
        // send the message "b" to the phone, using key #0
        Tuplet value = TupletCString(key, "b");
        dict_write_tuplet(iter, &value);
        app_message_outbox_send();
      }
  }
  else{
      //checks if alarm has been tripped, checks to see every 10 seconds if not
      if (tripped){
          text_layer_set_text(hello_layer, "INTRUDER ALERT!!!");
          vibes_double_pulse();
      }
      else { 
          DictionaryIterator *iter;
          app_message_outbox_begin(&iter);
          int key = 0;
          // send the message "t" to the phone, using key #0
          Tuplet value = TupletCString(key, "t");
          dict_write_tuplet(iter, &value);
          app_message_outbox_send();
      }
  }
  tickTimerMod += 1;
}
Exemple #2
0
/* Setup app message callbacks for weather */
void qtp_setup_app_message() {
#ifdef QTP_DEBUG
	APP_LOG(APP_LOG_LEVEL_DEBUG, "QTP: setting app message for weather");
#endif

	const int inbound_size = 100;
	const int outbound_size = 100;
	app_message_open(inbound_size, outbound_size);
	Tuplet initial_values[] = {
		TupletInteger(QTP_WEATHER_ICON_KEY, (uint8_t) 8),
		TupletCString(QTP_WEATHER_TEMP_F_KEY, "---\u00B0F"),
		TupletCString(QTP_WEATHER_TEMP_C_KEY, "---\u00B0F"),
		TupletCString(QTP_WEATHER_CITY_KEY, "Atlanta      "),
		TupletCString(QTP_WEATHER_DESC_KEY, "                       ")
	};
#ifdef QTP_DEBUG
	APP_LOG(APP_LOG_LEVEL_DEBUG, "QTP: weather tuples intialized");
#endif

	app_sync_init(&qtp_sync, qtp_sync_buffer, sizeof(qtp_sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
	  qtp_sync_changed_callback, qtp_sync_error_callback, NULL);
#ifdef QTP_DEBUG
	APP_LOG(APP_LOG_LEVEL_DEBUG, "QTP: weather app message initialized");
#endif

}
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();

}
Exemple #4
0
/* 
 * Responds to double up button clicks. When !tripped, asks the server to put the Arduino in
 * or out of standby mode and records it. When tripped, resets the alarm on the server and Arduino.
 */
void up_double_click_handler(ClickRecognizerRef recognizer, void *context) {
  if (!tripped){
      standbyEngaged = !standbyEngaged;
      wantAverage = 0;
      //text_layer_set_text(hello_layer, "UP!");
      DictionaryIterator *iter;
      app_message_outbox_begin(&iter);
      int key = 0;
      // send the message "hello?" to the phone, using key #0
      Tuplet value = TupletCString(key, "s");
      dict_write_tuplet(iter, &value);
      app_message_outbox_send();
  }
  else {
      tripped = 0;
      //text_layer_set_text(hello_layer, "UP!");
      DictionaryIterator *iter;
      app_message_outbox_begin(&iter);
      int key = 0;
      // send the message "hello?" to the phone, using key #0
      Tuplet value = TupletCString(key, "r");
      dict_write_tuplet(iter, &value);
      app_message_outbox_send();
  }
}
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);

  icon_layer = bitmap_layer_create(GRect(12, -5, 120, 120));
  layer_add_child(window_layer, bitmap_layer_get_layer(icon_layer));

  temperature_layer = text_layer_create(GRect(0, 100, 144, 68));
  text_layer_set_text_color(temperature_layer, GColorWhite);
  text_layer_set_background_color(temperature_layer, GColorClear);
  text_layer_set_font(temperature_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT));
  text_layer_set_text_alignment(temperature_layer, GTextAlignmentCenter);
  text_layer_set_text(temperature_layer, temperature);

  Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 0),
    TupletCString(WEATHER_TEMPERATURE_KEY, "70\u00B0F"),
    TupletCString(WEATHER_REALFEEL_KEY, "70\u00B0F"),
  };
    
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, sync_error_callback, NULL);
  
  window_set_click_config_provider(window, (ClickConfigProvider) config_provider);

  layer_add_child(window_layer, text_layer_get_layer(temperature_layer));
}
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  s_icon_layer = bitmap_layer_create(GRect(32, 10, 80, 80));
  layer_add_child(window_layer, bitmap_layer_get_layer(s_icon_layer));

  s_temperature_layer = text_layer_create(GRect(0, 75, bounds.size.w, 68));
  text_layer_set_text_color(s_temperature_layer, GColorWhite);
  text_layer_set_background_color(s_temperature_layer, GColorClear);
  text_layer_set_font(s_temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(s_temperature_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_temperature_layer));

  s_city_layer = text_layer_create(GRect(0, 105, bounds.size.w, 68));
  text_layer_set_text_color(s_city_layer, GColorWhite);
  text_layer_set_background_color(s_city_layer, GColorClear);
  text_layer_set_font(s_city_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(s_city_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_city_layer));

  Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1),
    TupletCString(WEATHER_TEMPERATURE_KEY, "1234\u00B0C"),
    TupletCString(WEATHER_CITY_KEY, "St Pebblesburg"),
  };

  app_sync_init(&s_sync, s_sync_buffer, sizeof(s_sync_buffer), 
      initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, sync_error_callback, NULL
  );

  request_weather();
}
Exemple #7
0
static void menu_select_callback(int index, void *ctx) {	
	if(index==0)
		send_to_phone(TupletCString(103, "BOAT")); 
	else if(index==1)
		send_to_phone(TupletCString(103, "PIN")); 

	vibes_short_pulse();
	window_stack_pop(true); //this window
}
Exemple #8
0
  // This function will set up all the text layers and will initialize the App_Sync.
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  
  //setting up the layer that displays the cardinal direction.
  direction_layer = text_layer_create(GRect(0, 60, 144, 68));
  text_layer_set_text_color(direction_layer, GColorBlack);
  text_layer_set_background_color(direction_layer, GColorClear);
  text_layer_set_font(direction_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  text_layer_set_text_alignment(direction_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(direction_layer));
  
  
  // Setting up top-most text layer. 
  top_layer = text_layer_create(GRect(50, 0, 100, 25));
  text_layer_set_text_color(top_layer, GColorBlack);
  text_layer_set_background_color(top_layer, GColorClear);
  text_layer_set_font(top_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(top_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(top_layer));
  text_layer_set_text(top_layer, "Numeric");
  
  // Setting up bottom-most text layer. 
  bottom_layer = text_layer_create(GRect(50, 140, 100, 30));
  text_layer_set_text_color(bottom_layer, GColorBlack);
  text_layer_set_background_color(bottom_layer, GColorClear);
  text_layer_set_font(bottom_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(bottom_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(bottom_layer));
  text_layer_set_text(bottom_layer, "Character");
  
  
  // Setting up "Open App" text layer. 
  init_layer = text_layer_create(GRect(0, 45, 144, 80));
  text_layer_set_text_color(init_layer, GColorBlack);
  text_layer_set_background_color(init_layer, GColorClear);
  text_layer_set_font(init_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(init_layer, GTextAlignmentCenter);
  text_layer_set_text(init_layer, "Please open the Android companion app, then choose a compass type.");  
  layer_add_child(window_layer, text_layer_get_layer(init_layer));
  
  
  Tuplet initial_values[]= {
    TupletCString(DIRECTION_KEY, "Loading...."),
    TupletCString(NUM_DIRECTION_KEY, "Loading...."),
   };
    
  
  // Initializing App_Sync!
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL);

  send_cmd();
  
}
/* Sends a request to change the units between celsius and fahrenheit */
void send_change_units_message() {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  if (celsius) {
    Tuplet value = TupletCString(4, "Use celsius");
    dict_write_tuplet(iter, &value);
  } else {
    Tuplet value = TupletCString(5, "Use Fahrenheit");
    dict_write_tuplet(iter, &value);
  }
  app_message_outbox_send();
}
Exemple #10
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  
  gridpower_layer = text_layer_create(GRect(0, 10, 144, 68));
  text_layer_set_text_color(gridpower_layer, GColorBlack);
  text_layer_set_background_color(gridpower_layer, GColorClear);
  text_layer_set_font(gridpower_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(gridpower_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(gridpower_layer));
  
  
  dailyenery_layer = text_layer_create(GRect(0, 30, 144, 68));
  text_layer_set_text_color(dailyenery_layer, GColorBlack);
  text_layer_set_background_color(dailyenery_layer, GColorClear);
  text_layer_set_font(dailyenery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(dailyenery_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(dailyenery_layer));  
  
  montlyenergy_layer = text_layer_create(GRect(0, 50, 144, 68));
  text_layer_set_text_color(montlyenergy_layer, GColorBlack);
  text_layer_set_background_color(montlyenergy_layer, GColorClear);
  text_layer_set_font(montlyenergy_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(montlyenergy_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(montlyenergy_layer));
  
  yearlyenergy_layer = text_layer_create(GRect(0, 70, 144, 68));
  text_layer_set_text_color(yearlyenergy_layer, GColorBlack);
  text_layer_set_background_color(yearlyenergy_layer, GColorClear);
  text_layer_set_font(yearlyenergy_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(yearlyenergy_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(yearlyenergy_layer));
  
  totalenergy_layer = text_layer_create(GRect(0, 90, 144, 68));
  text_layer_set_text_color(totalenergy_layer, GColorBlack);
  text_layer_set_background_color(totalenergy_layer, GColorClear);
  text_layer_set_font(totalenergy_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(totalenergy_layer, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(totalenergy_layer));
  
  Tuplet initial_values[] = {
    TupletCString(SOLAR_GRIDPOWER, "Power:"),
    TupletCString(SOLAR_DAILYENERGY, "Daily:"),
    TupletCString(SOLAR_MONTHLYENERGY, "Monthly:"),
    TupletCString(SOLAR_YEARLYENERGY, "Yearly:"),
    TupletCString(SOLAR_TOTALENERGY, "Total:"),
  };  
  
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, sync_error_callback, NULL);
  
  send_cmd(0);
  
}
Exemple #11
0
static void menu_select_callback(int index, void *ctx) {	

	if(index==0)// 10 mins - 600 sec's
		send_to_phone(TupletCString(104, "600")); 
	else if(index==1)
		send_to_phone(TupletCString(104, "300")); //5 mins
	else if(index==2) // 4 mins = 240 sec's
		send_to_phone(TupletCString(104, "240")); 
 
	window_stack_pop(true); //this window
	vibes_short_pulse();
	//show_start_solution();
}
Exemple #12
0
static void send_cmd(void) {
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	
	if (iter == NULL) {
		return;
	}
	Tuplet direction = TupletCString(0, index);	
	dict_write_tuplet(iter, &direction);
	Tuplet load = TupletCString(2, "Loading...");
	dict_write_tuplet(iter, &load);
	dict_write_end(iter);
	
	app_message_outbox_send();
}
void controller_setmodel(PropertyName propertyName, const char* const value) {
  Tuplet values[] = {
    TupletCString(propertyName, value)
  };
  app_sync_set(&s_sync, values, ARRAY_LENGTH(values));
  modelChangedCallback(propertyName, value);
}
void openweather_init(void) {
  // init forecast structure
  forecast_data.day = calloc(OPENWEATHER_FCAST_DAYS, sizeof(ForecastDayType));

  // init json parser
  json_register_callbacks(object_callback, array_callback);

  // Open channel
  const int inbound_size = app_message_inbox_size_maximum();
  const int outbound_size = app_message_outbox_size_maximum();
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Determined sizes: Inbox %u Outbox %u", inbound_size, outbound_size);  

  app_message_open(inbound_size, outbound_size);

  // Init sync
  Tuplet initial_values[] = {
    TupletCString(OPENWEATHER_KEY, "")
  };
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, sync_error_callback, NULL);

  // Set update
  set_timer(OPENWEATHER_REFRESH_INTERVAL);

}
Exemple #15
0
static void init() {
  window = window_create();
  window_set_background_color(window, GColorBlack);
  window_set_fullscreen(window, true);

  icon_layer = bitmap_layer_create(GRect(32, 10, 80, 80));
  bitmap_layer_set_bitmap(icon_layer, icon_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(icon_layer));

  temperature_layer = text_layer_create(GRect(0, 100, 144, 68));
  text_layer_set_text_color(temperature_layer, GColorWhite);
  text_layer_set_background_color(temperature_layer, GColorClear);
  text_layer_set_font(temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(temperature_layer, GTextAlignmentCenter);
  text_layer_set_text(temperature_layer, temperature);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(temperature_layer));

  Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1),
    TupletCString(WEATHER_TEMPERATURE_KEY, "1234\u00B0C"),
  };

  app_message_open(64, 64);
  send_cmd();

  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, sync_error_callback, NULL);


  window_stack_push(window, true /* Animated */);
}
Exemple #16
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  
  temperature_layer = text_layer_create(GRect(0, 140, 155, 40));
  text_layer_set_text_color(temperature_layer, GColorWhite);
  text_layer_set_background_color(temperature_layer, GColorBlack);
  text_layer_set_font(temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(temperature_layer, GTextAlignmentCenter);
  text_layer_set_text(temperature_layer, temperature);

  Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1),
    TupletCString(WEATHER_TEMPERATURE_KEY, "1234\u00B0C"),
  };
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, sync_error_callback, NULL);

  layer_add_child(window_layer, text_layer_get_layer(temperature_layer));
  
  s_time_layer = text_layer_create(GRect(0, 0, 150, 40));
  text_layer_set_background_color(s_time_layer, GColorBlack);
  text_layer_set_text_color(s_time_layer, GColorWhite);
  text_layer_set_text(s_time_layer, "00:00:00");
  
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
  
  changeWeatherCode(0);
  
  timer = app_timer_register(delta, (AppTimerCallback) timer_callback, NULL);
}
Exemple #17
0
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;
  }
}
Exemple #18
0
void handle_init(AppContextRef ctx) {

  window_init(&window, "Simplicity");
  window_stack_push(&window, true /* Animated */);
  window_set_background_color(&window, GColorBlack);

  resource_init_current_app(&APP_RESOURCES);

  layer_init(&time_layer, GRect(0, 12, 144, 168-68));
  layer_add_child(&window.layer, &time_layer);

  text_layer_init(&text_date_layer, window.layer.frame);
  text_layer_set_text_color(&text_date_layer, GColorWhite);
  text_layer_set_background_color(&text_date_layer, GColorClear);
  layer_set_frame(&text_date_layer.layer, GRect(8, 0, 144-8, 168-68));
  text_layer_set_font(&text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)));
  layer_add_child(&time_layer, &text_date_layer.layer);


  text_layer_init(&text_time_layer, window.layer.frame);
  text_layer_set_text_color(&text_time_layer, GColorWhite);
  text_layer_set_background_color(&text_time_layer, GColorClear);
  layer_set_frame(&text_time_layer.layer, GRect(7, 24, 144-7, 168-92));
  text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)));
  layer_add_child(&time_layer, &text_time_layer.layer);


  layer_init(&line_layer, window.layer.frame);
  line_layer.update_proc = &line_layer_update_callback;
  layer_add_child(&time_layer, &line_layer);

  layer_init(&car_layer, GRect(0, 90, 144, 168-90));
  layer_add_child(&window.layer, &car_layer);

  text_layer_init(&text_rated_layer, window.layer.frame);
  text_layer_set_text_color(&text_rated_layer, GColorWhite);
  text_layer_set_background_color(&text_rated_layer, GColorClear);
  layer_set_frame(&text_rated_layer.layer, GRect(8, 0, 144-8, 168-68));
  text_layer_set_font(&text_rated_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)));
  layer_add_child(&car_layer, &text_rated_layer.layer);
	
  text_layer_init(&text_state_layer, window.layer.frame);
  text_layer_set_text_color(&text_state_layer, GColorWhite);
  text_layer_set_background_color(&text_state_layer, GColorClear);
  layer_set_frame(&text_state_layer.layer, GRect(8, 20, 144-8, 168-68));
  text_layer_set_font(&text_state_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)));
  layer_add_child(&car_layer, &text_state_layer.layer);
	
  layer_init(&battery_layer, GRect(72, 10, 144-70, 10));
  battery_layer.update_proc = &battery_layer_update_callback;
  layer_add_child(&car_layer, &battery_layer);

  Tuplet initial_values[] = {
    TupletInteger(TESLA_RATED_REMAIN_KEY, (uint16_t) 148),
    TupletCString(TESLA_STATE_STRING_KEY, "Charging"),
	TupletInteger(TESLA_BATTERY_PERCENT_KEY, (uint8_t) 72),
  };
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
                sync_tuple_changed_callback, sync_error_callback, NULL);
}
 // 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);
 }
Exemple #20
0
static void window_load(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    
    datetime_layer = text_layer_create(GRect(0, 100, 144, 22));
    text_layer_set_text_color(datetime_layer, GColorBlack);
    text_layer_set_background_color(datetime_layer, GColorWhite);
    text_layer_set_font(datetime_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
    text_layer_set_text_alignment(datetime_layer, GTextAlignmentCenter);
    layer_add_child(window_layer, text_layer_get_layer(datetime_layer));
    
    icon_layer = bitmap_layer_create(GRect(84, 0, 60, 60));
    layer_add_child(window_layer, bitmap_layer_get_layer(icon_layer));
    
    bg_layer = text_layer_create(GRect(0, 5, 83, 68));
    text_layer_set_text_color(bg_layer, GColorWhite);
    text_layer_set_background_color(bg_layer, GColorClear);
    text_layer_set_font(bg_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_MEDIUM_NUMBERS));
    text_layer_set_text_alignment(bg_layer, GTextAlignmentCenter);
    layer_add_child(window_layer, text_layer_get_layer(bg_layer));
    
    readtime_layer = text_layer_create(GRect(0, 48, 144, 115));
    text_layer_set_text_color(readtime_layer, GColorWhite);
    text_layer_set_background_color(readtime_layer, GColorClear);
    text_layer_set_font(readtime_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT));
    text_layer_set_text_alignment(readtime_layer, GTextAlignmentCenter);
    layer_add_child(window_layer, text_layer_get_layer(readtime_layer));
    
    message_layer = text_layer_create(GRect(0, 124, 144, 68));
    text_layer_set_text_color(message_layer, GColorBlack);
    text_layer_set_background_color(message_layer, GColorWhite);
    text_layer_set_font(message_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
    text_layer_set_text_alignment(message_layer, GTextAlignmentCenter);
    layer_add_child(window_layer, text_layer_get_layer(message_layer));
    
    Tuplet initial_values[] = {
        TupletInteger(CGM_ICON_KEY, (uint8_t) 4),
        TupletCString(CGM_BG_KEY, ""),
        TupletCString(CGM_READTIME_KEY, ""),
        TupletInteger(CGM_ALERT_KEY, 0),
        TupletCString(CGM_TIME_NOW, "loading..."),
        TupletCString(CGM_DELTA_KEY, " ")
    };

    app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),sync_tuple_changed_callback, sync_error_callback, NULL);

    timer = app_timer_register(100, timer_callback, NULL);
}
Exemple #21
0
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();
}
Exemple #22
0
/* This is called when the down button is clicked */
void select_click_down_handler(ClickRecognizerRef recognizer, void *context) {
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  int key = 0;
  Tuplet value = TupletCString(key, "tmrw");
  dict_write_tuplet(iter, &value);
  app_message_outbox_send();
}
/*
 * send out msg to cell phone.
 * Param:
 * @param: msg to send out.
 */
void send_outbox(char *param) {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    int key = 0;
    Tuplet value = TupletCString(key, param);
    dict_write_tuplet(iter, &value);
    app_message_outbox_send();
}
Exemple #24
0
static void send_appmessage(char* message) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Fetching stop time");
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  Tuplet value = TupletCString(ACTION, message);
  dict_write_tuplet(iter, &value);
  app_message_outbox_send();
}
Exemple #25
0
void getEtas(char stopid[512], char routeid[512]) {
	Tuplet get_eta_tuple = TupletInteger(DOUBLEMAP_GET_ETA, 1);
	Tuplet stop_id_tuple = TupletCString(DOUBLEMAP_STOP_ID, stopid);
	Tuplet route_id_tuple = TupletCString(DOUBLEMAP_ROUTE_ID, routeid);
	DictionaryIterator *iter;
	app_message_outbox_begin(&iter);
	
	if (iter == NULL) {
		return;
	}
	
	dict_write_tuplet(iter, &get_eta_tuple);
	dict_write_tuplet(iter, &stop_id_tuple);
	dict_write_tuplet(iter, &route_id_tuple);
	dict_write_end(iter);
	app_message_outbox_send();
}
// Change to another client
void change_client_click(ClickRecognizerRef recognizer, Window *window) {
	app_message_outbox_begin(&iter);
	Tuplet value = TupletCString(0, "getClients");
	dict_write_tuplet(iter, &value);
	Tuplet pager = TupletInteger(1, page);
	dict_write_tuplet(iter, &pager);
	app_message_outbox_send();
}
Exemple #27
0
// Init function to handle the creation of layers,
// event subscribing, etc
void handle_init(void) 
{
	// window init
	window = window_create();
	window_stack_push(window, true);
	window_set_background_color(window, GColorWhite);

	// display layer
	Layer *window_layer = window_get_root_layer(window);
	
	// background
	leafs = gbitmap_create_with_resource(RESOURCE_ID_BKNG);
	leafs_layer = bitmap_layer_create(GRect(0, 0, WATCH_WIDTH, WATCH_HEIGHT));
	bitmap_layer_set_bitmap(leafs_layer, leafs);
	layer_add_child(window_layer, bitmap_layer_get_layer(leafs_layer));
	
	GFont prox_reg = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PROXIMA_REGULAR_16));
	GFont prox_bold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PROXIMA_BOLD_30));

	// time init
	text_time_layer = text_layer_create(GRect(55, 100,(WATCH_WIDTH - 55), 50));
	text_layer_set_font(text_time_layer, prox_bold);
	text_layer_set_background_color(text_time_layer, GColorClear);
    layer_add_child(window_layer, text_layer_get_layer(text_time_layer));
	
	// date init
	text_date_layer = text_layer_create(GRect(55, 130, (WATCH_WIDTH - 55), 20));
	text_layer_set_font(text_date_layer, prox_reg);
	text_layer_set_background_color(text_date_layer, GColorClear);
    layer_add_child(window_layer, text_layer_get_layer(text_date_layer));
	
	// score init
	text_score_layer = text_layer_create(GRect(55, 15, (WATCH_WIDTH - 55), 20));
	text_layer_set_font(text_score_layer, prox_reg);
	text_layer_set_text_color(text_score_layer, GColorWhite);
	text_layer_set_background_color(text_score_layer, GColorClear);
    layer_add_child(window_layer, text_layer_get_layer(text_score_layer));

 	//update_display(tick_time);
	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
	
	// AppSync stuff
	const int inbound_size = 64;
	const int outbound_size = 64;
	app_message_open(inbound_size, outbound_size);
	
	Tuplet initial_values[] = {
		TupletCString(0, "0-0")
	};
	
	app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
				 sync_tuple_changed_callback, sync_error_callback, NULL);
	
	send_cmd();
	
	// setting up timer to send cmds for updates
	timer = app_timer_register(10000, timer_callback, NULL);
}
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);

  lattitude_layer = text_layer_create(GRect(0, 15, 144, 68));
  text_layer_set_text_color(lattitude_layer, GColorWhite);
  text_layer_set_background_color(lattitude_layer, GColorClear);
  text_layer_set_font(lattitude_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(lattitude_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(lattitude_layer));

  longitude_layer = text_layer_create(GRect(0, 35, 144, 68));
  text_layer_set_text_color(longitude_layer, GColorWhite);
  text_layer_set_background_color(longitude_layer, GColorClear);
  text_layer_set_font(longitude_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(longitude_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(longitude_layer));
  
  tracking_layer = text_layer_create(GRect(0, 65, 144, 68));
  text_layer_set_text_color(tracking_layer, GColorWhite);
  text_layer_set_background_color(tracking_layer, GColorClear);
  text_layer_set_font(tracking_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(tracking_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(tracking_layer));
  
  activity_layer = text_layer_create(GRect(0, 95, 144, 68));
  text_layer_set_text_color(activity_layer, GColorWhite);
  text_layer_set_background_color(activity_layer, GColorClear);
  text_layer_set_font(activity_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(activity_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(activity_layer));

  Tuplet initial_values[] = {
    TupletCString(TRIPCHAIN_LATTITUDE_KEY, "60.1833\u00B0 N"),
    TupletCString(TRIPCHAIN_LONGITUDE_KEY, "24.8333\u00B0 E"),
    TupletCString(TRIPCHAIN_TRACKING_KEY, "Not tracking"),
    TupletCString(TRIPCHAIN_ACTIVITY_KEY, "default"),
    
    
  };

  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, sync_error_callback, NULL);

  send_cmd();
}
/* Handles the user clicking the select button to refresh the statistics */
void refresh_stats_click_handler(ClickRecognizerRef recognizer, void* context) {
  text_layer_set_text(hello_layer, "Getting data!");
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  // sends a request for the statistics, using key #1
  Tuplet value = TupletCString(1, "hello?");
  dict_write_tuplet(iter, &value);
  app_message_outbox_send();
}
Exemple #30
0
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	
	font_last_price_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_MEDIUM_39));
	font_last_price_large = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_MEDIUM_39));
  font_hash_large = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIAVLO_MEDIUM_39));
	
	text_five_layer = text_layer_create(GRect(0, 0, 144-0, 168-0));
	text_layer_set_text_color(text_five_layer, GColorWhite);
	text_layer_set_background_color(text_five_layer, GColorClear);
	text_layer_set_font(text_five_layer, font_last_price_large);
	text_layer_set_text_alignment(text_five_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(text_five_layer));
  
  text_hash_layer = text_layer_create(GRect(0, 64, 144-0, 168-40));
	text_layer_set_text_color(text_hash_layer, GColorWhite);
	text_layer_set_background_color(text_hash_layer, GColorClear);
	text_layer_set_font(text_hash_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
	text_layer_set_text_alignment(text_hash_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(text_hash_layer));
  

	
	
	text_date_layer = text_layer_create(GRect(8, 96, 144-8, 168-96));
	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_DIAVLO_15)));
	layer_add_child(window_layer, text_layer_get_layer(text_date_layer));
	
	text_time_layer = text_layer_create(GRect(7, 114, 144-7, 168-114));
	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_DIAVLO_HEAVY_44)));
	layer_add_child(window_layer, text_layer_get_layer(text_time_layer));
	
	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
	
	time_t now = time(NULL);
	struct tm *t = localtime(&now);
	update_time(t);
	
	Tuplet initial_values[] = {
		TupletCString(FIVE_HASH, "---"),
    //TupletCString(FIVE_HASH, "---"),
//		TupletCString(HOUR_HASH, "---"),
		TupletInteger(INVERT_COLOR_KEY, persist_read_bool(INVERT_COLOR_KEY)),
	};
	
	app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
				  sync_tuple_changed_callback, sync_error_callback, NULL);
	
	//send_cmd();last_price
	timer = app_timer_register(2000, timer_callback, NULL);
	//set_timer();
}