Commits

Trammell Hudson committed 0ffb32e Merge

Merged; need to update to hb002

  • Participants
  • Parent commits a41923c, cd369d8

Comments (0)

Files changed (6)

 # and GCC_PREFIX to point to your arm-none-eabi gcc tree.
 # Otherwise it should "just work".
 #
-PEBBLE_HOME := $(HOME)/build/pebble/sdk
+#PEBBLE_HOME := $(HOME)/build/pebble/sdk
+PEBBLE_HOME := $(HOME)/build/pebble/pebble-sdk-release-hb002/sdk
 ARM_GCC_PATH := $(HOME)/arm-cs-tools/bin
 GCC_PREFIX := $(ARM_GCC_PATH)/arm-none-eabi-
 export PATH := $(ARM_GCC_PATH):$(PATH)

hoelaat/src/nederlands.c

 #include "pebble_fonts.h"
 
 static Window window;
+static GFont font_thin;
+static GFont font_thick;
 
-static const char * min_text;
-static const char * rel_text;
-static const char * hour_text;
-static const char * ampm_text;
+typedef struct
+{
+	TextLayer layer;
+	PropertyAnimation anim;
+	const char * text;
+	const char * old_text;
+} word_t;
 
-static TextLayer min_layer;
-static TextLayer rel_layer;
-static TextLayer hour_layer;
-static TextLayer ampm_layer;
+static word_t min_word;
+static word_t rel_word;
+static word_t hour_word;
+static word_t ampm_word;
+
 
 static const char *nums[] = {
 	"",
 	int h
 )
 {
-	if (h == 0 || h == 24)
+	// only if it is actually midnight, not "before midnight"
+	if (h == 0)
 		return "midder-\nnacht";
 
 	if (h == 12)
 {
 	if (min == 0)
 	{
-		min_text = "";
-		rel_text = "";
+		min_word.text = "";
+		rel_word.text = "";
 	} else
 	if (min <= 15)
 	{
 		// over the hour
-		min_text = min_string(min);
-		rel_text = "over";
+		min_word.text = min_string(min);
+		rel_word.text = "over";
 	} else
 	if (min < 30)
 	{
 		// over the kwart
-		min_text = min_string(30 - min);
-		rel_text = "voor half";
+		min_word.text = min_string(30 - min);
+		rel_word.text = "voor half";
 		hour++;
 	} else
 	if (min == 30)
 	{
 		// just the half
-		min_text = "";
-		rel_text = "half";
+		min_word.text = "";
+		rel_word.text = "half";
 		hour++;
 	} else
 	if (min < 45)
 	{
 		// over the half
-		min_text = min_string(min - 30);
-		rel_text = "over half";
+		min_word.text = min_string(min - 30);
+		rel_word.text = "over half";
 		hour++;
 	} else
 	if (min == 45)
 	{
 		// just the kwart
-		min_text = "";
-		rel_text = "kwart voor";
+		min_word.text = "";
+		rel_word.text = "kwart voor";
 		hour++;
 	} else
 	if (min < 60)
 	{
 		// over the kwart
-		min_text = min_string(60 - min);
-		rel_text = "voor";
+		min_word.text = min_string(60 - min);
+		rel_word.text = "voor";
 		hour++;
 	}
 
-	hour_text = hour_string(hour);
+	hour_word.text = hour_string(hour);
 
 	// at midnight and noon do not display an am/pm notation
-	if (hour == 0 || hour == 12 || hour == 24)
+	// but don't say "before midnight"
+	if (hour == 0 || hour == 12)
 	{
 		// nothing to do
-		ampm_text = "";
+		ampm_word.text = "";
 	} else
-	if (hour <= 6)
-		ampm_text = "'s nachts";
+	if (hour < 6)
+		ampm_word.text = "'s nachts";
 	else
 	if (hour <= 12)
-		ampm_text = "'s morgens";
+		ampm_word.text = "'s morgens";
 	else
 	if (hour <= 17)
-		ampm_text = "'s middags";
+		ampm_word.text = "'s middags";
 	else
 	if (hour <= 24)
-		ampm_text = "'s avonds";
+		ampm_word.text = "'s avonds";
 }
 
 
 PBL_APP_INFO(
 	"Hoe laat is het?",
 	"hudson",
-	1, // Version
+	2, // Version
 	RESOURCE_ID_IMAGE_MENU_ICON,
 	APP_INFO_WATCH_FACE
 );
 
 
 
+static void
+update_word(
+	word_t * const word
+)
+{
+	text_layer_set_text(&word->layer, word->text);
+	if (word->text != word->old_text)
+		animation_schedule(&word->anim.animation);
+}
+
+
 /** Called once per minute */
 static void
 handle_tick(
 	int hour = ptm->tm_hour;
 	int min = ptm->tm_min;
 
-	const char * old_min = min_text;
-	const char * old_rel = rel_text;
-	const char * old_hour = hour_text;
-	const char * old_ampm = ampm_text;
+	ampm_word.old_text = ampm_word.text;
+	hour_word.old_text = hour_word.text;
+	rel_word.old_text = rel_word.text;
+	min_word.old_text = min_word.text;
 
 	nederlands_format(hour,  min);
 
 	);
 */
 
-	text_layer_set_text(&ampm_layer, ampm_text);
-	text_layer_set_text(&hour_layer, hour_text);
-	text_layer_set_text(&rel_layer, rel_text);
-	text_layer_set_text(&min_layer, min_text);
+	update_word(&ampm_word);
+	update_word(&hour_word);
+	update_word(&rel_word);
+	update_word(&min_word);
 }
 
 
 static void
 text_layer(
-	TextLayer * layer,
+	word_t * word,
 	GRect frame,
-	int font
+	GFont font
 )
 {
-	text_layer_init(layer, frame);
-	text_layer_set_text(layer, "");
-	text_layer_set_text_color(layer, GColorWhite);
-	text_layer_set_background_color(layer, GColorClear);
-	text_layer_set_font(layer, fonts_load_custom_font(resource_get_handle(font)));
+	text_layer_init(&word->layer, frame);
+	text_layer_set_text(&word->layer, "");
+	text_layer_set_text_color(&word->layer, GColorWhite);
+	text_layer_set_background_color(&word->layer, GColorClear);
+	text_layer_set_font(&word->layer, font);
 
-	layer_add_child(&window.layer, &layer->layer);
+	layer_add_child(&window.layer, &word->layer.layer);
+
+	GRect frame_right = frame;
+	frame_right.origin.x = 150;
+
+	property_animation_init_layer_frame(
+		&word->anim,
+		&word->layer.layer,
+		&frame_right,
+		&frame
+	);
+
+	animation_set_duration(&word->anim.animation, 500);
+	animation_set_curve(&word->anim.animation, AnimationCurveEaseIn);
 }
 
 
 	int y = 15;
 	int h = 30;
 
