diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index b1c5bfa..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7eded2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ + +# Ignore build generated files +build +.lock* + +#emacs +*~ + diff --git a/README.md b/README.md index fff0b30..6c4fa9b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,11 @@ This is an Hour Glass watch-face for the Pebble watch. It's a simple watch desig The watch-face uses the two halves of the hour glass to tell time. In the top half of the glass, you can see the time remaining hours until midnight, where each sand grain corresponds to one hour. The lower half of the glass fills with sand, with each grain representing a minute past the current hour. +Version 2.0 +=============== +- Ported to PebbleSDK-2.0BETA7 (splesniewski) + Version 1.0 =============== - First commit, the watch-face is in decent working order. -- There are minor off-by-one row errors in the sand animation. \ No newline at end of file +- There are minor off-by-one row errors in the sand animation. diff --git a/appinfo.json b/appinfo.json new file mode 100644 index 0000000..a8963d1 --- /dev/null +++ b/appinfo.json @@ -0,0 +1,27 @@ +{ + "uuid": "cd7be95b-95c1-49f4-b7eb-6acc8ab30b5b", + "shortName": "Hour Glass", + "longName": "Hour Glass", + "companyName": "ringdk", + "versionCode": 2, + "versionLabel": "2.0.0b7", + "watchapp": { + "watchface": true + }, + "appKeys": {}, + "resources": { + "media": [ + { + "type": "png", + "name": "HOUR_GLASS_BG", + "file": "img/bg.png" + }, + { + "menuIcon": true, + "type": "png", + "name": "HOUR_GLASS_ICON", + "file": "img/icon.png" + } + ] + } +} diff --git a/build/HourGlass.pbw b/build/HourGlass.pbw deleted file mode 100644 index ab824fa..0000000 Binary files a/build/HourGlass.pbw and /dev/null differ diff --git a/resources/.DS_Store b/resources/.DS_Store deleted file mode 100644 index 4c349a0..0000000 Binary files a/resources/.DS_Store and /dev/null differ diff --git a/resources/img/.DS_Store b/resources/img/.DS_Store deleted file mode 100644 index 5008ddf..0000000 Binary files a/resources/img/.DS_Store and /dev/null differ diff --git a/resources/src/resource_map.json b/resources/src/resource_map.json deleted file mode 100644 index 0316511..0000000 --- a/resources/src/resource_map.json +++ /dev/null @@ -1,16 +0,0 @@ - -{"friendlyVersion": "APP_RESOURCES", - "versionDefName": "APP_RESOURCES", - "media": [ - { - "type":"png", - "defName":"HOUR_GLASS_BG", - "file":"../img/bg.png" - }, - { - "type":"png", - "defName":"HOUR_GLASS_ICON", - "file":"../img/icon.png" - } - ] -} diff --git a/src/HourGlass.c b/src/HourGlass.c index 7d8cae3..bc50aab 100644 --- a/src/HourGlass.c +++ b/src/HourGlass.c @@ -1,17 +1,6 @@ -#include "pebble_os.h" -#include "pebble_app.h" -#include "pebble_fonts.h" - +#include "pebble.h" ////// Macros ///////////////// - -#define MY_UUID { 0xCD, 0x7B, 0xE9, 0x5B, 0x95, 0xC1, 0x49, 0xF4, 0xB7, 0xEB, 0x6A, 0xCC, 0x8A, 0xB3, 0x0B, 0x5B } -PBL_APP_INFO(MY_UUID, - "Hour Glass", "ringdk", - 1, 0, /* App version */ - RESOURCE_ID_HOUR_GLASS_ICON, - APP_INFO_WATCH_FACE); - #define MIN(a,b) (a < b ? a : b) #define MAX(a,b) (a > b ? a : b) @@ -22,10 +11,15 @@ PBL_APP_INFO(MY_UUID, ////// Global Variables ///////////////// -Window window; -InverterLayer inverterLayer; -BmpContainer backgroundImage; -Layer displayLayer; +static Window *window; +static Layer *windowLayer; + +static InverterLayer *inverterLayer; + +static GBitmap * backgroundImage; +static BitmapLayer *backgroundLayer; + +static Layer *displayLayer; int sandGrainTick = 0; @@ -188,21 +182,21 @@ const int bottomSandGrainRowAnimationEnd[] = { ////// Callback Functions ///////////////// -void handle_tick(AppContextRef ctx, PebbleTickEvent *event) { +static void handle_tick(struct tm *tick_time, TimeUnits units_changed) { // Tell the application to rerender the layer. - layer_mark_dirty(&displayLayer); + layer_mark_dirty(displayLayer); } -void displayLayer_update_callback(Layer *me, GContext* ctx) { +static void displayLayer_update_callback(Layer *me, GContext* ctx) { // If we're not using the layer, this will prevent compile errors. (void)me; // Getting the time - PblTm time; - get_time( &time ); - const int minutes = time.tm_min; - const int hours = time.tm_hour; + time_t now = time(NULL); + struct tm *time = localtime(&now); + const int minutes = time->tm_min; + const int hours = time->tm_hour; // Drawing the top sand grains. We use the 'dropTopSandGrainOrder' array to determine // what grains are drawn according the hour. This is set up so the grains will empty @@ -222,7 +216,7 @@ void displayLayer_update_callback(Layer *me, GContext* ctx) { // Drawing the bottom sand grains. Same as the above, but instead of emptying, we're // filling them up. - int numBottomGrainsToDraw = minutes - 1; + int numBottomGrainsToDraw = minutes; for(int grain=0; grain < numBottomGrainsToDraw; grain++) { if(grain < 0 || grain >= numBottomSandGrains) // For safety. @@ -285,45 +279,54 @@ void displayLayer_update_callback(Layer *me, GContext* ctx) { sandGrainTick = (sandGrainTick+1) % (BOTTOM_SAND_GRAIN_SIZE*2); } -void handle_init(AppContextRef ctx) { +static void handle_init() { // Initialise the main window - window_init(&window, "Hour Glass"); - window_stack_push(&window, true); - resource_init_current_app(&APP_RESOURCES); - + window = window_create(); + windowLayer = window_get_root_layer(window); + window_stack_push(window, true /* Animated */); + // Set up our background bitmap, pulled from our resources. - bmp_init_container(RESOURCE_ID_HOUR_GLASS_BG, &backgroundImage); - layer_add_child(&window.layer, &backgroundImage.layer.layer); + backgroundImage=gbitmap_create_with_resource(RESOURCE_ID_HOUR_GLASS_BG); + backgroundLayer=bitmap_layer_create(layer_get_frame(windowLayer)); + bitmap_layer_set_bitmap(backgroundLayer, backgroundImage); + layer_add_child(windowLayer, bitmap_layer_get_layer(backgroundLayer)); // Init the layer for the display. - layer_init(&displayLayer, window.layer.frame); - displayLayer.update_proc = &displayLayer_update_callback; - layer_add_child(&window.layer, &displayLayer); + displayLayer=layer_create(layer_get_frame(windowLayer)); + layer_set_update_proc(displayLayer, displayLayer_update_callback); + layer_add_child(windowLayer, displayLayer); // Lastly, set up the in inversion layer to make everything // nice and dark. - inverter_layer_init(&inverterLayer, GRect(0, 0, WATCH_WIDTH, WATCH_HEIGHT)); - layer_add_child(&window.layer, &inverterLayer.layer); + inverterLayer=inverter_layer_create(GRect(0, 0, WATCH_WIDTH, WATCH_HEIGHT)); + layer_add_child(windowLayer, inverter_layer_get_layer(inverterLayer)); + + // tick tock + tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } -void handle_deinit(AppContextRef ctx) { - (void)ctx; - - // Very important, de-init our bitmap image when we're done with it. - bmp_deinit_container(&backgroundImage); +static void handle_deinit() { + tick_timer_service_unsubscribe(); + + // Very important, destroy our layers, bitmap, & windows when we're done with them. + layer_remove_from_parent(inverter_layer_get_layer(inverterLayer)); + inverter_layer_destroy(inverterLayer); + + layer_remove_from_parent(displayLayer); + layer_destroy(displayLayer); + + layer_remove_from_parent(bitmap_layer_get_layer(backgroundLayer)); + bitmap_layer_destroy(backgroundLayer); + gbitmap_destroy(backgroundImage); + + window_destroy(window); } ////// Watchface Entry-point ///////////////// -void pbl_main(void *params) { - PebbleAppHandlers handlers = { - .init_handler = &handle_init, - .deinit_handler = &handle_deinit, - .tick_info = { - .tick_handler = &handle_tick, - .tick_units = SECOND_UNIT - } - }; - app_event_loop(params, &handlers); +int main(void) { + handle_init(); + app_event_loop(); + handle_deinit(); } diff --git a/wscript b/wscript new file mode 100644 index 0000000..0554dc8 --- /dev/null +++ b/wscript @@ -0,0 +1,24 @@ + +# +# This file is the default set of rules to compile a Pebble project. +# +# Feel free to customize this to your needs. +# + +top = '.' +out = 'build' + +def options(ctx): + ctx.load('pebble_sdk') + +def configure(ctx): + ctx.load('pebble_sdk') + +def build(ctx): + ctx.load('pebble_sdk') + + ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), + target='pebble-app.elf') + + ctx.pbl_bundle(elf='pebble-app.elf', + js=ctx.path.ant_glob('src/js/**/*.js'))