Commits

Trammell Hudson committed e7e7920 Merge

merge

  • Participants
  • Parent commits ea5608d, b6e58ba

Comments (0)

Files changed (5)

File Makefile.pebble

 # Otherwise it should "just work".
 #
 PEBBLE_HOME := $(HOME)/build/pebble/sdk
-GCC_PREFIX := $(HOME)/arm-cs-tools/bin/arm-none-eabi-
+ARM_GCC_PATH := $(HOME)/arm-cs-tools/bin
+GCC_PREFIX := $(ARM_GCC_PATH)/arm-none-eabi-
+export PATH := $(ARM_GCC_PATH):$(PATH)
 
 CC := $(GCC_PREFIX)gcc
 LD := $(CC)
 OBJCOPY := $(GCC_PREFIX)objcopy
+SIZE := $(GCC_PREFIX)size
 PYTHON := python
 
 # If no version is specified, use a default one
 		$(LDFLAGS) \
 		-o $@ \
 		$^ \
-		$(LDLIBS) \
+		$(LDLIBS)
+	$(SIZE) $@
 
 $O/%.o:
 	$(CC) $(CFLAGS) -c -o $@ $<
 # These are produced by the -MMD flag to gcc in $(CFLAGS).
 #
 -include $O/.*.o.d
+
+#
+# Start a web server in the .. directory
+#
+httpd:
+	cd .. ; $(PYTHON) -mSimpleHTTPServer

File words/src/Makefile

+APP := words
+
+SRCS += words.c
+
+FONTS := \
+	fonts/Courier.ttf:19 \
+	fonts/Courier-Bold.ttf:19 \
+
+include ../../Makefile.pebble

File words/src/fonts/Courier-Bold.ttf

+/Library/Fonts/Courier New Bold.ttf

File words/src/fonts/Courier.ttf

+/Library/Fonts/Courier New.ttf

File words/src/words.c

