예제 #1
0
static void handle_tick(struct tm *t, TimeUnits units_changed) {
 //test
  
  t->tm_hour = 6;
  t->tm_min = 45;
  
 rot_bitmap_layer_set_angle(rot_minute, TRIG_MAX_ANGLE * t->tm_min / 60);
 rot_bitmap_layer_set_angle(rot_hour,  (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
}
예제 #2
0
파일: trails.c 프로젝트: 8a22a/Trails
void update_watch(struct tm *t){

  long minute_hand_rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360;
  long hour_hand_rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) +
					      (t->tm_min/2)) / 360;
  rot_bitmap_layer_set_angle(minute_hand_layer, minute_hand_rotation);
  rot_bitmap_layer_set_angle(hour_hand_layer, hour_hand_rotation);

  layer_mark_dirty(bitmap_layer_get_layer((BitmapLayer *)minute_hand_layer));
  layer_mark_dirty(bitmap_layer_get_layer((BitmapLayer *)hour_hand_layer));

}
예제 #3
0
static void compass_heading_handler(CompassHeadingData chd) {
  int h = (chd.true_heading);
  rot_bitmap_layer_set_angle(rbl, h + (heading*TRIG_MAX_ANGLE/360));
//   rot_bitmap_layer_increment_angle(rbl, 1);
//   snprintf(buf, 100, "%d", h);
//   text_layer_set_text(s_time_layer, buf);
}
예제 #4
0
static void handleTick(struct tm *t, TimeUnits units_changed) {
	GRect r;
	int32_t minuteAngle = t->tm_sec * TRIG_MAX_ANGLE / 60;
	int32_t hourAngle = ((t->tm_min%12)*60 + t->tm_sec) * TRIG_MAX_ANGLE / 720;
	
	snprintf(text, sizeof(text), "%.2d:%.2d", (t->tm_min)%12, t->tm_sec);
	text_layer_set_text(textLayer, text);
	
	r = layer_get_frame((Layer *)minuteHandLayer);
	r.origin.x = 72 - r.size.w/2 + 56 * cos_lookup((minuteAngle + 3 * TRIG_MAX_ANGLE / 4)%TRIG_MAX_ANGLE) / TRIG_MAX_RATIO;
	r.origin.y = 84 - r.size.h/2 + 56 * sin_lookup((minuteAngle + 3 * TRIG_MAX_ANGLE / 4)%TRIG_MAX_ANGLE) / TRIG_MAX_RATIO;
	layer_set_frame((Layer *)minuteHandLayer, r);
	rot_bitmap_layer_set_angle(minuteHandLayer, minuteAngle);
	
	r = layer_get_frame((Layer *)hourHandLayer);
	r.origin.x = 72 - r.size.w/2 + 57 * cos_lookup((hourAngle + 3 * TRIG_MAX_ANGLE / 4)%TRIG_MAX_ANGLE) / TRIG_MAX_RATIO;
	r.origin.y = 84 - r.size.h/2 + 57 * sin_lookup((hourAngle + 3 * TRIG_MAX_ANGLE / 4)%TRIG_MAX_ANGLE) / TRIG_MAX_RATIO;
	layer_set_frame((Layer *)hourHandLayer, r);
	rot_bitmap_layer_set_angle(hourHandLayer, hourAngle);
}
static void draw_watchface(Layer *layer, GContext *ctx) {
	GRect bounds = layer_get_bounds(layer);
	uint16_t width = bounds.size.w - (2 * PADDING);
	uint16_t max_height = bounds.size.h - (2 * PADDING);

	//set the colour
	graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorRed, GColorWhite));	

	//display the seconds
	graphics_fill_rect(ctx, GRect(((s_sec * width)/60) + PADDING, 84 - 10, 2, 19), 0 ,0);

	//display the hours

	//left hours------------------------------ 
	int8_t cur_hours = s_hour % 12;
	if (cur_hours == 0) {
		cur_hours = 12;
	}

	int8_t left_hours = cur_hours;
	if (cur_hours > 6) {
		left_hours = 6;
	}
	GPathInfo HOURS_LEFT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(left_hours*width/12) + 2,0},{(left_hours*width/12) + 2,27},{0,27}}
	};

	GPath *s_hours_path_left = gpath_create(&HOURS_LEFT_PATH_INFO);
	gpath_rotate_to(s_hours_path_left, DEG_TO_TRIGANGLE(-45));
	gpath_move_to(s_hours_path_left, GPoint(3,32 + PADDING));
	gpath_draw_filled(ctx, s_hours_path_left);

	//right hours------------------------------ 
	
	int8_t right_hours = cur_hours;
	if (cur_hours < 6) {
		right_hours = 0;
	} else {
		right_hours = cur_hours - 6;
	}

	GPathInfo HOURS_RIGHT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(right_hours*width/12) + 2,0},{(right_hours*width/12) + 2,27},{0,27}}
	};

	GPath *s_hours_path_right = gpath_create(&HOURS_RIGHT_PATH_INFO);
	gpath_rotate_to(s_hours_path_right, DEG_TO_TRIGANGLE(45));
	gpath_move_to(s_hours_path_right, GPoint(width - 32 + 8, 1));
	gpath_draw_filled(ctx, s_hours_path_right);

	//display the minutes
	
	//left minutes------------------------------ 
	int8_t left_mins = s_min;
	if (s_min > 30) {
		left_mins = 30;
	}

	GPathInfo MINS_LEFT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(left_mins*width/60) + 1,0},{(left_mins*width/60) + 1, 27},{0,27}}
	};
	
	GPath *s_mins_path_left = gpath_create(&MINS_LEFT_PATH_INFO);
	gpath_rotate_to(s_mins_path_left, DEG_TO_TRIGANGLE(45));
	gpath_move_to(s_mins_path_left, GPoint(PADDING + 10, max_height - 32 - 11));
	gpath_draw_filled(ctx, s_mins_path_left);

	//right minutes------------------------------ 
	int8_t right_mins = s_min;
	if (s_min < 30) {
		right_mins = 0;
	} else {
		right_mins = s_min - 30;
	}

	GPathInfo MINS_RIGHT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(right_mins*width/60) + 1,0},{(right_mins*width/60) + 1, 27},{0,27}}
	};

	GPath *s_mins_path_right = gpath_create(&MINS_RIGHT_PATH_INFO);
	gpath_rotate_to(s_mins_path_right, DEG_TO_TRIGANGLE(-45));
	gpath_move_to(s_mins_path_right, GPoint(width - 32 - PADDING + 1, max_height));
	gpath_draw_filled(ctx, s_mins_path_right);
}

