diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2014-10-24 10:51:24 +0400 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2014-10-24 10:51:24 +0400 |
commit | 696ff11418d4b07fd5f2cf6b9a2b3dab6acb90ec (patch) | |
tree | d18d32415e5cf563769d51cb55fb5f91c324469d | |
parent | 7364150cfd742984e47342618b7dffcaa9e29b05 (diff) |
Configuration support
32 files changed, 474 insertions, 530 deletions
diff --git a/silly_walk_simple/resources/src/images/background.png b/silly_walk/resources/images/background-simple.png Binary files differindex 6e726bc..6e726bc 100644 --- a/silly_walk_simple/resources/src/images/background.png +++ b/silly_walk/resources/images/background-simple.png diff --git a/silly_walk_no_seconds/resources/src/images/background.png b/silly_walk/resources/images/background.png Binary files differindex 1219eff..1219eff 100644 --- a/silly_walk_no_seconds/resources/src/images/background.png +++ b/silly_walk/resources/images/background.png diff --git a/silly_walk/resources/images/battery-charging.png b/silly_walk/resources/images/battery-charging.png Binary files differnew file mode 100644 index 0000000..6d92660 --- /dev/null +++ b/silly_walk/resources/images/battery-charging.png diff --git a/silly_walk/resources/images/battery.png b/silly_walk/resources/images/battery.png Binary files differnew file mode 100644 index 0000000..1626e0c --- /dev/null +++ b/silly_walk/resources/images/battery.png diff --git a/silly_walk_no_seconds/resources/src/images/hour_hand.png b/silly_walk/resources/images/hour_hand.png Binary files differindex 342889a..342889a 100644 --- a/silly_walk_no_seconds/resources/src/images/hour_hand.png +++ b/silly_walk/resources/images/hour_hand.png diff --git a/silly_walk_no_seconds/resources/src/images/icon.png b/silly_walk/resources/images/icon.png Binary files differindex a34703d..a34703d 100644 --- a/silly_walk_no_seconds/resources/src/images/icon.png +++ b/silly_walk/resources/images/icon.png diff --git a/silly_walk_no_seconds/resources/src/images/minute_hand.png b/silly_walk/resources/images/minute_hand.png Binary files differindex 6a35022..6a35022 100644 --- a/silly_walk_no_seconds/resources/src/images/minute_hand.png +++ b/silly_walk/resources/images/minute_hand.png diff --git a/silly_walk/resources/images/no-phone.png b/silly_walk/resources/images/no-phone.png Binary files differnew file mode 100644 index 0000000..2c516bc --- /dev/null +++ b/silly_walk/resources/images/no-phone.png diff --git a/silly_walk_no_seconds/resources/src/images/seconds_hand.png b/silly_walk/resources/images/seconds_hand.png Binary files differindex 2c66619..2c66619 100644 --- a/silly_walk_no_seconds/resources/src/images/seconds_hand.png +++ b/silly_walk/resources/images/seconds_hand.png diff --git a/silly_walk/silly-walk.pbw b/silly_walk/silly-walk.pbw Binary files differnew file mode 100644 index 0000000..346285f --- /dev/null +++ b/silly_walk/silly-walk.pbw diff --git a/silly_walk/src/configuration.html b/silly_walk/src/configuration.html new file mode 100644 index 0000000..6d26ffe --- /dev/null +++ b/silly_walk/src/configuration.html @@ -0,0 +1,123 @@ +<!DOCTYPE html> +<!-- -*-coding: utf-8 -*- +vim: sw=2 ts=2 expandtab ai +--> + +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <style> + body { background-color: black; text-align: center; color: white } + h1 { margin: 0 } + small { color: gray } + a { color: white } + input { height: 1.5em; font-size: 1.2em; font-weight: bold } + .text { width: 93%; margin: 0.5em; text-align: center } + .submit { width: 93%; margin: 0.4em } + .param { display: inline-table; width: 95%; height: 3em } + .label,.checkbox { display: table-cell; vertical-align: middle } + .label { text-align: left } + .checkbox { text-align: right; width: 1.5em; height: 1.5em } + .example { width: 75%; display: inline-block; text-align: left; font-size: 0.6em } + </style> + <script> + + var config = _CONFIG_; + + function put_config() { + for (var param in config) { + var element = document.getElementById(param); + if (element) { + if (typeof config[param] === 'boolean') { + element.checked = config[param]; + } else { + element.value = config[param]; + } + } + } + } + + function get_config() { + var form = document.getElementById('config_form'); + for (config = {}, i = 0; i < form.length ; i++) { + id = form[i].id; + if (id != "save") { + if (form[i].type === 'checkbox') { + config[id] = form[i].checked; + } else { + config[id] = form[i].value; + } + } + } + return window.location.href = "pebblejs://close#" + encodeURIComponent(JSON.stringify(config)); + } + + function toggle_visibility(id) { + var e = document.getElementById(id); + if(e.style.display == 'block') + e.style.display = 'none'; + else + e.style.display = 'block'; + } + </script> + </head> + <body onload="put_config();"> + <h1>Silly Walk</h1> + <small>by Dan Long, mod by Alexey Avdyukhin</small> + <hr size="1" /> + + <form action="javascript: get_config();" id="config_form"> + <div class="param"> + <div class="label"> + Show "no connection" icon<br> + <small>Show when phone is not connected</small> + </div> + <div class="checkbox"> + <input type="checkbox" id="config_show_no_phone" class="checkbox"> + </div> + </div> + + <div class="param"> + <div class="label"> + Show battery icon<br> + <small>Show battery status</small> + </div> + <div class="checkbox"> + <input type="checkbox" id="config_show_battery" class="checkbox"> + </div> + </div> + + <div class="param"> + <div class="label"> + Vibe on disconnect<br> + <small>Vibe when phone is disconnected</small> + </div> + <div class="checkbox"> + <input type="checkbox" id="config_vibe" class="checkbox"> + </div> + </div> + + <div class="param"> + <div class="label"> + Seconds<br> + <small>Show seconds</small> + </div> + <div class="checkbox"> + <input type="checkbox" id="config_seconds" class="checkbox"> + </div> + </div> + + <div class="param"> + <div class="label"> + Simple mode<br> + <small>Use simple background</small> + </div> + <div class="checkbox"> + <input type="checkbox" id="config_simple" class="checkbox"> + </div> + </div> + + <hr size="1" /> + <input type="submit" id="save" class="submit" value="Save and apply"> + </body> +</html> diff --git a/silly_walk/src/js/pebble-js-app.js b/silly_walk/src/js/pebble-js-app.js new file mode 100644 index 0000000..9a95fb3 --- /dev/null +++ b/silly_walk/src/js/pebble-js-app.js @@ -0,0 +1,41 @@ +var initialized = false; +var options = { + "config_show_no_phone": true, + "config_show_battery": true, + "config_vibe": false, + "config_simple": false, + "config_seconds": false +}; + +Pebble.addEventListener("ready", function() { + initialized = true; + var json = window.localStorage.getItem('silly-walk-config'); + if (typeof json === 'string') { + try { + options = JSON.parse(json); + Pebble.sendAppMessage(options); + console.log("Loaded stored config: " + json); + } catch(e) { + console.log("stored config json parse error: " + json + ' - ' + e); + } + } +}); + +Pebble.addEventListener("showConfiguration", function() { + console.log("showing configuration"); + Pebble.openURL('data:text/html,'+encodeURI('<!DOCTYPE html><!-- -*-coding: utf-8 -*-vim: sw=2 ts=2 expandtab ai--><html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { background-color: black; text-align: center; color: white } h1 { margin: 0 } small { color: gray } a { color: white } input { height: 1.5em; font-size: 1.2em; font-weight: bold } .text { width: 93%; margin: 0.5em; text-align: center } .submit { width: 93%; margin: 0.4em } .param { display: inline-table; width: 95%; height: 3em } .label,.checkbox { display: table-cell; vertical-align: middle } .label { text-align: left } .checkbox { text-align: right; width: 1.5em; height: 1.5em } .example { width: 75%; display: inline-block; text-align: left; font-size: 0.6em } </style> <script> var config = _CONFIG_; function put_config() { for (var param in config) { var element = document.getElementById(param); if (element) { if (typeof config[param] === \'boolean\') { element.checked = config[param]; } else { element.value = config[param]; } } } } function get_config() { var form = document.getElementById(\'config_form\'); for (config = {}, i = 0; i < form.length ; i++) { id = form[i].id; if (id != "save") { if (form[i].type === \'checkbox\') { config[id] = form[i].checked; } else { config[id] = form[i].value; } } } return window.location.href = "pebblejs://close#" + encodeURIComponent(JSON.stringify(config)); } function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.display == \'block\') e.style.display = \'none\'; else e.style.display = \'block\'; } </script> </head> <body onload="put_config();"> <h1>Silly Walk</h1> <small>by Dan Long, mod by Alexey Avdyukhin</small> <hr size="1" /> <form action="javascript: get_config();" id="config_form"> <div class="param"> <div class="label"> Show "no connection" icon<br> <small>Show when phone is not connected</small> </div> <div class="checkbox"> <input type="checkbox" id="config_show_no_phone" class="checkbox"> </div> </div> <div class="param"> <div class="label"> Show battery icon<br> <small>Show battery status</small> </div> <div class="checkbox"> <input type="checkbox" id="config_show_battery" class="checkbox"> </div> </div> <div class="param"> <div class="label"> Vibe on disconnect<br> <small>Vibe when phone is disconnected</small> </div> <div class="checkbox"> <input type="checkbox" id="config_vibe" class="checkbox"> </div> </div> <div class="param"> <div class="label"> Seconds<br> <small>Show seconds</small> </div> <div class="checkbox"> <input type="checkbox" id="config_seconds" class="checkbox"> </div> </div> <div class="param"> <div class="label"> Simple mode<br> <small>Use simple background</small> </div> <div class="checkbox"> <input type="checkbox" id="config_simple" class="checkbox"> </div> </div> <hr size="1" /> <input type="submit" id="save" class="submit" value="Save and apply"> </body></html><!--.html'.replace('_CONFIG_', JSON.stringify(options), 'g'))); +}); + +Pebble.addEventListener("webviewclosed", function(e) { + var response = decodeURIComponent(e.response); + if (response.charAt(0) == "{" && response.slice(-1) == "}" && response.length > 5) { + window.localStorage.setItem('silly-walk-config', response); + try { + options = JSON.parse(response); + Pebble.sendAppMessage(options); + } catch(e) { + console.log("Response config json parse error: " + response + ' - ' + e); + } + console.log("Options = " + response); + } +}); diff --git a/silly_walk/src/pebble-js-app.src.js b/silly_walk/src/pebble-js-app.src.js new file mode 100644 index 0000000..f82d77e --- /dev/null +++ b/silly_walk/src/pebble-js-app.src.js @@ -0,0 +1,41 @@ +var initialized = false; +var options = { + "config_show_no_phone": true, + "config_show_battery": true, + "config_vibe": false, + "config_simple": false, + "config_seconds": false +}; + +Pebble.addEventListener("ready", function() { + initialized = true; + var json = window.localStorage.getItem('silly-walk-config'); + if (typeof json === 'string') { + try { + options = JSON.parse(json); + Pebble.sendAppMessage(options); + console.log("Loaded stored config: " + json); + } catch(e) { + console.log("stored config json parse error: " + json + ' - ' + e); + } + } +}); + +Pebble.addEventListener("showConfiguration", function() { + console.log("showing configuration"); + Pebble.openURL('data:text/html,'+encodeURI('_HTMLMARKER_<!--.html'.replace('_CONFIG_', JSON.stringify(options), 'g'))); +}); + +Pebble.addEventListener("webviewclosed", function(e) { + var response = decodeURIComponent(e.response); + if (response.charAt(0) == "{" && response.slice(-1) == "}" && response.length > 5) { + window.localStorage.setItem('silly-walk-config', response); + try { + options = JSON.parse(response); + Pebble.sendAppMessage(options); + } catch(e) { + console.log("Response config json parse error: " + response + ' - ' + e); + } + console.log("Options = " + response); + } +}); diff --git a/silly_walk/src/silly_walk.c b/silly_walk/src/silly_walk.c index d40852d..2ee3bdd 100644 --- a/silly_walk/src/silly_walk.c +++ b/silly_walk/src/silly_walk.c @@ -1,114 +1,292 @@ -#include "pebble_os.h" -#include "pebble_app.h" -#include "pebble_fonts.h" - - -#define MY_UUID { 0xAE, 0xF7, 0x20, 0xA0, 0x74, 0x8F, 0x49, 0x01, 0xB2, 0xF5, 0xD4, 0x0B, 0xF9, 0xF6, 0xA5, 0x96 } -PBL_APP_INFO(MY_UUID, - "Silly Walk", "Dansl", - 1, 0, /* App version */ - RESOURCE_ID_IMAGE_MENU_ICON, - APP_INFO_WATCH_FACE); - -Window window; - -BmpContainer background_image_container; - -RotBmpPairContainer hour_hand_image_container; -RotBmpPairContainer minute_hand_image_container; -RotBmpPairContainer second_hand_image_container; - -void update_watch(PblTm* t){ - - //rotbmp_pair_layer_set_angle(&hour_hand_image_container.layer, ((t->tm_hour % 12) * 30) + (t->tm_min/2)); - hour_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.layer.frame.origin.x = (144/2) - (hour_hand_image_container.layer.layer.frame.size.w/2); - hour_hand_image_container.layer.layer.frame.origin.y = (168/2) - (hour_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&hour_hand_image_container.layer.layer); - - //rotbmp_pair_layer_set_angle(&minute_hand_image_container.layer, t->tm_min * 6); - minute_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.layer.frame.origin.x = (144/2) - (minute_hand_image_container.layer.layer.frame.size.w/2); - minute_hand_image_container.layer.layer.frame.origin.y = (168/2) - (minute_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&minute_hand_image_container.layer.layer); - - //rotbmp_pair_layer_set_angle(&second_hand_image_container.layer, t->tm_sec * 6); - second_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (t->tm_sec * 6) / 360; - second_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (t->tm_sec * 6) / 360; - second_hand_image_container.layer.layer.frame.origin.x = (144/2) - (second_hand_image_container.layer.layer.frame.size.w/2); - second_hand_image_container.layer.layer.frame.origin.y = (168/2) - (second_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&second_hand_image_container.layer.layer); +#include <pebble.h> + +#define MSG_SHOW_NO_PHONE 0 +#define MSG_SHOW_BATTERY 1 +#define MSG_VIBE 2 +#define MSG_SIMPLE 3 +#define MSG_SECONDS 4 + +static Window *window; + +static GBitmap *hour_bmp_black; +static GBitmap *min_bmp_black; +static GBitmap *sec_bmp_black; +static GBitmap *hour_bmp_white; +static GBitmap *min_bmp_white; +static GBitmap *sec_bmp_white; +static GBitmap *bg_bmp; +static GBitmap *bg_bmp_simple; +static GBitmap *battery_bmp_black; +static GBitmap *battery_bmp_white; +static GBitmap *battery_charging_bmp_black; +static GBitmap *battery_charging_bmp_white; +static GBitmap *no_phone_bmp_black; +static GBitmap *no_phone_bmp_white; + +static BitmapLayer* bg_layer; +static RotBitmapLayer* hour_hand_layer_black; +static RotBitmapLayer* minute_hand_layer_black; +static RotBitmapLayer* second_hand_layer_black; +static RotBitmapLayer* hour_hand_layer_white; +static RotBitmapLayer* minute_hand_layer_white; +static RotBitmapLayer* second_hand_layer_white; +static Layer *battery_layer; +static Layer *no_phone_layer; + +bool config_show_no_phone = true; +bool config_show_battery = true; +bool config_vibe = false; +bool config_simple = false; +bool config_seconds = false; + +static void update_time() +{ + time_t t = time(NULL); + struct tm *tick_time = localtime(&t); + rot_bitmap_layer_set_angle(hour_hand_layer_black, TRIG_MAX_ANGLE * (tick_time->tm_hour%12) / 12 + TRIG_MAX_ANGLE * tick_time->tm_min / 720); + rot_bitmap_layer_set_angle(hour_hand_layer_white, TRIG_MAX_ANGLE * (tick_time->tm_hour%12) / 12 + TRIG_MAX_ANGLE * tick_time->tm_min / 720); + rot_bitmap_layer_set_angle(minute_hand_layer_black, TRIG_MAX_ANGLE * tick_time->tm_min / 60); + rot_bitmap_layer_set_angle(minute_hand_layer_white, TRIG_MAX_ANGLE * tick_time->tm_min / 60); + if (config_seconds) + { + rot_bitmap_layer_set_angle(second_hand_layer_black, TRIG_MAX_ANGLE * tick_time->tm_sec / 60); + rot_bitmap_layer_set_angle(second_hand_layer_white, TRIG_MAX_ANGLE * tick_time->tm_sec / 60); + } } -// Called once per second -void handle_second_tick(AppContextRef ctx, PebbleTickEvent *t) { - update_watch(t->tick_time); +static void handle_tick(struct tm *tick_time, TimeUnits units_changed) { + update_time(); } +void battery_update_callback(Layer *layer, GContext *ctx) +{ + if (config_show_battery) + { + GRect image_rect = battery_bmp_white->bounds; + BatteryChargeState charge_state = battery_state_service_peek(); + if (!charge_state.is_charging) + { + graphics_context_set_compositing_mode(ctx, GCompOpOr); + graphics_draw_bitmap_in_rect(ctx, battery_bmp_white, image_rect); + graphics_context_set_compositing_mode(ctx, GCompOpClear); + graphics_draw_bitmap_in_rect(ctx, battery_bmp_black, image_rect); + graphics_context_set_fill_color(ctx, GColorBlack); + graphics_fill_rect(ctx, GRect(4, 4, charge_state.charge_percent / 10, 6), 0, GCornerNone); + } else { + graphics_context_set_compositing_mode(ctx, GCompOpOr); + graphics_draw_bitmap_in_rect(ctx, battery_charging_bmp_white, image_rect); + graphics_context_set_compositing_mode(ctx, GCompOpClear); + graphics_draw_bitmap_in_rect(ctx, battery_charging_bmp_black, image_rect); + } + } +} -// Handle the start-up of the app -void handle_init(AppContextRef app_ctx) { +void handle_battery(BatteryChargeState charge_state) +{ + layer_mark_dirty(battery_layer); +} - // Create our app's base window - window_init(&window, "Silly Walk"); - window_stack_push(&window, true); - window_set_background_color(&window, GColorBlack); +void no_phone_update_callback(Layer *layer, GContext *ctx) +{ + if (config_show_no_phone && !bluetooth_connection_service_peek()) + { + GRect image_rect = no_phone_bmp_white->bounds; + graphics_context_set_compositing_mode(ctx, GCompOpOr); + graphics_draw_bitmap_in_rect(ctx, no_phone_bmp_white, image_rect); + graphics_context_set_compositing_mode(ctx, GCompOpClear); + graphics_draw_bitmap_in_rect(ctx, no_phone_bmp_black, image_rect); + } +} - resource_init_current_app(&APP_RESOURCES); +void bluetooth_connection_callback(bool connected) +{ + layer_mark_dirty(no_phone_layer); + if (config_vibe && !connected) { + static const uint32_t const segments[] = { 100, 200, 100, 200, 100 }; + VibePattern pat = { + .durations = segments, + .num_segments = ARRAY_LENGTH(segments), + }; + vibes_enqueue_custom_pattern(pat); + } +} - // Set up a layer for the static watch face background - bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); - layer_add_child(&window.layer, &background_image_container.layer.layer); +static void update_config() +{ + bitmap_layer_set_bitmap(bg_layer, config_simple ? bg_bmp_simple : bg_bmp); + layer_set_hidden((Layer*)second_hand_layer_black, !config_seconds); + layer_set_hidden((Layer*)second_hand_layer_white, !config_seconds); + tick_timer_service_unsubscribe(); + tick_timer_service_subscribe(config_seconds ? SECOND_UNIT : MINUTE_UNIT, handle_tick); +} +void in_received_handler(DictionaryIterator *received, void *context) { + APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config"); + Tuple *tuple = dict_find(received, MSG_SHOW_NO_PHONE); + if (tuple) { + config_show_no_phone = (strcmp(tuple->value->cstring, "true") == 0); + layer_mark_dirty(no_phone_layer); + } + tuple = dict_find(received, MSG_SHOW_BATTERY); + if (tuple) { + config_show_battery = (strcmp(tuple->value->cstring, "true") == 0); + layer_mark_dirty(battery_layer); + } + tuple = dict_find(received, MSG_VIBE); + if (tuple) { + config_vibe = (strcmp(tuple->value->cstring, "true") == 0); + } + tuple = dict_find(received, MSG_SIMPLE); + if (tuple) { + config_simple = (strcmp(tuple->value->cstring, "true") == 0); + } + tuple = dict_find(received, MSG_SECONDS); + if (tuple) { + config_seconds = (strcmp(tuple->value->cstring, "true") == 0); + } + update_config(); + persist_write_bool(MSG_SHOW_NO_PHONE, config_show_no_phone); + persist_write_bool(MSG_SHOW_BATTERY, config_show_battery); + persist_write_bool(MSG_VIBE, config_vibe); + persist_write_bool(MSG_SIMPLE, config_simple); + persist_write_bool(MSG_SECONDS, config_seconds); +} - // Set up a layer for the hour hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_HAND_WHITE, RESOURCE_ID_IMAGE_HOUR_HAND_BLACK, &hour_hand_image_container); - rotbmp_pair_layer_set_src_ic(&hour_hand_image_container.layer, GPoint(33, 40)); - layer_add_child(&window.layer, &hour_hand_image_container.layer.layer); +// Handle the start-up of the app +static void handle_init() { + if (persist_exists(MSG_SHOW_NO_PHONE)) + config_show_no_phone = persist_read_bool(MSG_SHOW_NO_PHONE); + if (persist_exists(MSG_SHOW_BATTERY)) + config_show_battery = persist_read_bool(MSG_SHOW_BATTERY); + if (persist_exists(MSG_VIBE)) + config_vibe = persist_read_bool(MSG_VIBE); + if (persist_exists(MSG_SIMPLE)) + config_simple = persist_read_bool(MSG_SIMPLE); + if (persist_exists(MSG_SECONDS)) + config_seconds = persist_read_bool(MSG_SECONDS); + app_message_register_inbox_received(in_received_handler); + app_message_open(64, 64); - // Set up a layer for the minute hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_MINUTE_HAND_WHITE, RESOURCE_ID_IMAGE_MINUTE_HAND_BLACK, &minute_hand_image_container); - rotbmp_pair_layer_set_src_ic(&minute_hand_image_container.layer, GPoint(16, 60)); - layer_add_child(&window.layer, &minute_hand_image_container.layer.layer); + hour_bmp_black = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_HAND_BLACK); + min_bmp_black = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_HAND_BLACK); + sec_bmp_black = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SECOND_HAND_BLACK); + battery_bmp_black = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_BLACK); + battery_charging_bmp_black = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_CHARGING_BLACK); + no_phone_bmp_black = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_NO_PHONE_BLACK); + hour_bmp_white = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_HAND_WHITE); + min_bmp_white = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_HAND_WHITE); + sec_bmp_white = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SECOND_HAND_WHITE); + battery_bmp_white = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_WHITE); + battery_charging_bmp_white = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_CHARGING_WHITE); + no_phone_bmp_white = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_NO_PHONE_WHITE); + bg_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); + bg_bmp_simple = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND_SIMPLE); + window = window_create(); - // Set up a layer for the second hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_SECOND_HAND_WHITE, RESOURCE_ID_IMAGE_SECOND_HAND_BLACK, &second_hand_image_container); - rotbmp_pair_layer_set_src_ic(&second_hand_image_container.layer, GPoint(7, 44)); - layer_add_child(&window.layer, &second_hand_image_container.layer.layer); + bg_layer = bitmap_layer_create(GRect(0,0, 144, 168)); + bitmap_layer_set_bitmap(bg_layer, bg_bmp_simple); - PblTm t; - get_time(&t); - update_watch(&t); + hour_hand_layer_black = rot_bitmap_layer_create(hour_bmp_black); + minute_hand_layer_black = rot_bitmap_layer_create(min_bmp_black); + second_hand_layer_black = rot_bitmap_layer_create(sec_bmp_black); + rot_bitmap_set_compositing_mode(hour_hand_layer_black, GCompOpClear); + rot_bitmap_set_compositing_mode(minute_hand_layer_black, GCompOpClear); + rot_bitmap_set_compositing_mode(second_hand_layer_black, GCompOpClear); -} + hour_hand_layer_white = rot_bitmap_layer_create(hour_bmp_white); + minute_hand_layer_white = rot_bitmap_layer_create(min_bmp_white); + second_hand_layer_white = rot_bitmap_layer_create(sec_bmp_white); + rot_bitmap_set_compositing_mode(hour_hand_layer_white, GCompOpOr); + rot_bitmap_set_compositing_mode(minute_hand_layer_white, GCompOpOr); + rot_bitmap_set_compositing_mode(second_hand_layer_white, GCompOpOr); -void handle_deinit(AppContextRef ctx) { + rot_bitmap_set_src_ic(hour_hand_layer_black, GPoint(33, 40)); + rot_bitmap_set_src_ic(minute_hand_layer_black, GPoint(16, 60)); + rot_bitmap_set_src_ic(second_hand_layer_black, GPoint(7, 44)); + rot_bitmap_set_src_ic(hour_hand_layer_white, GPoint(33, 40)); + rot_bitmap_set_src_ic(minute_hand_layer_white, GPoint(16, 60)); + rot_bitmap_set_src_ic(second_hand_layer_white, GPoint(7, 44)); - bmp_deinit_container(&background_image_container); - rotbmp_pair_deinit_container(&hour_hand_image_container); - rotbmp_pair_deinit_container(&minute_hand_image_container); - rotbmp_pair_deinit_container(&second_hand_image_container); -} + GRect frame = layer_get_frame((Layer*)hour_hand_layer_black); + frame.origin.x = 144/2 - frame.size.w/2; + frame.origin.y = 168/2 - frame.size.h/2; + layer_set_frame((Layer*)hour_hand_layer_black, frame); + layer_set_frame((Layer*)hour_hand_layer_white, frame); + //APP_LOG(APP_LOG_LEVEL_DEBUG, "H X: %d, X: %d, W: %d, H: %d", frame.origin.x, frame.origin.y, frame.size.w, frame.size.h); + frame = layer_get_frame((Layer*)minute_hand_layer_black); + frame.origin.x = 144/2 - frame.size.w/2; + frame.origin.y = 168/2 - frame.size.h/2; + layer_set_frame((Layer*)minute_hand_layer_black, frame); + layer_set_frame((Layer*)minute_hand_layer_white, frame); + //APP_LOG(APP_LOG_LEVEL_DEBUG, "M X: %d, X: %d, W: %d, H: %d", frame.origin.x, frame.origin.y, frame.size.w, frame.size.h); -// The main event/run loop for our app -void pbl_main(void *params) { - PebbleAppHandlers handlers = { + frame = layer_get_frame((Layer*)second_hand_layer_black); + frame.origin.x = 144/2 - frame.size.w/2; + frame.origin.y = 168/2 - frame.size.h/2; + layer_set_frame((Layer*)second_hand_layer_black, frame); + layer_set_frame((Layer*)second_hand_layer_white, frame); + //APP_LOG(APP_LOG_LEVEL_DEBUG, "S X: %d, X: %d, W: %d, H: %d", frame.origin.x, frame.origin.y, frame.size.w, frame.size.h); + + battery_layer = layer_create(GRect(120, 5, 20, 14)); + no_phone_layer = layer_create(GRect(7, 5, 11, 12)); + + Layer *window_layer = window_get_root_layer(window); + layer_add_child(window_layer, (Layer*)bg_layer); + layer_add_child(window_layer, (Layer*)hour_hand_layer_black); + layer_add_child(window_layer, (Layer*)hour_hand_layer_white); + layer_add_child(window_layer, (Layer*)minute_hand_layer_black); + layer_add_child(window_layer, (Layer*)minute_hand_layer_white); + layer_add_child(window_layer, (Layer*)second_hand_layer_black); + layer_add_child(window_layer, (Layer*)second_hand_layer_white); + layer_add_child(window_layer, battery_layer); + layer_add_child(window_layer, no_phone_layer); + layer_set_update_proc(battery_layer, &battery_update_callback); + layer_set_update_proc(no_phone_layer, &no_phone_update_callback); - // Handle app start - .init_handler = &handle_init, - .deinit_handler = &handle_deinit, + update_config(); - // Handle time updates - .tick_info = { - .tick_handler = &handle_second_tick, - .tick_units = SECOND_UNIT - } + update_time(); - }; - app_event_loop(params, &handlers); -}
\ No newline at end of file + window_stack_push(window, true /* Animated */); + battery_state_service_subscribe(handle_battery); + bluetooth_connection_service_subscribe(bluetooth_connection_callback); +} + +static void handle_deinit() { + tick_timer_service_unsubscribe(); + battery_state_service_unsubscribe(); + bluetooth_connection_service_unsubscribe(); + app_message_deregister_callbacks(); + rot_bitmap_layer_destroy(hour_hand_layer_black); + rot_bitmap_layer_destroy(minute_hand_layer_black); + rot_bitmap_layer_destroy(second_hand_layer_black); + rot_bitmap_layer_destroy(hour_hand_layer_white); + rot_bitmap_layer_destroy(minute_hand_layer_white); + rot_bitmap_layer_destroy(second_hand_layer_white); + layer_destroy(battery_layer); + layer_destroy(no_phone_layer); + gbitmap_destroy(hour_bmp_black); + gbitmap_destroy(min_bmp_black); + gbitmap_destroy(sec_bmp_black); + gbitmap_destroy(hour_bmp_white); + gbitmap_destroy(min_bmp_white); + gbitmap_destroy(sec_bmp_white); + gbitmap_destroy(bg_bmp); + gbitmap_destroy(bg_bmp_simple); + gbitmap_destroy(battery_bmp_black); + gbitmap_destroy(battery_bmp_white); + gbitmap_destroy(battery_charging_bmp_black); + gbitmap_destroy(battery_charging_bmp_white); + gbitmap_destroy(no_phone_bmp_black); + gbitmap_destroy(no_phone_bmp_white); +} + +int main(void) +{ + handle_init(); + app_event_loop(); + handle_deinit(); +} diff --git a/silly_walk_no_seconds/resources/src/resource_map.json b/silly_walk_no_seconds/resources/src/resource_map.json deleted file mode 100644 index 4e9fe55..0000000 --- a/silly_walk_no_seconds/resources/src/resource_map.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "friendlyVersion": "dev_0.0", - "versionDefName": "APP_RESOURCES", - - "media": [ - - { - "type": "png", - "defName": "IMAGE_MENU_ICON", - "file": "images/icon.png" - }, - - { - "type": "png", - "defName": "IMAGE_BACKGROUND", - "file": "images/background.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_HOUR_HAND", - "file": "images/hour_hand.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_MINUTE_HAND", - "file": "images/minute_hand.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_SECOND_HAND", - "file": "images/seconds_hand.png" - } - - ] -} - diff --git a/silly_walk_no_seconds/silly_walk_no_seconds.pbw b/silly_walk_no_seconds/silly_walk_no_seconds.pbw Binary files differdeleted file mode 100644 index 662e07d..0000000 --- a/silly_walk_no_seconds/silly_walk_no_seconds.pbw +++ /dev/null diff --git a/silly_walk_no_seconds/src/silly_walk_no_seconds.c b/silly_walk_no_seconds/src/silly_walk_no_seconds.c deleted file mode 100644 index c462df5..0000000 --- a/silly_walk_no_seconds/src/silly_walk_no_seconds.c +++ /dev/null @@ -1,104 +0,0 @@ -#include "pebble_os.h" -#include "pebble_app.h" -#include "pebble_fonts.h" - - -#define MY_UUID { 0x9B, 0x5E, 0x69, 0x04, 0xCA, 0xAD, 0x4E, 0xFA, 0xB7, 0x19, 0x82, 0x10, 0x6B, 0x65, 0x47, 0x79 } - -PBL_APP_INFO(MY_UUID, - "Silly Walk - No Seconds", "Dansl", - 1, 0, /* App version */ - RESOURCE_ID_IMAGE_MENU_ICON, - APP_INFO_WATCH_FACE); - -Window window; - -BmpContainer background_image_container; - -RotBmpPairContainer hour_hand_image_container; -RotBmpPairContainer minute_hand_image_container; -RotBmpPairContainer second_hand_image_container; - -void update_watch(PblTm* t){ - - //rotbmp_pair_layer_set_angle(&hour_hand_image_container.layer, ((t->tm_hour % 12) * 30) + (t->tm_min/2)); - hour_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.layer.frame.origin.x = (144/2) - (hour_hand_image_container.layer.layer.frame.size.w/2); - hour_hand_image_container.layer.layer.frame.origin.y = (168/2) - (hour_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&hour_hand_image_container.layer.layer); - - //rotbmp_pair_layer_set_angle(&minute_hand_image_container.layer, t->tm_min * 6); - minute_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.layer.frame.origin.x = (144/2) - (minute_hand_image_container.layer.layer.frame.size.w/2); - minute_hand_image_container.layer.layer.frame.origin.y = (168/2) - (minute_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&minute_hand_image_container.layer.layer); - -} - -// Called once per second -void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { - update_watch(t->tick_time); -} - - -// Handle the start-up of the app -void handle_init(AppContextRef app_ctx) { - - // Create our app's base window - window_init(&window, "Silly Walk"); - window_stack_push(&window, true); - window_set_background_color(&window, GColorBlack); - - resource_init_current_app(&APP_RESOURCES); - - // Set up a layer for the static watch face background - bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); - layer_add_child(&window.layer, &background_image_container.layer.layer); - - - // Set up a layer for the hour hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_HAND_WHITE, RESOURCE_ID_IMAGE_HOUR_HAND_BLACK, &hour_hand_image_container); - rotbmp_pair_layer_set_src_ic(&hour_hand_image_container.layer, GPoint(33, 40)); - layer_add_child(&window.layer, &hour_hand_image_container.layer.layer); - - - // Set up a layer for the minute hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_MINUTE_HAND_WHITE, RESOURCE_ID_IMAGE_MINUTE_HAND_BLACK, &minute_hand_image_container); - rotbmp_pair_layer_set_src_ic(&minute_hand_image_container.layer, GPoint(16, 60)); - layer_add_child(&window.layer, &minute_hand_image_container.layer.layer); - - - PblTm t; - get_time(&t); - update_watch(&t); - -} - -void handle_deinit(AppContextRef ctx) { - - bmp_deinit_container(&background_image_container); - rotbmp_pair_deinit_container(&hour_hand_image_container); - rotbmp_pair_deinit_container(&minute_hand_image_container); - rotbmp_pair_deinit_container(&second_hand_image_container); -} - - -// The main event/run loop for our app -void pbl_main(void *params) { - PebbleAppHandlers handlers = { - - // Handle app start - .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); -}
\ No newline at end of file diff --git a/silly_walk_simple/resources/src/images/hour_hand.png b/silly_walk_simple/resources/src/images/hour_hand.png Binary files differdeleted file mode 100644 index 342889a..0000000 --- a/silly_walk_simple/resources/src/images/hour_hand.png +++ /dev/null diff --git a/silly_walk_simple/resources/src/images/icon.png b/silly_walk_simple/resources/src/images/icon.png Binary files differdeleted file mode 100644 index a34703d..0000000 --- a/silly_walk_simple/resources/src/images/icon.png +++ /dev/null diff --git a/silly_walk_simple/resources/src/images/minute_hand.png b/silly_walk_simple/resources/src/images/minute_hand.png Binary files differdeleted file mode 100644 index 6a35022..0000000 --- a/silly_walk_simple/resources/src/images/minute_hand.png +++ /dev/null diff --git a/silly_walk_simple/resources/src/images/seconds_hand.png b/silly_walk_simple/resources/src/images/seconds_hand.png Binary files differdeleted file mode 100644 index 2c66619..0000000 --- a/silly_walk_simple/resources/src/images/seconds_hand.png +++ /dev/null diff --git a/silly_walk_simple/resources/src/resource_map.json b/silly_walk_simple/resources/src/resource_map.json deleted file mode 100644 index 4e9fe55..0000000 --- a/silly_walk_simple/resources/src/resource_map.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "friendlyVersion": "dev_0.0", - "versionDefName": "APP_RESOURCES", - - "media": [ - - { - "type": "png", - "defName": "IMAGE_MENU_ICON", - "file": "images/icon.png" - }, - - { - "type": "png", - "defName": "IMAGE_BACKGROUND", - "file": "images/background.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_HOUR_HAND", - "file": "images/hour_hand.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_MINUTE_HAND", - "file": "images/minute_hand.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_SECOND_HAND", - "file": "images/seconds_hand.png" - } - - ] -} - diff --git a/silly_walk_simple/silly_walk_simple.pbw b/silly_walk_simple/silly_walk_simple.pbw Binary files differdeleted file mode 100644 index 96d4f88..0000000 --- a/silly_walk_simple/silly_walk_simple.pbw +++ /dev/null diff --git a/silly_walk_simple/src/silly_walk_simple.c b/silly_walk_simple/src/silly_walk_simple.c deleted file mode 100644 index 700721d..0000000 --- a/silly_walk_simple/src/silly_walk_simple.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "pebble_os.h" -#include "pebble_app.h" -#include "pebble_fonts.h" - - -#define MY_UUID { 0x08, 0x08, 0xBD, 0x57, 0x94, 0x61, 0x4D, 0xA5, 0x98, 0xF4, 0x61, 0x6D, 0xA2, 0x5E, 0x6B, 0xA8 } -PBL_APP_INFO(MY_UUID, - "Silly Walk Simple", "Dansl", - 1, 0, /* App version */ - RESOURCE_ID_IMAGE_MENU_ICON, - APP_INFO_WATCH_FACE); - -Window window; - -BmpContainer background_image_container; - -RotBmpPairContainer hour_hand_image_container; -RotBmpPairContainer minute_hand_image_container; -RotBmpPairContainer second_hand_image_container; - -void update_watch(PblTm* t){ - - //rotbmp_pair_layer_set_angle(&hour_hand_image_container.layer, ((t->tm_hour % 12) * 30) + (t->tm_min/2)); - hour_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.layer.frame.origin.x = (144/2) - (hour_hand_image_container.layer.layer.frame.size.w/2); - hour_hand_image_container.layer.layer.frame.origin.y = (168/2) - (hour_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&hour_hand_image_container.layer.layer); - - //rotbmp_pair_layer_set_angle(&minute_hand_image_container.layer, t->tm_min * 6); - minute_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.layer.frame.origin.x = (144/2) - (minute_hand_image_container.layer.layer.frame.size.w/2); - minute_hand_image_container.layer.layer.frame.origin.y = (168/2) - (minute_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&minute_hand_image_container.layer.layer); - - //rotbmp_pair_layer_set_angle(&second_hand_image_container.layer, t->tm_sec * 6); - second_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (t->tm_sec * 6) / 360; - second_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (t->tm_sec * 6) / 360; - second_hand_image_container.layer.layer.frame.origin.x = (144/2) - (second_hand_image_container.layer.layer.frame.size.w/2); - second_hand_image_container.layer.layer.frame.origin.y = (168/2) - (second_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&second_hand_image_container.layer.layer); -} - -// Called once per second -void handle_second_tick(AppContextRef ctx, PebbleTickEvent *t) { - update_watch(t->tick_time); -} - - -// Handle the start-up of the app -void handle_init(AppContextRef app_ctx) { - - // Create our app's base window - window_init(&window, "Silly Walk Simple"); - window_stack_push(&window, true); - window_set_background_color(&window, GColorBlack); - - resource_init_current_app(&APP_RESOURCES); - - // Set up a layer for the static watch face background - bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); - layer_add_child(&window.layer, &background_image_container.layer.layer); - - - // Set up a layer for the hour hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_HAND_WHITE, RESOURCE_ID_IMAGE_HOUR_HAND_BLACK, &hour_hand_image_container); - rotbmp_pair_layer_set_src_ic(&hour_hand_image_container.layer, GPoint(33, 40)); - layer_add_child(&window.layer, &hour_hand_image_container.layer.layer); - - - // Set up a layer for the minute hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_MINUTE_HAND_WHITE, RESOURCE_ID_IMAGE_MINUTE_HAND_BLACK, &minute_hand_image_container); - rotbmp_pair_layer_set_src_ic(&minute_hand_image_container.layer, GPoint(16, 60)); - layer_add_child(&window.layer, &minute_hand_image_container.layer.layer); - - - // Set up a layer for the second hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_SECOND_HAND_WHITE, RESOURCE_ID_IMAGE_SECOND_HAND_BLACK, &second_hand_image_container); - rotbmp_pair_layer_set_src_ic(&second_hand_image_container.layer, GPoint(7, 44)); - layer_add_child(&window.layer, &second_hand_image_container.layer.layer); - - PblTm t; - get_time(&t); - update_watch(&t); - -} - -void handle_deinit(AppContextRef ctx) { - - bmp_deinit_container(&background_image_container); - rotbmp_pair_deinit_container(&hour_hand_image_container); - rotbmp_pair_deinit_container(&minute_hand_image_container); - rotbmp_pair_deinit_container(&second_hand_image_container); -} - - -// The main event/run loop for our app -void pbl_main(void *params) { - PebbleAppHandlers handlers = { - - // Handle app start - .init_handler = &handle_init, - .deinit_handler = &handle_deinit, - - // Handle time updates - .tick_info = { - .tick_handler = &handle_second_tick, - .tick_units = SECOND_UNIT - } - - }; - app_event_loop(params, &handlers); -}
\ No newline at end of file diff --git a/silly_walk_simple_no_seconds/resources/src/images/background.png b/silly_walk_simple_no_seconds/resources/src/images/background.png Binary files differdeleted file mode 100644 index 6e726bc..0000000 --- a/silly_walk_simple_no_seconds/resources/src/images/background.png +++ /dev/null diff --git a/silly_walk_simple_no_seconds/resources/src/images/hour_hand.png b/silly_walk_simple_no_seconds/resources/src/images/hour_hand.png Binary files differdeleted file mode 100644 index 342889a..0000000 --- a/silly_walk_simple_no_seconds/resources/src/images/hour_hand.png +++ /dev/null diff --git a/silly_walk_simple_no_seconds/resources/src/images/icon.png b/silly_walk_simple_no_seconds/resources/src/images/icon.png Binary files differdeleted file mode 100644 index a34703d..0000000 --- a/silly_walk_simple_no_seconds/resources/src/images/icon.png +++ /dev/null diff --git a/silly_walk_simple_no_seconds/resources/src/images/minute_hand.png b/silly_walk_simple_no_seconds/resources/src/images/minute_hand.png Binary files differdeleted file mode 100644 index 6a35022..0000000 --- a/silly_walk_simple_no_seconds/resources/src/images/minute_hand.png +++ /dev/null diff --git a/silly_walk_simple_no_seconds/resources/src/images/seconds_hand.png b/silly_walk_simple_no_seconds/resources/src/images/seconds_hand.png Binary files differdeleted file mode 100644 index 2c66619..0000000 --- a/silly_walk_simple_no_seconds/resources/src/images/seconds_hand.png +++ /dev/null diff --git a/silly_walk_simple_no_seconds/resources/src/resource_map.json b/silly_walk_simple_no_seconds/resources/src/resource_map.json deleted file mode 100644 index 4e9fe55..0000000 --- a/silly_walk_simple_no_seconds/resources/src/resource_map.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "friendlyVersion": "dev_0.0", - "versionDefName": "APP_RESOURCES", - - "media": [ - - { - "type": "png", - "defName": "IMAGE_MENU_ICON", - "file": "images/icon.png" - }, - - { - "type": "png", - "defName": "IMAGE_BACKGROUND", - "file": "images/background.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_HOUR_HAND", - "file": "images/hour_hand.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_MINUTE_HAND", - "file": "images/minute_hand.png" - }, - - { - "type": "png-trans", - "defName": "IMAGE_SECOND_HAND", - "file": "images/seconds_hand.png" - } - - ] -} - diff --git a/silly_walk_simple_no_seconds/silly_walk_simple_no_seconds.pbw b/silly_walk_simple_no_seconds/silly_walk_simple_no_seconds.pbw Binary files differdeleted file mode 100644 index 2713d89..0000000 --- a/silly_walk_simple_no_seconds/silly_walk_simple_no_seconds.pbw +++ /dev/null diff --git a/silly_walk_simple_no_seconds/src/silly_walk_simple_no_seconds.c b/silly_walk_simple_no_seconds/src/silly_walk_simple_no_seconds.c deleted file mode 100644 index f173df7..0000000 --- a/silly_walk_simple_no_seconds/src/silly_walk_simple_no_seconds.c +++ /dev/null @@ -1,104 +0,0 @@ -#include "pebble_os.h" -#include "pebble_app.h" -#include "pebble_fonts.h" - - -#define MY_UUID { 0xC2, 0x01, 0x53, 0xB1, 0xD7, 0xBD, 0x47, 0xCC, 0x90, 0xD6, 0x02, 0x2B, 0x51, 0xBA, 0x7B, 0x89 } - -PBL_APP_INFO(MY_UUID, - "Silly Walk Simple - No Seconds", "Dansl", - 1, 0, /* App version */ - RESOURCE_ID_IMAGE_MENU_ICON, - APP_INFO_WATCH_FACE); - -Window window; - -BmpContainer background_image_container; - -RotBmpPairContainer hour_hand_image_container; -RotBmpPairContainer minute_hand_image_container; -RotBmpPairContainer second_hand_image_container; - -void update_watch(PblTm* t){ - - //rotbmp_pair_layer_set_angle(&hour_hand_image_container.layer, ((t->tm_hour % 12) * 30) + (t->tm_min/2)); - hour_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 30) + (t->tm_min/2)) / 360; - hour_hand_image_container.layer.layer.frame.origin.x = (144/2) - (hour_hand_image_container.layer.layer.frame.size.w/2); - hour_hand_image_container.layer.layer.frame.origin.y = (168/2) - (hour_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&hour_hand_image_container.layer.layer); - - //rotbmp_pair_layer_set_angle(&minute_hand_image_container.layer, t->tm_min * 6); - minute_hand_image_container.layer.white_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.black_layer.rotation = TRIG_MAX_ANGLE * (t->tm_min * 6) / 360; - minute_hand_image_container.layer.layer.frame.origin.x = (144/2) - (minute_hand_image_container.layer.layer.frame.size.w/2); - minute_hand_image_container.layer.layer.frame.origin.y = (168/2) - (minute_hand_image_container.layer.layer.frame.size.h/2); - layer_mark_dirty(&minute_hand_image_container.layer.layer); - -} - -// Called once per second -void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { - update_watch(t->tick_time); -} - - -// Handle the start-up of the app -void handle_init(AppContextRef app_ctx) { - - // Create our app's base window - window_init(&window, "Silly Walk"); - window_stack_push(&window, true); - window_set_background_color(&window, GColorBlack); - - resource_init_current_app(&APP_RESOURCES); - - // Set up a layer for the static watch face background - bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); - layer_add_child(&window.layer, &background_image_container.layer.layer); - - - // Set up a layer for the hour hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_HAND_WHITE, RESOURCE_ID_IMAGE_HOUR_HAND_BLACK, &hour_hand_image_container); - rotbmp_pair_layer_set_src_ic(&hour_hand_image_container.layer, GPoint(33, 40)); - layer_add_child(&window.layer, &hour_hand_image_container.layer.layer); - - - // Set up a layer for the minute hand - rotbmp_pair_init_container(RESOURCE_ID_IMAGE_MINUTE_HAND_WHITE, RESOURCE_ID_IMAGE_MINUTE_HAND_BLACK, &minute_hand_image_container); - rotbmp_pair_layer_set_src_ic(&minute_hand_image_container.layer, GPoint(16, 60)); - layer_add_child(&window.layer, &minute_hand_image_container.layer.layer); - - - PblTm t; - get_time(&t); - update_watch(&t); - -} - -void handle_deinit(AppContextRef ctx) { - - bmp_deinit_container(&background_image_container); - rotbmp_pair_deinit_container(&hour_hand_image_container); - rotbmp_pair_deinit_container(&minute_hand_image_container); - rotbmp_pair_deinit_container(&second_hand_image_container); -} - - -// The main event/run loop for our app -void pbl_main(void *params) { - PebbleAppHandlers handlers = { - - // Handle app start - .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); -}
\ No newline at end of file |