Source

pebble / cst / src / cst.c

Full commit
Trammell Hudson b3f79c5 









Trammell Hudson 29fb3fa 
Trammell Hudson b3f79c5 
Trammell Hudson 40ae272 

Trammell Hudson b3f79c5 
Trammell Hudson 40ae272 
Trammell Hudson b3f79c5 

Trammell Hudson 40ae272 
Trammell Hudson b3f79c5 





Trammell Hudson 29fb3fa 


Trammell Hudson b3f79c5 






































Trammell Hudson 2814f13 
Trammell Hudson b3f79c5 

























Trammell Hudson 29fb3fa 


Trammell Hudson b3f79c5 

Trammell Hudson 29fb3fa 

Trammell Hudson b3f79c5 
Trammell Hudson 6da4ac3 
Trammell Hudson 29fb3fa 
Trammell Hudson b3f79c5 

Trammell Hudson 29fb3fa 

Trammell Hudson b3f79c5 
Trammell Hudson 6da4ac3 
Trammell Hudson 29fb3fa 
Trammell Hudson b3f79c5 

Trammell Hudson 29fb3fa 

Trammell Hudson b3f79c5 
Trammell Hudson 6da4ac3 
Trammell Hudson 29fb3fa 
Trammell Hudson b3f79c5 



Trammell Hudson 29fb3fa 











Trammell Hudson b3f79c5 






Trammell Hudson 29fb3fa 
Trammell Hudson b3f79c5 






/** \file
 * CST font clock
 *
 * Two lines:
 * HH:MM (large, bold)
 * YYYY-MM-DD
 */
#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",
	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 TextLayer time_layer;
static TextLayer date_layer;
static TextLayer day_layer;


static const char *days[] = {
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday",
};


/** Called once per minute */
static void
handle_tick(
	AppContextRef ctx,
	PebbleTickEvent * const event
)
{
	(void) ctx;
	const PblTm * const ptm = event->tick_time;

	string_format_time(
		time_text,
		sizeof(time_text),
		"%H:%M",
		ptm
	);

	string_format_time(
		date_text,
		sizeof(date_text),
		"%d %B",
		ptm
	);


	text_layer_set_text(&date_layer, date_text);
	text_layer_set_text(&time_layer, time_text);
	text_layer_set_text(&day_layer, days[ptm->tm_wday]);
}


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);

	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_setup(
		&window,
		&time_layer,
		GRect(0, 80, 144, 168),
		font_big
	);

	text_layer_setup(
		&window,
		&date_layer,
		GRect(0, 120, 144, 40),
		font_small
	);

	text_layer_setup(
		&window,
		&day_layer,
		GRect(0, 140, 144, 40),
		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,
		},
	};

	app_event_loop(params, &handlers);
}