Commits

Trammell Hudson committed 6f851cb Merge

merged

  • Participants
  • Parent commits 0b0f242, a3ef683

Comments (0)

Files changed (16)

 dc01cb57c35db5de2a518d61dccc0ed28af2b3b5 makefile-works
 0772e0fc674ce4418228827c51df65037864b2ab qlock2-clone
+29fb3fabe7af1023a36bb1a9235c52e2768d94fe before-release-001-b1
+DIRS += lib
 DIRS += hoelaat
 DIRS += auth
 DIRS += mario
 DIRS += words
 DIRS += cst
+DIRS += calendar
+DIRS += interval
+DIRS += worldmap
 
 all: $(DIRS)
 

File Makefile.pebble

 # Otherwise it should "just work".
 #
 #PEBBLE_HOME := $(HOME)/build/pebble/sdk
-PEBBLE_HOME := $(HOME)/build/pebble/pebble-sdk-release-hb002/sdk
+PEBBLE_HOME := $(HOME)/build/pebble/pebble-sdk-release-001-b1/sdk
 ARM_GCC_PATH := $(HOME)/arm-cs-tools/bin
 GCC_PREFIX := $(ARM_GCC_PATH)/arm-none-eabi-
 export PATH := $(ARM_GCC_PATH):$(PATH)
 LD := $(CC)
 OBJCOPY := $(GCC_PREFIX)objcopy
 SIZE := $(GCC_PREFIX)size
+AR := $(GCC_PREFIX)ar
 PYTHON := python
 
 # If no version is specified, use a default one
 VERSION ?= 0.1
 APP ?= pebble-app
 
+# TOP is the location with of this build tree
+TOP := $(dir $(lastword $(MAKEFILE_LIST)))
+
+# Our custom Pebble library shared with all our watch faces
+LIBPEBBLE_TH := $(TOP)lib/build/libpebble_th.a
+
 
 # Helper macros
 map = $(foreach f,$2,$(call $1,$f))
 	-fPIE \
 	-I$(PEBBLE_HOME)/include \
 	-I. \
-	-I../../common \
+	-I../../lib/src \
 	-I$O \
 	-DNDEBUG \
 	-Wp,-MMD,$(dir $@).$(notdir $@).d \
 	-L$(PEBBLE_HOME)/lib \
 	-lpebble \
 
+BUILD_TIME := $(shell date "+%s")
+
+ifeq ($(LIB),)
+# Force all executables to depend on our pebble library
+all: $O/$(APP).pbw
+else
+# Libraries do not depend on anything external
+all: $O/$(LIB)
+endif
+
 
 #
 # Convert the elf file to a binary file, with
 # the appended Pebble metadata.
 #
-%.bin: %.elf
+$O/pebble-app.bin: $O/pebble-app.elf
 	$(OBJCOPY) -O binary $< $@
 	$(PYTHON) $(PEBBLE_HOME)/waftools/inject_metadata.py $@
 
 # 
 # Bundle the binary (with pebble meta data) into an application.
 #
-BUILD_TIME := $(shell date "+%s")
 
-%.pbw: %.bin
+# Final step to link everything into the PBW file
+$O/$(APP).pbw: $O/pebble-app.bin
 	$(PYTHON) $(PEBBLE_HOME)/tools/mkbundle.py \
 		--watchapp $< \
 		--watchapp-timestamp $(BUILD_TIME) \
 		-o $@ \
 		-v \
 
-all: $O/$(APP).pbw
+
 
 #
 # Generate the list of object files from the SRCS list.
 
 $(foreach f,$(SRCS),$(call add_srcs,$f,$O/$(notdir $(f:.c=.o))))
 
+ifeq ($(LIB),)
+# Only build resource_ids.auto.h if we are making an application
 $(OBJS): $O/src/resource_ids.auto.h
+
 #$(eval $(info OBJS=$(OBJS)))
 
 $O/$(APP).pbw: $O/app_resources.pbpack
-$O/$(APP).elf: $(OBJS)
+$O/pebble-app.elf: $(OBJS) $(LIBPEBBLE_TH)
 	$(LD) \
 		$(LDFLAGS) \
 		-o $@ \
 		$(LDLIBS)
 	$(SIZE) $@
 
+$(LIBPEBBLE_TH):
+	$(MAKE) -C $(dir $(LIBPEBBLE_TH))../src
+
+else
+# Libraries do not use resources, but do need to link everything together
+$O/$(LIB): $(OBJS)
+	$(RM) $@
+	$(AR) \
+		crv \
+		$@ \
+		$^
+	$(SIZE) $@
+endif
+
 $O/%.o:
 	$(CC) $(CFLAGS) -c -o $@ $<
 

