Skip to content

Instantly share code, notes, and snippets.

@fredley
Created March 13, 2014 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredley/9525782 to your computer and use it in GitHub Desktop.
Save fredley/9525782 to your computer and use it in GitHub Desktop.
Holiday Pebble App
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
PBL_APP_INFO(MY_UUID, "Holiday", "Tom Medley", 1, 1 /* App version */, RESOURCE_ID_IMAGE_MENU_ICON, APP_INFO_WATCH_FACE);
Window window;
TextLayer text_time_layer;
void handle_init(AppContextRef ctx) {
(void)ctx;
window_init(&window, "Holiday");
window_stack_push(&window, true /* Animated */);
window_set_background_color(&window, GColorBlack);
resource_init_current_app(&APP_RESOURCES);
text_layer_init(&text_time_layer, window.layer.frame);
text_layer_set_text_color(&text_time_layer, GColorWhite);
text_layer_set_background_color(&text_time_layer, GColorBlack);
layer_set_frame(&text_time_layer.layer, GRect(7, 60, 144-7, 168-60));
text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)));
layer_add_child(&window.layer, &text_time_layer.layer);
}
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) {
(void)ctx;
// Need to be static because they're used by the system later.
static char time_text[] = "12ish";
char *time_format;
time_format = "%Iish";
int hour = t->tick_time->tm_hour;
int minute = t->tick_time->tm_min;
if(minute >= 30){
if(t->tick_time->tm_hour == 23){
t->tick_time->tm_hour = 11;
// terrible hack, but hey...
}
t->tick_time->tm_hour = t->tick_time->tm_hour + 1;
}
string_format_time(time_text, sizeof(time_text), time_format, t->tick_time);
// Kludge to handle lack of non-padded hour format string
// for twelve hour clock.
if (time_text[0] == '0') {
memmove(time_text, &time_text[1], sizeof(time_text) - 1);
}
text_layer_set_text(&text_time_layer, time_text);
}
void pbl_main(void *params) {
PebbleAppHandlers handlers = {
.init_handler = &handle_init,
.tick_info = {
.tick_handler = &handle_minute_tick,
.tick_units = MINUTE_UNIT
}
};
app_event_loop(params, &handlers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment