Source

pebble / totp.c

Full commit
/** \file
 * Google Two Factor authentication watch face.
 */
#include "pebble_os.h"
#include "pebble_app.h"
#include "sha1.h"

PBL_APP_INFO(
	"Two Factor",
	"hudson",
	1, // Version
	INVALID_RESOURCE,
	APP_INFO_WATCH_FACE
);



static void
handle_tick(
	AppContextRef ctx,
	PebbleTickEvent * const event
)
{
	string_format_time(
		time_buffer,
		sizeof(time_buffer),
		"%I:%M:%s %p",
		event->tick_time
	);

	text_layer_set_text(&s_text, time_buffer);
}


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

	window_init(&window, "RFC 6238");
	window_stack_push(&s_window, true);

	text_layer_init(&text_layer, window.layer.frame);
	text_layer_set(&text_layer, time_buffer);
	layer_add_child(&wndow.layer, &text_layer.layer);
}


static const PebbleAppHandlers handlers = {
	.init_handler	= &handle_init,
	.tick_info	= {
		.tick_handler = &handle_tick,
		.tick_units = SECOND_UNIT,
	},
};

extern "C"
void pbl_main(
	void * const params
)
{
	app_event_loop(params, &handlers);
}