File auth/src/totp.c

 #include "pebble_fonts.h"
 #include "sha1.h"
 
+#define UUID {0x24, 0x15, 0x2D, 0xAE, 0xDD, 0x49, 0x47, 0x47, 0x96, 0xD5, 0x78, 0xB1, 0xDD, 0xBD, 0x1B, 0xB2}
+
 PBL_APP_INFO(
+	UUID,
 	"2wo Factor",
 	"hudson",
-	1, // Version
+	2, 0, // Version
 	INVALID_RESOURCE,
 	APP_INFO_WATCH_FACE
 );

File calendar/src/main.c

 #include <pebble_app.h>
 #include <pebble_fonts.h>
 
+
+#define UUID {0xA4, 0x8B, 0x43, 0x03, 0xFA, 0x4F, 0x4F, 0xF2, 0xBB, 0x49, 0x3E, 0xA2, 0x38, 0x91, 0x57, 0xE0}
+
 PBL_APP_INFO(
+	UUID,
 	"Calendar",
 	"hudson",
-	1, // Version
+	2, 0, // Version
 	RESOURCE_ID_IMAGE_MENU_ICON,
 	APP_INFO_WATCH_FACE
 );
 #define FONT_W 7
 #define ROWS 8
 #define COLS 7
-#define FONT_OFF	RESOURCE_ID_FONT_SOURCECODEPRO_LIGHT_18
+#define FONT_OFF	RESOURCE_ID_FONT_SOURCECODEPRO_LIGHT_16
 static GFont font_off;
 
 static Window window;

File cst/src/cst.c

 #include <pebble_os.h>
 #include <pebble_app.h>
 #include <pebble_fonts.h>
+#include <pebble_th.h>
+
+#define UUID {0x7F, 0x58, 0x4D, 0xD7, 0x32, 0xC7, 0x49, 0x65, 0x8B, 0xD6, 0x6F, 0xCE, 0x06, 0x82, 0x2B, 0xA2}
 
 PBL_APP_INFO(
+	UUID,
 	"CST Style",
 	"hudson",
-	1, // Version
+	2, 0, // Version
 	RESOURCE_ID_IMAGE_MENU_ICON,
 	APP_INFO_WATCH_FACE
 );
 
 static Window window;
 
+static GFont font_big;
+static GFont font_small;
+
 static char time_text[8];
 static char date_text[16];
 
 
 
 static void
-text_layer(
-	TextLayer * layer,
-	GRect frame,
-	int 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)));
-
-	layer_add_child(&window.layer, &layer->layer);
-}
-
-
-static void
 handle_init(
 	AppContextRef ctx
 )
 	int y = 15;
 	int h = 30;
 
+	font_big  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CST_BLACK_32));
+	font_small  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CST_LIGHT_15));
+
 	// Stack top to bottom.  Note that the hour can take up
 	// two rows at midnight.