+/** \file
+ * Word clock, like the qlock2
+ */
+#include <pebble_os.h>
+#include <pebble_app.h>
+#include <pebble_fonts.h>
+
+PBL_APP_INFO(
+	"Wordsquare",
+	"hudson",
+	1, // Version
+	INVALID_RESOURCE,
+	APP_INFO_WATCH_FACE
+);
+
+#define ROWS 10
+#define COLS 11
+#define FONT_H 16
+#define FONT_W 11
+#define FONT_ON		RESOURCE_ID_FONT_COURIER_BOLD_19
+#define FONT_OFF	RESOURCE_ID_FONT_COURIER_19
+
+
+typedef struct
+{
+	int row;
+	int col;
+	char text_on[8];
+	char text_off[8];
+} word_t;
+
+#define LAYER_FIVE	13
+#define LAYER_TEN	14
+#define LAYER_QUARTER	15
+#define LAYER_HALF	16
+#define LAYER_TWENTY	17
+#define LAYER_IT	 0
+#define LAYER_IS	18
+#define LAYER_PAST	19
+#define LAYER_TO	20
+#define LAYER_OCLOCK	21
+#define LAYER_FILLER	22
+
+static const word_t words[] = {
+	// Hours 1-12
+	[1] = {  5, 0, "ONE", "one" },
+	[2] = {  6, 8, "TWO", "two" },
+	[3] = {  5, 6, "THREE", "three" },
+	[4] = {  6, 0, "FOUR", "four" },
+	[5] = {  6, 4, "FIVE", "five" }, // hour
+	[6] = {  5, 3, "SIX", "six" },
+	[7] = {  8, 0, "SEVEN", "seven" },
+	[8] = {  7, 0, "EIGHT", "eight" },
+	[9] = {  4, 7, "NINE", "nine" },
+	[10] = {  9, 0, "TEN", "ten" }, // hour
+	[11] = {  7, 5, "ELEVEN", "eleven" },
+	[12] = {  8, 5, "TWELVE", "twelve" },
+
+	// Minutes 13-
+	[LAYER_FIVE]	= {  2, 6, "FIVE", "five" }, // minute
+	[LAYER_TEN]	= {  3, 5, "TEN", "ten" }, // minute
+	[LAYER_QUARTER]	= {  1, 2, "QUARTER", "quarter" },
+	[LAYER_HALF]	= {  3, 0, "HALF", "half" },
+	[LAYER_TWENTY]	= {  2, 0, "TWENTY", "twenty" },
+
+	// Relative
+	[LAYER_IT] = {  0, 0, "IT", "it" },
+	[LAYER_PAST]	= {  4, 0, "PAST", "past" },
+	[LAYER_TO]	= {  3, 9, "TO", "to", },
+	[LAYER_OCLOCK]	= {  9, 5, "OCLOCK", "oclock" },
+	[LAYER_IS]	= {  0, 3, "IS", "is" },
+
+	// Fillers
+	[LAYER_FILLER]	=
+	{  0, 2, "L", "l" },
+	{  0, 5, "AATIME", "aatime" },
+	{  1, 0, "A", "a" },
+	{  1, 1, "T", "t" },
+	{  1, 9, "TH", "th" },
+	{  2, 10, "X", "x" },
+	{  3, 4, "B", "b" },
+	{  3, 8, "F", "f" },
+	{  4, 4, "ERU", "eru" },
+	{  9, 3, "SE", "se" },
+};
+
+#define WORD_COUNT ((sizeof(words) / sizeof(*words)))
+
+static Window window;
+static TextLayer layers[WORD_COUNT];
+
+static void
+layer_mark(
+	int which,
+	int on
+)
+{
+	TextLayer * const layer = &layers[which];
+	const word_t * const w = &words[which];
+
+	text_layer_set_text(
+		layer,
+		on ? w->text_on : w->text_off
+	);
+
+	text_layer_set_font(
+		layer,
+		fonts_load_custom_font(resource_get_handle(on ? FONT_ON : FONT_OFF))
+	);
+}
+
+
+/** Called once per minute.
+ *
+0-4 "IT IS X OCLOCK"
+5-9 "IT IS FIVE PAST X"
+10-14 "IT IS TEN PAST X"
+15-19 "IT IS A QUARTER PAST X"
+20-24 "IT IS TWENTY PAST X"
+25-29 "IT IS TWENTY FIVE PAST X"
+30-34 "IT IS HALF PAST X"
+35-39 "IT IS TWENTY FIVE TO X+1"
+40-44 "IT IS TWENTY TO X+1"
+45-49 "IT IS A QUARTER TO X+1"
+50-54 "IT IS TEN TO X+1"
+55-59 "IT IS FIVE TO X+1"
+ */
+static void
+handle_tick(
+	AppContextRef ctx,
+	PebbleTickEvent * const event
+)
+{
+	(void) ctx;
+	const PblTm * const ptm = event->tick_time;
+
+	int hour = ptm->tm_hour;
+	int min = ptm->tm_min;
+
+	// light up the next hour if we are half before
+	if (min > 30)
+	{
+		hour++;
+		min = 60 - min;
+		layer_mark(LAYER_TO, 1);
+		layer_mark(LAYER_PAST, 0);
+	} else {
+		layer_mark(LAYER_TO, 0);
+		layer_mark(LAYER_PAST, min >= 5);
+	}
+
+	// Convert from 24-hour to 12-hour time
+	if (hour == 0)
+		hour = 12;
+	else
+	if (hour > 12)
+		hour -= 12;
+
+	for (int i = 1 ; i < 12 ; i++)
+		layer_mark(i, i == hour ? 1 : 0);
+
+	// mark all of the minutes as off,
+	// and then turn on the ones that count
+	layer_mark(LAYER_OCLOCK, 0);
+	layer_mark(LAYER_FIVE, 0);
+	layer_mark(LAYER_TEN, 0);
+	layer_mark(LAYER_QUARTER, 0);
+	layer_mark(LAYER_TWENTY, 0);
+	layer_mark(LAYER_HALF, 0);
+
+	if (min < 5)
+		layer_mark(LAYER_OCLOCK, 1);
+	else
+	if (min < 10)
+		layer_mark(LAYER_FIVE, 1);
+	else
+	if (min < 15)
+		layer_mark(LAYER_TEN, 1);
+	else
+	if (min < 20)
+		layer_mark(LAYER_QUARTER, 1);
+	else
+	if (min < 25)
+		layer_mark(LAYER_TWENTY, 1);
+	else
+	if (min < 30)
+	{
+		layer_mark(LAYER_TWENTY, 1);
+		layer_mark(LAYER_FIVE, 1);
+	} else
+	{
+		layer_mark(LAYER_HALF, 1);
+	}
+		
+/*
+	string_format_time(
+		time_buffer,
+		sizeof(time_buffer),
+		"%H:%M",
+		event->tick_time
+	);
+
+	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);
+*/
+}
+
+
+static void
+text_layer(
+	int which
+)
+{
+	TextLayer * const layer = &layers[which];
+	const word_t * const w = &words[which];
+
+	GRect frame = GRect(
+		w->col*FONT_W + 10,
+		w->row*FONT_H,
+		strlen(w->text_on)*(FONT_W+4),
+		FONT_H+5
+	);
+	text_layer_init(layer, frame);
+	text_layer_set_text_color(layer, GColorWhite);
+	text_layer_set_background_color(layer, GColorClear);
+	layer_mark(which, 0); // all are "off" initially
+
+	layer_add_child(&window.layer, &layer->layer);
+}
+
+
+static void
+handle_init(
+	AppContextRef ctx
+)
+{
+	(void) ctx;
+
+	window_init(&window, "Main");
+	window_stack_push(&window, true);
+	window_set_background_color(&window, GColorBlack);
+
+	resource_init_current_app(&RESOURCES);
+
+	for (unsigned i = 0 ; i < WORD_COUNT ; i++)
+	{
+		text_layer(i);
+	}
+
+	// Flag the ones that are always on
+	layer_mark(LAYER_IT, 1);
+	layer_mark(LAYER_IS, 1);
+}
+
+
+void
+pbl_main(
+	void * const params
+)
+{
+	PebbleAppHandlers handlers = {
+		.init_handler	= &handle_init,
+		.tick_info	= {
+			.tick_handler = &handle_tick,
+			.tick_units = MINUTE_UNIT,
+		},
+	};
+
+	app_event_loop(params, &handlers);
+}