Trammell Hudson avatar Trammell Hudson committed 839602b

started on interval timer

Comments (0)

Files changed (2)

interval/src/Makefile

+#
+# Interval timing for jogging
+#
+
+APP := interval
+
+SRCS += interval.c
+
+include ../../Makefile.pebble

interval/src/interval.c

+/** \file
+ * Interval timer
+ */
+#include "pebble_os.h"
+#include "pebble_app.h"
+#include "pebble_fonts.h"
+
+PBL_APP_INFO(
+	"Intervals",
+	"hudson",
+	1, // Version
+	INVALID_RESOURCE,
+	APP_INFO_WATCH_FACE
+);
+
+
+static Window window;
+static TextLayer time_layer;
+static TextLayer remaining_layer;
+static Layer line_layer;
+static char time_buffer[12];
+static char remaining_buffer[12];
+
+static int remaining = 120;
+
+
+static void
+layer_update(
+	Layer * const me,
+	GContext * ctx
+)
+{
+#if 0
+	// Draw a white rectangle across the entire bottom
+	const unsigned w = me->bounds.size.w;
+	const unsigned h = me->bounds.size.h;
+	graphics_context_set_fill_color(ctx, GColorWhite);
+	graphics_fill_rect(ctx, GRect(0, 0, w, h), 0, GCornersAll);
+
+	graphics_context_set_fill_color(ctx, GColorBlack);
+	graphics_fill_rect(ctx, GRect(0, 0, (w * remaining) / 30, h), 4, GCornersRight);
+#endif
+}
+
+
+static void
+handle_tick(
+	AppContextRef ctx,
+	PebbleTickEvent * const event
+)
+{
+	(void) ctx;
+	const PblTm * const ptm = event->tick_time;
+
+	string_format_time(
+		time_buffer,
+		sizeof(time_buffer),
+		"%H:%M:%S",
+		ptm
+	);
+
+	text_layer_set_text(&time_layer, time_buffer);
+
+	if (remaining != 0)
+		remaining--;
+
+	remaining_buffer[0] = '0' + (remaining / 100) % 10;
+	remaining_buffer[1] = '0' + (remaining / 10) % 10;
+	remaining_buffer[2] = '0' + (remaining / 1) % 10;
+	remaining_buffer[3] = '\0';
+
+	text_layer_set_text(&remaining_layer, remaining_buffer);
+}
+
+
+static void
+handle_init(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	window_init(&window, "Odometer");
+	window_stack_push(&window, true);
+	window_set_background_color(&window, GColorBlack);
+
+	resource_init_current_app(&RESOURCES);
+
+
+	text_layer_init(&time_layer, GRect(10,10,134,30));
+	text_layer_init(&remaining_layer, GRect(10,40,134,30));
+
+	text_layer_set_text_color(&time_layer, GColorWhite);
+	text_layer_set_text_color(&remaining_layer, GColorWhite);
+        text_layer_set_background_color(&time_layer, GColorClear);
+        text_layer_set_background_color(&remaining_layer, GColorClear);
+
+	text_layer_set_text(&time_layer, "");
+	text_layer_set_text(&remaining_layer, "");
+
+	text_layer_set_font(&time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
+	text_layer_set_font(&remaining_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
+
+	layer_add_child(&window.layer, &time_layer.layer);
+	layer_add_child(&window.layer, &remaining_layer.layer);
+
+#if 0
+	// Bargraph layer is across the bottom
+	const unsigned bargraph_height = 20;
+	layer_init(&bargraph_layer, GRect(0,168-bargraph_height-15,144,bargraph_height));
+	bargraph_layer.update_proc = bargraph_layer_update;
+
+	layer_add_child(&window.layer, &bargraph_layer);
+#endif
+}
+
+
+void
+pbl_main(
+	void * const params
+)
+{
+	PebbleAppHandlers handlers = {
+		.init_handler	= handle_init,
+		.tick_info	= {
+			.tick_handler = handle_tick,
+			.tick_units = SECOND_UNIT,
+		},
+	};
+
+	app_event_loop(params, &handlers);
+}
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.