-	text_layer(
+	text_layer_setup(
+		&window,
 		&time_layer,
 		GRect(0, 80, 144, 168),
-		RESOURCE_ID_FONT_CST_BLACK_32
+		font_big
 	);
 
-	text_layer(
+	text_layer_setup(
+		&window,
 		&date_layer,
 		GRect(0, 120, 144, 40),
-		RESOURCE_ID_FONT_CST_LIGHT_15
+		font_small
 	);
 
-	text_layer(
+	text_layer_setup(
+		&window,
 		&day_layer,
 		GRect(0, 140, 144, 40),
-		RESOURCE_ID_FONT_CST_LIGHT_15
+		font_small
 	);
 }
 
 
+static void
+handle_deinit(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	fonts_unload_custom_font(font_big);
+	fonts_unload_custom_font(font_small);
+}
+
+
 void
 pbl_main(
 	void * const params
 {
 	PebbleAppHandlers handlers = {
 		.init_handler	= &handle_init,
+		.deinit_handler	= &handle_deinit,
 		.tick_info	= {
 			.tick_handler = &handle_tick,
 			.tick_units = MINUTE_UNIT,

File hoelaat/src/nederlands.c

 #include "pebble_os.h"
 #include "pebble_app.h"
 #include "pebble_fonts.h"
+#include "pebble_th.h"
+
+#define UUID { 0x5D, 0xBE, 0xBB, 0x58, 0x3C, 0xF4, 0x4C, 0xAF, 0xB4, 0xAC, 0x02, 0x44, 0xA2, 0x64, 0x40, 0x37 },
+PBL_APP_INFO(
+	UUID,
+	"Hoe laat is het?",
+	"hudson",
+	3, 0, // Version
+	RESOURCE_ID_IMAGE_MENU_ICON,
+	APP_INFO_WATCH_FACE
+);
+
+
 
 static Window window;
 static GFont font_thin;
 }
 
 
-PBL_APP_INFO(
-	"Hoe laat is het?",
-	"hudson",
-	2, // Version
-	RESOURCE_ID_IMAGE_MENU_ICON,
-	APP_INFO_WATCH_FACE
-);
-
-
-
 static void
 update_word(
 	word_t * const word
 	GFont 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, &word->layer.layer);
+	text_layer_setup(&window, &word->layer, frame, font);
 
 	GRect frame_right = frame;
 	frame_right.origin.x = 150;

File interval/src/interval.c

 #include "pebble_app.h"
 #include "pebble_fonts.h"
 
+#define UUID {0xB5, 0xF1, 0xBC, 0xE4, 0x7B, 0x0F, 0x47, 0xBB, 0xAC, 0x8B, 0x94, 0xA2, 0x50, 0xEF, 0xCD, 0x5F}
+
 PBL_APP_INFO(
+	UUID,
 	"Intervals",
 	"hudson",
-	1, // Version
+	2, 0, // Version
 	INVALID_RESOURCE,
-	APP_INFO_WATCH_FACE
+	APP_INFO_WATCH_FACE // should be an APP
 );
 
 

File lib/src/Makefile

+#
+# Library for common functions in watch faces and apps.
+#
+
+SRCS += \
+	sprintf.c \
+	layer.c \
+
+LIB := libpebble_th.a
+
+include ../../Makefile.pebble

File lib/src/layer.c

+/** \file
+ * Text layer management.
+ */
+
+#include "pebble_th.h"
+
+void
+text_layer_setup(
+	Window * window,
+	TextLayer * layer,
+	GRect frame,
+	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, font);
+        layer_add_child(&window->layer, &layer->layer);
+}
+
+
+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;
+	}
+}

File lib/src/pebble_th.h

+/** \file
+ * Functions in libpblth.a.
+ */
+#ifndef _pblth_h_
+#define _pblth_h_
+
+#include <stdint.h>
+#include "pebble_os.h"
+
+
+extern int
+__attribute__((__format__(printf, 2, 3)))
+pebble_sprintf(
+	char * buf,
+	const char * fmt,
+	...
+);
+
+
+extern void
+text_layer_setup(
+	Window * window,
+	TextLayer * layer,
+	GRect frame,
+	GFont font
+);
+
+
+void
+monospace_text(
+	GContext * ctx,
+	const char * buf,
+	GFont font,
+	GPoint xy,
+	int x_size,
+	int y_size
+);
+
+#endif

File lib/src/sprintf.c

+/** \file
+ * Simple version of sprintf to avoid bringing in all of libc.
+ *
+ * Only supported: %d, %s, %x
+ */
+//#include <stdio.h>
+#include <stdarg.h>
+#include "pebble_th.h"
+
+
+static int
+fmt_int(
+	char * buf,
+	unsigned x,
+	int base,
+	int width,
+	int leading_zero
+)
+{
+	(void) width;
+	(void) leading_zero;
+
+	char tmp[16];
+	int offset = 0;
+	do {
+		int digit;
+		if (base == 16)
+		{
+			digit = x % 16;
+			x /= 16;
+		} else
+		//if (base == 10) // do it always
+		{
+			digit = x % 10;
+			x /= 10;
+		}
+
+		char c;
+		if (digit >=  0xA)
+			c = digit + 'A' - 0xA;
+		else
+			c = digit + '0';
+
+		tmp[offset++] = c;
+	} while (x);
+
+	tmp[offset] = '\0';
+
+	// reverse it into place
+	int i;
+	for (i = 0 ; i < offset ; i++)
+		buf[i] = tmp[offset - i - 1];
+
+	return offset;
+}
+
+
+int
+pebble_sprintf(
+	char * buf,
+	const char * fmt,
+	...
+)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	int offset = 0;
+
+	while (1)
+	{
+		const char c = *fmt++;
+		if (c == '\0')
+			break;
+		if (c != '%')
+		{
+			buf[offset++] = c;
+			continue;
+		}
+
+		// Look for a digit
+		int leading_zero = 0;
+		int width = 0;
+
+		char n = *fmt;
+		if ('0' <= n && n <= '9')
+		{
+			if (n == '0')
+			{
+				leading_zero = 1;
+				n = *++fmt;
+			}
+
+			while ('0' <= n && n <= '9')
+			{
+				width = width * 10 + n - '0';
+				n = *++fmt;
+			}
+		}
+
+		// width and leading zero are set.
+		// fmt now points at the type
+		const char type = *fmt++;
+
+		switch (type)
+		{
+		case 's':
+		{
+			// Width and zero are ignored for now
+			const char * s = va_arg(ap, const char *);
+			while (1)
+			{
+				const char c = *s++;
+				if (c == '\0')
+					break;
+				buf[offset++] = c;
+			}
+			break;
+		}
+
+		case 'd':
+		{
+			const int x = va_arg(ap, int);
+			offset += fmt_int(buf + offset, x, 10, width, leading_zero);
+			break;
+		}
+		case 'x':
+		{
+			const int x = va_arg(ap, int);
+			offset += fmt_int(buf + offset, x, 16, width, leading_zero);
+			break;
+		}
+		case '%':
+			buf[offset++] = '%';
+			break;
+		default:
+		{
+			va_arg(ap, int);
+			buf[offset++] = '?';
+			break;
+		}
+		}
+	}
+
+	va_end(ap);
+
+	buf[offset] = '\0';
+	return offset;
+}
+
+#if 0
+int main(void)
+{
+	char buf[64];
+
+	pebble_sprintf(buf, "hello: foo %s %% %d 0x%x 0x%08x\n",
+		"bar",
+		123,
+		0x9999,
+		0xdeadbeef
+	);
+
+	printf("%s", buf);
+	return 0;
+}
+#endif

File mario/src/main.c

 #include <stdint.h>
 #include <math.h>
 
+#define UUID {0x0A, 0xCE, 0x42, 0x1B, 0x8B, 0xDF, 0x4F, 0x61, 0xBC, 0x50, 0x2C, 0x85, 0x36, 0xC8, 0xA4, 0x20}
+
 PBL_APP_INFO(
+	UUID,
 	"MarioChron",
 	"hudson",
-	1, // Version
+	2, 0, // Version
 	RESOURCE_ID_IMAGE_MENU_ICON,
 	APP_INFO_WATCH_FACE
 );

File stopwatch/src/stopwatch.c

 static int running;
 
 
-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

File words/src/words.c

 #include <pebble_os.h>
 #include <pebble_app.h>
 #include <pebble_fonts.h>
+#include "pebble_th.h"
+
+#define UUID {0x82, 0xA1, 0x47, 0x0E, 0x48, 0xFF, 0x48, 0xC9, 0x86, 0xB4, 0x88, 0x99, 0x72, 0xA0, 0x6C, 0xF5}
 
 PBL_APP_INFO(
+	UUID,
 	"Wordsquare",
 	"hudson",
-	1, // Version
+	2, 0, // Version
 	RESOURCE_ID_IMAGE_MENU_ICON,
 	APP_INFO_WATCH_FACE
 );
 	TextLayer * const layer = &layers[which];
 	const word_t * const w = &words[which];
 
-	font_on = fonts_load_custom_font(resource_get_handle(FONT_ON));
-	font_off = fonts_load_custom_font(resource_get_handle(FONT_OFF));
-
 	GRect frame = GRect(
 		w->col*FONT_W,
 		w->row*FONT_H - 2,
 		strlen(w->text_on)*(FONT_W+4),
 		FONT_H+8
 	);
-	text_layer_init(layer, frame);
-	text_layer_set_text_color(layer, GColorWhite);
-	text_layer_set_background_color(layer, GColorClear);
+
+	text_layer_setup(&window, layer, frame, font_off);
 	word_mark(which, 0); // all are "off" initially
-
-	layer_add_child(&window.layer, &layer->layer);
 }
 
 
 
 	resource_init_current_app(&RESOURCES);
 