static void set_background_color(int color) {
	GColor background_color = GColorFromHEX(color);
	window_set_background_color(window, background_color);
}

static void inbox_received_handler(DictionaryIterator *iter, void *context) {
	APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler");
	Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR);

	if (background_color_t) {
		int background_color = background_color_t->value->int32;
		if (background_color == 0) { //quick fix so that black colour persists
			background_color++;
		}
		persist_write_int(KEY_BACKGROUND_COLOR, background_color);
		set_background_color(background_color);

		APP_LOG(APP_LOG_LEVEL_DEBUG, "background color: %d", background_color);
	}
}

static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);

	s_layer = layer_create(layer_get_bounds(window_get_root_layer(window)));
	layer_add_child(window_get_root_layer(window), s_layer);
	layer_set_update_proc(s_layer, draw_watchface);

	uint16_t width = bounds.size.w - (2 * PADDING);
	uint16_t max_height = bounds.size.h - (2 * PADDING);

	//create the ternary seconds image
	s_ternary_seconds_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SECONDS_TERNARY_REFLECT);
	s_ternary_seconds_layer = bitmap_layer_create(GRect(PADDING, 0, width + 1, 168));
	bitmap_layer_set_background_color(s_ternary_seconds_layer, GColorClear);
	bitmap_layer_set_bitmap(s_ternary_seconds_layer, s_ternary_seconds_bitmap);
	bitmap_layer_set_compositing_mode(s_ternary_seconds_layer, GCompOpSet);
	layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_seconds_layer));

	//create the left hours image
	s_unary_hours_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_6_SINGLE_BLOCKS);
	s_unary_hours_layer_left = rot_bitmap_layer_create(s_unary_hours_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_unary_hours_layer_left, GColorClear);
	rot_bitmap_set_compositing_mode(s_unary_hours_layer_left, GCompOpSet);
	rot_bitmap_layer_set_angle(s_unary_hours_layer_left, DEG_TO_TRIGANGLE(-45));

	//position the frame
	GRect r = layer_get_frame((Layer *) s_unary_hours_layer_left);
	r.origin.x = 2;
	layer_set_frame((Layer *) s_unary_hours_layer_left, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_unary_hours_layer_left);

	//create the right hours image
	s_unary_hours_layer_right = rot_bitmap_layer_create(s_unary_hours_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_unary_hours_layer_right, GColorClear);
	rot_bitmap_set_compositing_mode(s_unary_hours_layer_right, GCompOpSet);
	rot_bitmap_layer_set_angle(s_unary_hours_layer_right, DEG_TO_TRIGANGLE(45));

	//position the frame
	r = layer_get_frame((Layer *) s_unary_hours_layer_right);
	r.origin.x = width - 32 - PADDING; 
	layer_set_frame((Layer *) s_unary_hours_layer_right, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_unary_hours_layer_right);

	//create the left minutes image
	s_ternary_minutes_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_30_TERNARY);	
	s_ternary_minutes_layer_left = rot_bitmap_layer_create(s_ternary_minutes_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_ternary_minutes_layer_left, GColorClear);
	rot_bitmap_set_compositing_mode(s_ternary_minutes_layer_left, GCompOpSet);
	rot_bitmap_layer_set_angle(s_ternary_minutes_layer_left, DEG_TO_TRIGANGLE(45));

	//position the frame
	r = layer_get_frame((Layer *) s_ternary_minutes_layer_left);
	r.origin.x = 2;
	r.origin.y = max_height - 32 - PADDING;
	layer_set_frame((Layer *) s_ternary_minutes_layer_left, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_ternary_minutes_layer_left);

	//create the right minutes image
	s_ternary_minutes_layer_right = rot_bitmap_layer_create(s_ternary_minutes_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_ternary_minutes_layer_right, GColorClear);
	rot_bitmap_set_compositing_mode(s_ternary_minutes_layer_right, GCompOpSet);
	rot_bitmap_layer_set_angle(s_ternary_minutes_layer_right, DEG_TO_TRIGANGLE(-45));

	//position the frame
	r = layer_get_frame((Layer *) s_ternary_minutes_layer_right);
	r.origin.x = width - 32 - PADDING;
	r.origin.y = max_height - 32 - PADDING;
	layer_set_frame((Layer *) s_ternary_minutes_layer_right, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_ternary_minutes_layer_right);

	if (persist_read_int(KEY_BACKGROUND_COLOR)) {
		set_background_color(persist_read_int(KEY_BACKGROUND_COLOR));
	}
}

