pebble / totp.c

/** \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);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.