+	font_on = fonts_load_custom_font(resource_get_handle(FONT_ON));
+	font_off = fonts_load_custom_font(resource_get_handle(FONT_OFF));
+
 	for (unsigned i = 0 ; i < WORD_COUNT ; i++)
 		word_layer_init(i);
 
 }
 
 
+static void
+handle_deinit(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	fonts_unload_custom_font(font_on);
+	fonts_unload_custom_font(font_off);
+}
+	
+
 void
 pbl_main(
 	void * const params
 {
 	PebbleAppHandlers handlers = {
 		.init_handler	= &handle_init,
+		.deinit_handler = &handle_deinit,
 		.tick_info	= {
 			.tick_handler = &handle_tick,
 			.tick_units = MINUTE_UNIT,

File worldmap/src/worldmap.c

 // Update once per second to test things
 #undef CONFIG_DEBUG
 
+#define UUID {0x38, 0x38, 0x8B, 0x74, 0xB3, 0xD1, 0x42, 0x1F, 0x90, 0xFA, 0xBF, 0x34, 0xED, 0xB3, 0xB3, 0x8F}
+
 PBL_APP_INFO(
+	UUID,
 	"Polar Map",
 	"hudson",
-	1, // Version
+	2, 0, // Version
 	RESOURCE_ID_IMAGE_MENU_ICON,
 	APP_INFO_WATCH_FACE
 );