static void window_unload(Window *window) {
	gbitmap_destroy(s_ternary_seconds_bitmap);
	bitmap_layer_destroy(s_ternary_seconds_layer);

	gbitmap_destroy(s_unary_hours_bitmap);
	rot_bitmap_layer_destroy(s_unary_hours_layer_left);
	rot_bitmap_layer_destroy(s_unary_hours_layer_right);

	gbitmap_destroy(s_ternary_minutes_bitmap);
	rot_bitmap_layer_destroy(s_ternary_minutes_layer_left);
	rot_bitmap_layer_destroy(s_ternary_minutes_layer_right);
}
예제 #6
0
void update_time(struct tm* t) {
  // Find out what needs to be updated
  bool hour_changed = false;
  bool minute_changed = false;
  
  if (last_hour != t->tm_hour) {
    hour_changed = true;
    last_hour = t->tm_hour;
  }
  
  if (last_minute != t->tm_min) {
    minute_changed = true;
    last_minute = t->tm_min;
  }
  
  // Update hour hand
  if (hour_changed) {
    int32_t hour_angle = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360;
    GRect hour_frame = layer_get_frame((Layer*) white_hour_layer);
    hour_frame.origin.x = (144/2) - (hour_frame.size.w/2);  
    hour_frame.origin.y = (168/2) - (hour_frame.size.h/2);
  
    rot_bitmap_layer_set_angle(white_hour_layer, hour_angle);
    layer_set_frame((Layer*) white_hour_layer, hour_frame);
  	layer_mark_dirty((Layer*) white_hour_layer);
    
    rot_bitmap_layer_set_angle(black_hour_layer, hour_angle);
    layer_set_frame((Layer*) black_hour_layer, hour_frame);
  	layer_mark_dirty((Layer*) black_hour_layer);
  }
  
  // Update minute hand
  if (minute_changed) {
    int32_t minute_angle = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360;
    GRect minute_frame = layer_get_frame((Layer*) white_minute_layer);
    minute_frame.origin.x = (144/2) - (minute_frame.size.w/2);  
    minute_frame.origin.y = (168/2) - (minute_frame.size.h/2);
    
    rot_bitmap_layer_set_angle(white_minute_layer, minute_angle);
    layer_set_frame((Layer*) white_minute_layer, minute_frame);
  	layer_mark_dirty((Layer*) white_minute_layer);
    
    rot_bitmap_layer_set_angle(black_minute_layer, minute_angle);
    layer_set_frame((Layer*) black_minute_layer, minute_frame);
  	layer_mark_dirty((Layer*) black_minute_layer);
  }
  
  // Update second hand
  if (seconds == seconds_on) {
    int32_t second_angle = TRIG_MAX_ANGLE * (t->tm_sec * 6) / 360;
    GRect second_frame = layer_get_frame((Layer*) white_second_layer);
    second_frame.origin.x = (144/2) - (second_frame.size.w/2);  
    second_frame.origin.y = (168/2) - (second_frame.size.h/2);
    
    rot_bitmap_layer_set_angle(white_second_layer, second_angle);
    layer_set_frame((Layer*) white_second_layer, second_frame);
  	layer_mark_dirty((Layer*) white_second_layer);
    
    rot_bitmap_layer_set_angle(black_second_layer, second_angle);
    layer_set_frame((Layer*) black_second_layer, second_frame);
  	layer_mark_dirty((Layer*) black_second_layer);
  }
  
  // Update info layer, but not that often
  if ((info == info_on) && (minute_changed)) {    
    if (bluetooth_connection_service_peek())
      text_layer_set_text(bluetooth_layer, "Linked");
    else      
      text_layer_set_text(bluetooth_layer, "Offline");
    
    BatteryChargeState initial = battery_state_service_peek();
    bool battery_plugged = initial.is_plugged;
    uint8_t battery_level = initial.charge_percent;
    
    if (battery_plugged)
	    snprintf(battery_text, sizeof(battery_text), "! %d%%", battery_level);
    else 
	    snprintf(battery_text, sizeof(battery_text), "%d%%", battery_level);
      
    text_layer_set_text(battery_layer, battery_text);
    
    strftime(day_text, sizeof(day_text), "%a", t);
    text_layer_set_text(day_layer, day_text);
    
    strftime(date_text, sizeof(date_text), "%b %e", t);
    text_layer_set_text(date_layer, date_text);
  }
  
  // Update digital time
  if ((digital != digital_off) && (minute_changed)) {
    if (digital == digital_12)
      strftime(digital_text, sizeof(digital_text), "%I:%M %p", t);
    else
      strftime(digital_text, sizeof(digital_text), "%H:%M", t);
    
    text_layer_set_text(digital_layer, digital_text);
  }
}
예제 #7
0
static void set_angle(void *subject, int16_t value) {
  rot_bitmap_layer_set_angle(((Needle*)subject)->layer, value);
  ((Needle*)subject)->angle = value;
}