Source

pebble / mario / src / main.c

Full commit
Trammell Hudson dec6270 






















Trammell Hudson 40ae272 

Trammell Hudson dec6270 
Trammell Hudson 40ae272 
Trammell Hudson dec6270 

Trammell Hudson 40ae272 
Trammell Hudson 53cad8e 
Trammell Hudson dec6270 



















Trammell Hudson 38ca31f 



Trammell Hudson b17e328 

Trammell Hudson dec6270 










Trammell Hudson 38ca31f 














Trammell Hudson fdf4baa 
Trammell Hudson 38ca31f 





Trammell Hudson dec6270 







Trammell Hudson fdf4baa 




Trammell Hudson dec6270 



















Trammell Hudson 38ca31f 
Trammell Hudson dec6270 

Trammell Hudson 38ca31f 





Trammell Hudson dec6270 








Trammell Hudson 38ca31f 

Trammell Hudson dec6270 
Trammell Hudson 38ca31f 
Trammell Hudson dec6270 




/* ***************************************************************************
// This code is distributed under the GNU Public License
//		which can be found at http://www.gnu.org/licenses/gpl.txt
//
**************************************************************************** */

// MarioChron: Mario Themed Clock Face
// Initial work based on InvaderChron by Dataman
// By: techninja (James T) & Super-Awesome Sylvia
// Ported to Pebble by Trammell Hudson <hudson@osresearch.net>
//
// Originally created for Sylvia's Super-Awesome Mini Maker Show Episode S02E03
// sylviashow.com/monochron

#include <pebble_os.h>
#include <pebble_app.h>
#include <pebble_fonts.h>

#include <string.h>
#include <stdlib.h>
#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",
	2, 0, // Version
	RESOURCE_ID_IMAGE_MENU_ICON,
	APP_INFO_WATCH_FACE
);


volatile uint8_t time_s, time_m, time_h;
volatile uint8_t old_m, old_h;
volatile uint8_t date_m, date_d, date_y;
volatile uint8_t alarming, alarm_h, alarm_m;
volatile uint8_t time_format;
volatile uint8_t region;
volatile uint8_t score_mode;
volatile uint8_t write_font;

volatile uint8_t minute_changed, hour_changed;



static Window window;
static Layer layer;

static AppTimerHandle timer_handle;
#define COOKIE_MY_TIMER 1


extern void draw(GContext * gctx);

static void
layer_update(
	Layer * const me,
	GContext * ctx
)
{
	draw(ctx);
}


static void
handle_timer(
	AppContextRef ctx,
	AppTimerHandle handle,
	uint32_t cookie
)
{
	(void)handle;

	if (cookie != COOKIE_MY_TIMER)
		return;

	layer_mark_dirty(&layer);

	timer_handle = app_timer_send_event(
		ctx,
		75 /* milliseconds */,
		COOKIE_MY_TIMER
	);
}


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

	if (time_m != ptm->tm_min)
		minute_changed = 1;
	if (time_h != ptm->tm_hour)
		hour_changed = 1;

	time_s = ptm->tm_sec;
	time_m = ptm->tm_min;
	time_h = ptm->tm_hour;
	date_m = ptm->tm_mon + 1;
	date_d = ptm->tm_mday;
	date_y = ptm->tm_year;
}


static void
handle_init(
	AppContextRef ctx
)
{
	(void) ctx;

	window_init(&window, "MarioChron");
	window_stack_push(&window, true);

	// Mario Layer
	layer_init(&layer, GRect(0,0, 144, 168));
	layer.update_proc = layer_update;
	layer_add_child(&window.layer, &layer);

	timer_handle = app_timer_send_event(
		ctx,
		50 /* milliseconds */,
		COOKIE_MY_TIMER
	);
}


void
pbl_main(
	void * const params
)
{
	PebbleAppHandlers handlers = {
		.init_handler	= handle_init,
		.timer_handler	= handle_timer,
		.tick_info	= {
			.tick_handler = handle_tick,
			.tick_units = SECOND_UNIT,
		},
	};

	app_event_loop(params, &handlers);
}