Beispiel #1
0
static void handle_tap(AccelAxisType axis, int32_t direction) {
    persist_write_bool(STYLE_KEY, !persist_read_bool(STYLE_KEY));
    set_style();
    force_update();
    vibes_long_pulse();
    accel_tap_service_unsubscribe();
}
Beispiel #2
0
static void handle_init(void) {
    window = window_create();
    window_stack_push(window, true /* Animated */);

    // child init
    simplebig_init(window);
    status_init(window);
    termo_init(window);

    // Register callbacks
    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);

    // Open AppMessage
    AppMessageResult result = app_message_open(APP_MESSAGE_INBOX_SIZE_MINIMUM, APP_MESSAGE_OUTBOX_SIZE_MINIMUM);
    if (result != APP_MSG_OK) {
        APP_LOG(APP_LOG_LEVEL_ERROR, "Can't open inbox");
    }

    // handlers
    tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
    UnobstructedAreaHandlers ua_handler = {
        .change = handle_unobstructed_change
    };
    unobstructed_area_service_subscribe(ua_handler, NULL);

    // style
    set_style();

    // draw first frame
    force_update();
}
Beispiel #3
0
void main_window_init(void)
{
	main_window = window_create();
	window_stack_push(main_window, true);
	window_set_background_color(main_window, BACKGROUND_COLOR);
	Layer *window_layer = window_get_root_layer(main_window);
 
	int y_pos = 8;
	for (int index = 0; index < 4; index++) {
		TextLayer *text_layer = text_layer_create(GRect(0, y_pos, 144, 36));
		text_layer_set_text_color(text_layer, TEXT_COLOR);
		text_layer_set_background_color(text_layer, GColorClear);
		text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
		
		memset(lines[index], ' ', LINES_WIDTH);
		text_layer_set_text(text_layer, lines[index]);
		
		layer_add_child(window_layer, text_layer_get_layer(text_layer));
		text_layers[index] = text_layer;
		y_pos += 38;
	}

	force_update();

	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
	accel_tap_service_subscribe(&accel_tap_handler);
}
Beispiel #4
0
static void auto_close_info_window(void *data)
{
	app_timer = NULL;
	force_update();
	const bool animated = false;
	window_stack_pop_all(animated);
	window_stack_push(main_window, true);
}
Beispiel #5
0
// MESSAGING
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {

    // Look for item
    Tuple *t = dict_find(iterator, MESSAGE_KEY_INVERSE);
 
    // For all items
    if (t) {
        persist_write_bool(STYLE_KEY, t->value->int32 == 1);
        set_style();
        force_update();
        vibes_long_pulse();
    }

    termo_inbox_received(iterator, context);
}
Beispiel #6
0
static void init(void) {
  memset(&time_digits_layers, 0, sizeof(time_digits_layers));
  memset(&time_digits_images, 0, sizeof(time_digits_images));

  memset(&date_digits_layers, 0, sizeof(date_digits_layers));
  memset(&date_digits_images, 0, sizeof(date_digits_images));

 // Setup messaging
  const int inbound_size = 128;
  const int outbound_size = 128;
  app_message_open(inbound_size, outbound_size);	
	
  window = window_create();
  if (window == NULL) {
      //APP_LOG(APP_LOG_LEVEL_DEBUG, "OOM: couldn't allocate window");
      return;
  }
	
  window_set_background_color(window, GColorBlack);

	
  window_stack_push(window, true /* Animated */);
  window_layer = window_get_root_layer(window);
	
	// resources
  custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SQUARE_26));

    img_battery_100   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_090_100);
    img_battery_90   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_080_090);
    img_battery_80   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_070_080);
    img_battery_70   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_060_070);
    img_battery_60   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_050_060);
    img_battery_50   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_040_050);
    img_battery_40   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_030_040);
    img_battery_30    = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_020_030);
    img_battery_20    = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_010_020);
    img_battery_10    = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_000_010);
    img_battery_charge = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_CHARGING);

    // layers
    layer_batt_img  = bitmap_layer_create(GRect(132, 5, 9, 98));
    bitmap_layer_set_bitmap(layer_batt_img, img_battery_100);
	layer_add_child(window_layer, bitmap_layer_get_layer(layer_batt_img));
	
  separator_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SEPARATOR);
#ifdef PBL_PLATFORM_BASALT
  GRect bitmap_bounds = gbitmap_get_bounds(separator_image);
#else
  GRect bitmap_bounds = separator_image->bounds;
