Commits

Trammell Hudson  committed bd7a17a

Added CONFIG_SECOND for a second hand

  • Participants
  • Parent commits 40e36ec

Comments (0)

Files changed (1)

File th10/src/th10.c

 #include "pebble_fonts.h"
 #include "pebble_th.h"
 
+#define CONFIG_SECOND
+
+
 #define UUID { 0xDD, 0xD6, 0x07, 0x2A, 0x2D, 0x0B, 0x4D, 0x79, 0x99, 0x6D, 0xDC, 0x69, 0xD4, 0x62, 0xB8, 0x5B }
 
 PBL_APP_INFO(
 static Window window;
 static Layer hand_layer;
 static Layer bg_layer;
+#ifdef CONFIG_SECOND
+static Layer sec_layer;
+#endif
+
 static PblTm now;
 static GFont font_time;
 static GFont font_date;
 	{ -5, -20 },
 };
 
+#ifdef CONFIG_SECOND
+// Second hand
+static GPath sec_path;
+static GPoint sec_points[] = {
+	{ -3, -20 },
+	{ -3, -60 },
+	{  0, -76 },
+	{ +3, -60 },
+	{ +3, -20 },
+	{ -3, -20 },
+};
+#endif
+
+
 // Hour hand ticks around the circle (slightly shorter)
 static GPath hour_tick_path;
 static GPoint hour_tick_points[] = {
 	{ 0, 84 },
 };
 
+
 static void
 hand_layer_update(
         Layer * const me,
 	(void) me;
 
 	// Draw the minute hand outline in black and filled with white
-	int minute_angle = (now.tm_min * TRIG_MAX_ANGLE) / 60;
+	int minute_angle = ((now.tm_min * 60 + now.tm_sec) * TRIG_MAX_ANGLE) / 3600;
 
 	gpath_rotate_to(&minute_path, minute_angle);
 	graphics_context_set_stroke_color(ctx, GColorBlack);
 }
 
 
+#ifdef CONFIG_SECOND
+static void
+sec_layer_update(
+        Layer * const me,
+        GContext * ctx
+)
+{
+	(void) me;
+
+	// Draw the second hand outline in black and filled with white
+	int sec_angle = (now.tm_sec * TRIG_MAX_ANGLE) / 60;
+
+	gpath_rotate_to(&sec_path, sec_angle);
+	graphics_context_set_stroke_color(ctx, GColorBlack);
+	gpath_draw_outline(ctx, &sec_path);
+	graphics_context_set_fill_color(ctx, GColorWhite);
+	gpath_draw_filled(ctx, &sec_path);
+}
+#endif
+
+
 /** Called once per minute */
 static void
 handle_tick(
 	GPATH_INIT(&minute_path, minute_points);
 	gpath_move_to(&minute_path, GPoint(W/2,H/2));
 
+#ifdef CONFIG_SECOND
+	GPATH_INIT(&sec_path, sec_points);
+	gpath_move_to(&sec_path, GPoint(W/2,H/2));
+#endif
+
 	GPATH_INIT(&major_tick_path, major_tick_points);
 	gpath_move_to(&major_tick_path, GPoint(W/2,H/2));
 
 	layer_add_child(&window.layer, &hand_layer);
 	hand_layer.update_proc = hand_layer_update;
 	layer_mark_dirty(&hand_layer);
+
+#ifdef CONFIG_SECOND
+	layer_init(&sec_layer, GRect(0, 0, W, H));
+	layer_add_child(&window.layer, &sec_layer);
+	sec_layer.update_proc = sec_layer_update;
+	layer_mark_dirty(&sec_layer);
+#endif
 }
 
 
 		.deinit_handler = &handle_deinit,
 		.tick_info	= {
 			.tick_handler = &handle_tick,
-			.tick_units = MINUTE_UNIT,
+#ifdef CONFIG_SECOND
+			.tick_units = SECOND_UNIT,
+#else
+			.tick_units = SECOND_MINUTE,
+#endif
 		},
 	};