Source

pebble / mario / src / main.c

Diff from to

mario/src/main.c

 static Window window;
 static Layer layer;
 
+static AppTimerHandle timer_handle;
+#define COOKIE_MY_TIMER 1
+
+
 extern void draw(GContext * gctx);
 
 static void
 
 
 static void
+handle_timer(
+	AppContextRef ctx,
+	AppTimerHandle handle,
+	uint32_t cookie
+)
+{
+	(void)handle;
+
+	if (cookie != COOKIE_MY_TIMER)
+		return;
+
+	layer_mark_dirty(&layer);
+
+	timer_handle = app_timer_send_event(
+		ctx,
+		50 /* milliseconds */,
+		COOKIE_MY_TIMER
+	);
+}
+
+
+static void
 handle_tick(
 	AppContextRef ctx,
 	PebbleTickEvent * const event
 	date_m = ptm->tm_mon + 1;
 	date_d = ptm->tm_mday;
 	date_y = ptm->tm_year;
-
-	layer_mark_dirty(&layer);
 }
 
 
 	window_stack_push(&window, true);
 
 	// Mario Layer
-	layer_init(&layer, GRect(0,0, 128, 64));
+	layer_init(&layer, GRect(0,0, 144, 168));
 	layer.update_proc = layer_update;
 	layer_add_child(&window.layer, &layer);
+
+	timer_handle = app_timer_send_event(
+		ctx,
+		50 /* milliseconds */,
+		COOKIE_MY_TIMER
+	);
 }
 
 
 )
 {
 	PebbleAppHandlers handlers = {
-		.init_handler	= &handle_init,
+		.init_handler	= handle_init,
+		.timer_handler	= handle_timer,
 		.tick_info	= {
-			.tick_handler = &handle_tick,
+			.tick_handler = handle_tick,
 			.tick_units = SECOND_UNIT,
 		},
 	};