#endif	
  GRect frame = GRect(68, 81, bitmap_bounds.size.w, bitmap_bounds.size.h);
  separator_layer = bitmap_layer_create(frame);
  bitmap_layer_set_bitmap(separator_layer, separator_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(separator_layer));   

  bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH);
#ifdef PBL_PLATFORM_BASALT
  GRect bitmap_bounds2 = gbitmap_get_bounds(bluetooth_image);
#else
  GRect bitmap_bounds2 = bluetooth_image->bounds;
#endif	
  GRect frame2 = GRect(128, 112, bitmap_bounds2.size.w, bitmap_bounds2.size.h);
  bluetooth_layer = bitmap_layer_create(frame2);
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer));

  Layer *weather_holder = layer_create(GRect(0, 0, 144, 168 ));
  layer_add_child(window_layer, weather_holder);

  icon_layer = bitmap_layer_create(GRect(-3, 100, 60, 75));
  layer_add_child(weather_holder, bitmap_layer_get_layer(icon_layer));
 	
  // Create time and date layers
  GRect dummy_frame = { {0, 0}, {0, 0} };	
   day_name_layer = bitmap_layer_create(dummy_frame);
   layer_add_child(window_layer, bitmap_layer_get_layer(day_name_layer));	
		
   month_layer = bitmap_layer_create(dummy_frame);
   layer_add_child(window_layer, bitmap_layer_get_layer(month_layer));	
	
    for (int i = 0; i < TOTAL_TIME_DIGITS; ++i) {
    time_digits_layers[i] = bitmap_layer_create(dummy_frame);
    layer_add_child(window_layer, bitmap_layer_get_layer(time_digits_layers[i]));
  }
	
    for (int i = 0; i < TOTAL_DATE_DIGITS; ++i) {
    date_digits_layers[i] = bitmap_layer_create(dummy_frame);
    layer_add_child(window_layer, bitmap_layer_get_layer(date_digits_layers[i]));
  }
	
  for (int i = 0; i < TOTAL_SECONDS_DIGITS; ++i) {
    seconds_digits_layers[i] = bitmap_layer_create(dummy_frame);
    layer_add_child(window_layer, bitmap_layer_get_layer(seconds_digits_layers[i]));
  }

  temp_layer = text_layer_create(GRect(120, 135, 40, 40));
  text_layer_set_text_color(temp_layer, GColorWhite);
#ifdef PBL_COLOR	
		text_layer_set_text_color(temp_layer, GColorVividCerulean     );			
