Skip to content

Instantly share code, notes, and snippets.

@mcowger
Last active December 16, 2015 08:59
Show Gist options
  • Save mcowger/5410016 to your computer and use it in GitHub Desktop.
Save mcowger/5410016 to your computer and use it in GitHub Desktop.
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID {0xC3, 0x0D, 0xBA, 0xF1, 0x5F, 0x6F, 0x4F, 0x22, 0xBA, 0xAA, 0x8C, 0x2A, 0x96, 0x8C, 0xFC, 0x28}
PBL_APP_INFO(MY_UUID, "VMworld", "Cowger", 0x2, 0x0, INVALID_RESOURCE, APP_INFO_WATCH_FACE);
Window window;
TextLayer timeLayer; // The clock
TextLayer textLayer; // The static text
TextLayer vMotionLayer; //the dynamic vMotion Layer
TextLayer vmTextLayer; // The static text
TextLayer vmLayer; //the dynamic VM Layer
#define INT_DIGITS 11
char *itoa(i)
int i;
{
static char buf[INT_DIGITS + 2];
char *p = buf + INT_DIGITS + 1;
if (i >= 0) {
do {
*--p = '0' + (i % 10);
i /= 10;
} while (i != 0);
return p;
}
return p;
}
BmpContainer image_container;
// Called once per second
static void update_watch(PblTm* t) {
static char timeText[] = "00:00:00"; // Needs to be static because it's used by the system later.
static char messageText[] = "vMotions Today: "; // Needs to be static because it's used by the system later.
static char vMotionStr[INT_DIGITS];
static char vmText[] = "VMs Built Today: "; // Needs to be static because it's used by the system later.
static char vMStr[INT_DIGITS];
string_format_time(timeText, sizeof(timeText), "%R", t);
text_layer_set_text(&timeLayer, timeText);
text_layer_set_text(&textLayer, messageText);
text_layer_set_text(&vmTextLayer, vmText);
int hrs = t->tm_hour;
int mins = t->tm_min;
int sec = t->tm_sec;
int total = (hrs * 60 * 60) + (mins * 60) + sec;
int vmotions = total * 6;
int vms = total / 6;
//vmotions = 48577;
strcpy(vMotionStr,itoa(vmotions));
strcpy(vMStr,itoa(vms));
text_layer_set_text(&vMotionLayer, vMotionStr);
text_layer_set_text(&vmLayer, vMStr);
}
// Called once per minute
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) {
update_watch(t->tick_time);
}
void handle_init(AppContextRef ctx) {
(void)ctx;
window_init(&window, "Demo");
window_stack_push(&window, true /* Animated */);
window_set_background_color(&window, GColorWhite);
resource_init_current_app(&FEATURE_DEMO_IMAGE_RESOURCES);
// Note: This needs to be "de-inited" in the application's
// deinit handler.
bmp_init_container(RESOURCE_ID_IMAGE_VMWLOGO, &image_container);
text_layer_init(&timeLayer, GRect(30, 60, 144 /* width */, 168 /* height */));
text_layer_set_text_color(&timeLayer, GColorBlack);
text_layer_set_background_color(&timeLayer, GColorClear);
text_layer_set_font(&timeLayer, fonts_get_system_font(FONT_KEY_GOTHAM_34_MEDIUM_NUMBERS));
text_layer_init(&vmTextLayer, GRect(2, 130, 144-2 /* width */, 168-116 /* height */));
text_layer_set_text_color(&vmTextLayer, GColorBlack);
text_layer_set_background_color(&vmTextLayer, GColorClear);
text_layer_set_font(&vmTextLayer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
text_layer_init(&vmLayer, GRect(90, 130, 144-2 /* width */, 168-116 /* height */));
text_layer_set_text_color(&vmLayer, GColorBlack);
text_layer_set_background_color(&vmLayer, GColorClear);
text_layer_set_font(&vmLayer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
text_layer_init(&textLayer, GRect(2, 150, 144-2 /* width */, 168-116 /* height */));
text_layer_set_text_color(&textLayer, GColorBlack);
text_layer_set_background_color(&textLayer, GColorClear);
text_layer_set_font(&textLayer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
text_layer_init(&vMotionLayer, GRect(90, 150, 144-2 /* width */, 168-116 /* height */));
text_layer_set_text_color(&vMotionLayer, GColorBlack);
text_layer_set_background_color(&vMotionLayer, GColorClear);
text_layer_set_font(&vMotionLayer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
layer_add_child(&window.layer, &image_container.layer.layer);
layer_add_child(&window.layer, &timeLayer.layer);
layer_add_child(&window.layer, &vmTextLayer.layer);
layer_add_child(&window.layer, &vmLayer.layer);
layer_add_child(&window.layer, &textLayer.layer);
layer_add_child(&window.layer, &vMotionLayer.layer);
}
void handle_deinit(AppContextRef ctx) {
(void)ctx;
// Note: Failure to de-init this here will result in instability and
// unable to allocate memory errors.
bmp_deinit_container(&image_container);
}
void pbl_main(void *params) {
PebbleAppHandlers handlers = {
.init_handler = &handle_init,
.deinit_handler = &handle_deinit,
// Handle time updates
.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