Trammell Hudson avatar Trammell Hudson committed 0b0f242

still trying to get proper ms timer resolution

Comments (0)

Files changed (1)

stopwatch/src/stopwatch.c

 #include "pebble_app.h"
 #include "pebble_fonts.h"
 
-PBL_APP_INFO(
+PBL_APP_INFO_SIMPLE(
 	"Stopwatch",
 	"hudson",
-	1, // Version
-	INVALID_RESOURCE,
-	0 // App, not watch face
+	1 // Version
 );
 
 
 
 static int seconds;
 static int miliseconds;
+static int running;
 
 
 static void
 	const unsigned w = me->bounds.size.w;
 	const unsigned h = me->bounds.size.h;
 	static char buf[16];
-	int ms = miliseconds += 1;
+
+	int ms = miliseconds;
 	int s = seconds;
 
 	buf[5] = '\0';
 		28,
 		60
 	);
+}
 
-#if 0
-	const int bar_h = h / run_count;
-	int y = 0;
 
-	graphics_context_set_fill_color(ctx, GColorWhite);
+static void
+schedule_timer(void)
+{
+	if (timer_handle)
+		return;
 
-	for (int i = 0 ; i < interval_count ; i++)
-	{
-		if (intervals[i] < 0)
-			continue;
-
-		int bar_w;
-		if (i < interval)
-			bar_w = 0;
-		else
-		if (i == interval)
-			bar_w = (w * remaining) / intervals[i];
-		else
-			bar_w = w;
-
-		graphics_fill_rect(ctx, GRect(0, y, bar_w, bar_h - 2), 2, GCornersAll);
-		y += bar_h;
-	}
-#endif
+	timer_handle = app_timer_send_event(
+		ctx,
+		100 /* milliseconds */,
+		COOKIE_MY_TIMER
+	);
 }
 
 
 	if (cookie != COOKIE_MY_TIMER)
 		return;
 
-	timer_handle = app_timer_send_event(
-		ctx,
-		100 /* milliseconds */,
-		COOKIE_MY_TIMER
-	);
+	if (running)
+	{
+		miliseconds++;
+
+		schedule_timer();
+	}
 
 	layer_mark_dirty(&layer);
 
 	seconds++;
 	miliseconds = 0;
 	
-	if (!timer_handle)
-		timer_handle = app_timer_send_event(
-			ctx,
-			100 /* milliseconds */,
-			COOKIE_MY_TIMER
-		);
+	schedule_timer();
 
 #if 0
 	if (remaining != 0)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.