#endif
  text_layer_set_background_color(temp_layer, GColorClear);
 // text_layer_set_font(temp_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_font(temp_layer, custom_font);
  text_layer_set_text_alignment(temp_layer, GTextAlignmentLeft);
  layer_add_child(weather_holder, text_layer_get_layer(temp_layer));
	
 // creating effect layer to rotate temp
  effect_layer_2 = effect_layer_create(GRect(115,135,33,33));
  effect_layer_add_effect(effect_layer_2, effect_rotate_90_degrees, (void *)false);
  layer_add_child(window_get_root_layer(window), effect_layer_get_layer(effect_layer_2));
	
Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 14),
    TupletInteger(INVERT_COLOR_KEY, persist_read_bool(INVERT_COLOR_KEY)),
    TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)),
    TupletInteger(STYLE_KEY, persist_read_bool(STYLE_KEY)),
    TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)),
    TupletInteger(HIDE_BATT_KEY, persist_read_bool(HIDE_BATT_KEY)),
	TupletInteger(HIDE_DATE_KEY, persist_read_bool(HIDE_DATE_KEY)),
	TupletInteger(HIDE_WEATHER_KEY, persist_read_bool(HIDE_WEATHER_KEY)),
	TupletCString(WEATHER_TEMPERATURE_KEY, ""),

  };

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

  appStarted = true;

  // Avoids a blank screen on watch start.
  time_t now = time(NULL);
  struct tm *tick_time = localtime(&now);  
  handle_tick(tick_time, MONTH_UNIT + DAY_UNIT + HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT);

  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);	

	 // handlers
    battery_state_service_subscribe(&handle_battery);
    bluetooth_connection_service_subscribe(&handle_bluetooth);
	
	 // draw first frame
    force_update();

}
Beispiel #7
0
static void init(void) {

  memset(&normal_time_digits_layers, 0, sizeof(normal_time_digits_layers));
  memset(&normal_time_digits_images, 0, sizeof(normal_time_digits_images));
		
  // Setup messaging
  const int inbound_size = 256;
  const int outbound_size = 256;
  app_message_open(inbound_size, outbound_size);	
	
  window = window_create();
  if (window == NULL) {
      //APP_LOG(APP_LOG_LEVEL_DEBUG, "OOM: couldn't allocate window");
      return;
  }
  window_stack_push(window, true /* Animated */);
  window_layer = window_get_root_layer(window);

  window_set_background_color(window, GColorBlack);


  GRect dummy_frame = { {0, 0}, {0, 0} };

	for (int i = 0; i < TOTAL_NORMAL_DIGITS; ++i) {
    normal_time_digits_layers[i] = bitmap_layer_create(dummy_frame);
   layer_add_child(window_layer, bitmap_layer_get_layer(normal_time_digits_layers[i]));
  }	
 
	
	 // ** { begin setup mask for MASK effect
  mask.text = NULL;
  mask.bitmap_mask = NULL;

  #ifdef PBL_COLOR
    mask.mask_colors = malloc(sizeof(GColor)*4);
    mask.mask_colors[0] = GColorWhite;
    mask.mask_colors[1] = GColorDarkGray;
    mask.mask_colors[2] = GColorLightGray;
//    mask.mask_colors[3] = GColorClear;
  #else
    mask.mask_colors = malloc(sizeof(GColor)*2);
    mask.mask_colors[0] = GColorWhite;
    mask.mask_colors[1] = GColorClear;
  #endif
	  
  mask.background_color = GColorClear;
  mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK);


  // ** end setup mask }
	
  //creating effect layer
  effect_layer_mask = effect_layer_create(GRect(0,0,144,168));
  effect_layer_add_effect(effect_layer_mask, effect_mask, &mask);
  layer_add_child((window_layer), effect_layer_get_layer(effect_layer_mask));

	
	img_battery_100   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_080_100);
    img_battery_30   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_005_030);
    img_battery_00   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_000_005);
    img_battery_charge = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_CHARGING);
    layer_batt_img  = bitmap_layer_create(GRect(66, 102, 9,11));
	bitmap_layer_set_bitmap(layer_batt_img, img_battery_100);
	layer_add_child(window_layer, bitmap_layer_get_layer(layer_batt_img));
		
   bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_ICON_NOBLUETOOTH);
#ifdef PBL_PLATFORM_BASALT
  GRect bitmap_bounds_bt_on = gbitmap_get_bounds(bluetooth_image);
#else
  GRect bitmap_bounds_bt_on = bluetooth_image->bounds;
#endif	
  GRect frame_bt = GRect(66, 102, bitmap_bounds_bt_on.size.w, bitmap_bounds_bt_on.size.h);
  bluetooth_layer = bitmap_layer_create(frame_bt);
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer));
	
	date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ODIN_24));

	layer_date_text = text_layer_create(GRect(0, 10, 144, 26));
	text_layer_set_text_color(layer_date_text, GColorWhite);		
    text_layer_set_background_color(layer_date_text, GColorClear);
    text_layer_set_font(layer_date_text, date_font);
    text_layer_set_text_alignment(layer_date_text, GTextAlignmentRight);
    layer_add_child(window_layer, text_layer_get_layer(layer_date_text));

	layer_ampm_text = text_layer_create(GRect(0, 114, 140, 26));
    text_layer_set_text_color(layer_ampm_text, GColorWhite);
	text_layer_set_background_color(layer_ampm_text, GColorClear);
    text_layer_set_font(layer_ampm_text, date_font);
    text_layer_set_text_alignment(layer_ampm_text, GTextAlignmentRight);
    layer_add_child(window_layer, text_layer_get_layer(layer_ampm_text));

	
  // Avoids a blank screen on watch start.
  time_t now = time(NULL);
  struct tm *tick_time = localtime(&now);  
  handle_tick(tick_time, MONTH_UNIT + DAY_UNIT + HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT);

  Tuplet initial_values[] = {
    TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)),
    TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)),
	TupletInteger(FLIP_KEY, persist_read_bool(FLIP_KEY)),
	TupletInteger(COLOUR_KEY, persist_read_bool(COLOUR_KEY)),
	TupletInteger(BLINK_KEY, persist_read_bool(BLINK_KEY)),
  };

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

  appStarted = true;
 
	 // handlers
    battery_state_service_subscribe(&update_battery);
    bluetooth_connection_service_subscribe(&bluetooth_connection_callback);
    tick_timer_service_subscribe(SECOND_UNIT, handle_tick);

	 // draw first frame
    force_update();
}