+	font_thin = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_28));
+	font_thick = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_BLACK_30));
+
 	// Stack top to bottom.  Note that the hour can take up
 	// two rows at midnight.
-	text_layer(&ampm_layer, GRect(4, y + 3*h, 144, h+8), RESOURCE_ID_FONT_ARIAL_28);
-	text_layer(&hour_layer, GRect(4, y + 2*h, 144, 2*h+8), RESOURCE_ID_FONT_ARIAL_BLACK_30);
-	text_layer(&rel_layer, GRect(4, y + 1*h, 144, h+8), RESOURCE_ID_FONT_ARIAL_28);
-	text_layer(&min_layer, GRect(4, y + 0*h, 144, h+8), RESOURCE_ID_FONT_ARIAL_28);
+	text_layer(&ampm_word, GRect(4, y + 3*h, 144, h+8), font_thin);
+	text_layer(&hour_word, GRect(4, y + 2*h, 144, 2*h+8), font_thick);
+	text_layer(&rel_word, GRect(4, y + 1*h, 144, h+8), font_thin);
+	text_layer(&min_word, GRect(4, y + 0*h, 144, h+8), font_thin);
+
+}
+
+
+static void
+handle_deinit(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	fonts_unload_custom_font(font_thin);
+	fonts_unload_custom_font(font_thick);
 }
 
 
 {
 	PebbleAppHandlers handlers = {
 		.init_handler	= &handle_init,
+		.deinit_handler = &handle_deinit,
 		.tick_info	= {
 			.tick_handler = &handle_tick,
 			.tick_units = MINUTE_UNIT,

stopwatch/src/Makefile

+#
+# Stop watch functions
+#
+
+APP := stopwatch
+
+SRCS += stopwatch.c
+
+include ../../Makefile.pebble

stopwatch/src/stopwatch.c

+/** \file
+ * Stopwatch display
+ */
+#include "pebble_os.h"
+#include "pebble_app.h"
+#include "pebble_fonts.h"
+
+PBL_APP_INFO(
+	"Stopwatch",
+	"hudson",
+	1, // Version
+	INVALID_RESOURCE,
+	0 // App, not watch face
+);
+
+
+static Window window;
+static TextLayer time_layer;
+//static TextLayer elapsed_layer;
+static Layer layer;
+static char time_buffer[12];
+static char remaining_buffer[12];
+static GFont big_font;
+
+static AppTimerHandle timer_handle;
+#define COOKIE_MY_TIMER 1
+
+static int seconds;
+static int miliseconds;
+
+
+static void
+monospace_text(
+	GContext * ctx,
+	const char * buf,
+	GFont font,
+	GPoint xy,
+	int x_size,
+	int y_size
+)
+{
+	while (1)
+	{
+		const char c = *buf++;
+		char str[2] = { c, '\0' };
+
+		if (c == '\0')
+			break;
+
+		graphics_text_draw(
+			ctx,
+			str,
+			font,
+			GRect(xy.x, xy.y, x_size, y_size),
+			GTextOverflowModeTrailingEllipsis,
+			GTextAlignmentRight,
+			NULL
+		);
+
+		xy.x += x_size;
+	}
+}
+
+
+/**
+ */
+static void
+layer_update(
+	Layer * const me,
+	GContext * ctx
+)
+{
+	const unsigned w = me->bounds.size.w;
+	const unsigned h = me->bounds.size.h;
+	static char buf[16];
+	int ms = miliseconds += 1;
+	int s = seconds;
+
+	buf[5] = '\0';
+	buf[4] = ('0' + ms % 10); ms /= 10;
+	buf[3] = ('0' + s % 10); s /= 10;
+	buf[2] = ('0' + s % 10); s /= 10;
+	buf[1] = ('0' + s % 10); s /= 10;
+	buf[0] = ('0' + s % 10); s /= 10;
+
+	monospace_text(
+		ctx,
+		buf,
+		big_font,
+		GPoint(0,0),
+		28,
+		60
+	);
+
+#if 0
+	const int bar_h = h / run_count;
+	int y = 0;
+
+	graphics_context_set_fill_color(ctx, GColorWhite);
+
+	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
+}
+
+
+static void
+handle_timer(
+	AppContextRef ctx,
+	AppTimerHandle handle,
+	uint32_t cookie
+)
+{
+	(void)handle;
+
+	if (cookie != COOKIE_MY_TIMER)
+		return;
+
+	timer_handle = app_timer_send_event(
+		ctx,
+		100 /* milliseconds */,
+		COOKIE_MY_TIMER
+	);
+
+	layer_mark_dirty(&layer);
+
+}
+
+
+
+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);
+
+	seconds++;
+	miliseconds = 0;
+	
+	if (!timer_handle)
+		timer_handle = app_timer_send_event(
+			ctx,
+			100 /* milliseconds */,
+			COOKIE_MY_TIMER
+		);
+
+#if 0
+	if (remaining != 0)
+		remaining--;
+	else
+	if (interval < interval_count-1)
+	{
+		remaining = intervals[++interval];
+		if (remaining < 0)
+		{
+			remaining = -remaining;
+			walk = 1;
+			vibes_long_pulse();
+		} else {
+			walk = 0;
+			vibes_double_pulse();
+		}
+	}
+
+	int min = remaining / 60;
+	int sec = remaining % 60;
+
+	if (walk)
+	{
+		text_layer_set_text_color(&elapsed_layer, GColorBlack);
+		text_layer_set_background_color(&elapsed_layer, GColorWhite);
+	} else {
+		text_layer_set_text_color(&elapsed_layer, GColorWhite);
+		text_layer_set_background_color(&elapsed_layer, GColorClear);
+	}
+
+	remaining_buffer[0] = '0' + (min / 10) % 10;
+	remaining_buffer[1] = '0' + (min / 1) % 10;
+	remaining_buffer[2] = ':';
+	remaining_buffer[3] = '0' + (sec / 10) % 10;
+	remaining_buffer[4] = '0' + (sec / 1) % 10;
+	remaining_buffer[5] = '\0';
+
+	text_layer_set_text(&elapsed_layer, remaining_buffer);
+#endif
+}
+
+
+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(30,-3,100,30));
+	text_layer_set_text_color(&time_layer, GColorWhite);
+        text_layer_set_background_color(&time_layer, GColorClear);
+	text_layer_set_text(&time_layer, "");
+	text_layer_set_font(&time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
+
+	big_font = fonts_get_system_font(FONT_KEY_GOTHAM_42_LIGHT);
+
+#if 0
+	text_layer_init(&elapsed_layer, GRect(7,26,132,44));
+	text_layer_set_text(&elapsed_layer, "");
+
+	text_layer_set_font(&elapsed_layer, fonts_get_system_font(FONT_KEY_GOTHAM_42_BOLD));
+#endif
+
+	// Layer to draw the bargraphs
+	layer_add_child(&window.layer, &time_layer.layer);
+	//layer_add_child(&window.layer, &elapsed_layer.layer);
+
+	layer_init(&layer, GRect(0,70,144,168-70));
+	layer.update_proc = layer_update;
+
+	layer_add_child(&window.layer, &layer);
+}
+
+
+static void
+handle_deinit(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+}
+
+
+void
+pbl_main(
+	void * const params
+)
+{
+	PebbleAppHandlers handlers = {
+		.init_handler	= handle_init,
+		.deinit_handler	= handle_deinit,
+		.timer_handler	= handle_timer,
+		.tick_info	= {
+			.tick_handler = handle_tick,
+			.tick_units = SECOND_UNIT,
+		},
+	};
+
+	app_event_loop(params, &handlers);
+}

words/src/words.c

 
 	// Fillers
 	[LAYER_FILLER] =
-	{  0, 2, "z", "z" },
+	{  0, 2, "o", "z" },
 	{  0, 5, "apebble", "apebble" },
-	{  1, 1, "t", "t" },
-	{  2, 0, "k", "k" },
-	{  2, 7, "n", "n" },
+	{  1, 1, "T", "t" },
+	{  2, 0, "K", "k" },
+	{  2, 7, "N", "n" },
 	{  3, 4, "B", "o" },
 	{  3, 11, "F", "f" },
 	{  6, 3, "E", "e" },
 	{  7, 11, "S", "s" },
-	{  8, 5, "h", "h" },
+	{  8, 5, "H", "h" },
 };
 
 #define WORD_COUNT ((sizeof(words) / sizeof(*words)))
 
 	text_layer_set_text(
 		layer,
-		on ? w->text_on : w->text_off
+		 w->text_on
 	);
 
 	text_layer_set_font(

worldmap/src/fonts/SourceCodePro-Light.otf

+../../../words/src/fonts/SourceCodePro-Light.otf