From 9e801e6f1f20fb734a72ad301e74e1c7187143aa Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 11 Nov 2015 18:42:04 -0700 Subject: [PATCH] Trying to make configurable --- appinfo.json | 17 +++++++++--- src/main.c | 27 ++++++++++++++----- src/pebble-js-app.js | 28 ++++++++++++++++++++ wscript | 62 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 src/pebble-js-app.js create mode 100644 wscript diff --git a/appinfo.json b/appinfo.json index a844f34..1a33425 100644 --- a/appinfo.json +++ b/appinfo.json @@ -1,7 +1,18 @@ { - "appKeys": {}, + "appKeys": { + "bluetooth": 1, + "color-bg": 2, + "color-day": 4, + "color-hr": 9, + "color-min": 8, + "color-mon": 5, + "color-num": 3, + "color-sec": 7, + "color-tic": 6, + "seconds": 0 + }, "capabilities": [ - "" + "configurable" ], "companyName": "dartcatcher@gmail.com", "longName": "Neale's Watch", @@ -29,7 +40,7 @@ "basalt", "chalk" ], - "uuid": "e0b60de0-c43e-4dcd-817b-b60c1be26cb5", + "uuid": "8287a53c-1b7e-4f4b-9104-608de13b9f77", "versionLabel": "1.0", "watchapp": { "watchface": true diff --git a/src/main.c b/src/main.c index 5017fba..9a7bda1 100644 --- a/src/main.c +++ b/src/main.c @@ -5,8 +5,7 @@ static Window *window; static Layer *s_simple_bg_layer, *s_date_layer, *s_hands_layer; static TextLayer *s_bt_label, *s_day_label, *s_mon_label; - - +static GColor second_color; static GPath *s_tic_path; static GPath *s_second_arrow, *s_minute_arrow, *s_hour_arrow; static char s_mon_buffer[4], s_day_buffer[6]; @@ -81,9 +80,7 @@ static void hands_update_proc(Layer *layer, GContext *ctx) { if (seconds) { // second hand -#ifdef PBL_COLOR - graphics_context_set_fill_color(ctx, GColorJaegerGreen); -#endif + graphics_context_set_fill_color(ctx, second_color); gpath_rotate_to(s_second_arrow, TRIG_MAX_ANGLE * t->tm_sec / 60); gpath_draw_filled(ctx, s_second_arrow); //gpath_draw_outline(ctx, s_second_arrow); @@ -235,9 +232,23 @@ static void bt_handler(bool connected) { layer_mark_dirty(s_date_layer); } +static void in_received_handler(DictionaryIterator *rec, void *context) { + Tuple *sec_color_tuple = dict_find(rec, CONFIG_KEY_COLOR_SEC); + + if (sec_color_tuple) { + second_color = GColorFromHex(sec_color_tuple->value->int32); + } +} + +static void in_dropped_handler(AppMessageResult reason, void *context) { + // What could we possibly do here? +} + static void init() { fg = GColorBlack; bg = GColorWhite; + second_color = COLOR_FALLBACK(GColorWindsorTan, GColorBlack); + window = window_create(); window_set_window_handlers(window, (WindowHandlers) { .load = window_load, @@ -264,12 +275,16 @@ static void init() { bluetooth_connection_service_subscribe(bt_handler); bt_connected = bluetooth_connection_service_peek(); - + if (seconds) { tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick); } else { tick_timer_service_subscribe(MINUTE_UNIT, handle_second_tick); } + + app_message_register_inbox_received(in_received_handler); + app_message_register_inbox_dropped(in_dropped_handler); + app_message_open(256, 64); } static void deinit() { diff --git a/src/pebble-js-app.js b/src/pebble-js-app.js new file mode 100644 index 0000000..fab85d0 --- /dev/null +++ b/src/pebble-js-app.js @@ -0,0 +1,28 @@ +var initialized = false; + +function appMessageAck(e) { + console.log("Configuration sent"); +} + +function appMessageNak(e) { + console.log("Configuration not sent: ", e); +} + + +Pebble.addEventListener("ready", function() { + console.log("ready called!"); + initialized = true; +}); + +Pebble.addEventListener("showConfiguration", function() { + console.log("showing configuration"); + Pebble.openURL('http://woozle.org/t/twatch/'); +}); + +Pebble.addEventListener("webviewclosed", function(e) { + console.log("configuration closed"); + // webview closed + var options = JSON.parse(decodeURIComponent(e.response)); + console.log("Options = " + JSON.stringify(options)); + Pebble.sendAppMessage(options, appMessageAck, appMessageNak); +}); diff --git a/wscript b/wscript new file mode 100644 index 0000000..b20f58f --- /dev/null +++ b/wscript @@ -0,0 +1,62 @@ + + # +# This file is the default set of rules to compile a Pebble project. +# +# Feel free to customize this to your needs. +# + +import os.path +try: + from sh import CommandNotFound, jshint, cat, ErrorReturnCode_2 + hint = jshint +except (ImportError, CommandNotFound): + hint = None + +top = '.' +out = 'build' + +def options(ctx): + ctx.load('pebble_sdk') + +def configure(ctx): + ctx.load('pebble_sdk') + +def build(ctx): + if False and hint is not None: + try: + hint([node.abspath() for node in ctx.path.ant_glob("src/**/*.js")], _tty_out=False) # no tty because there are none in the cloudpebble sandbox. + except ErrorReturnCode_2 as e: + ctx.fatal("\nJavaScript linting failed (you can disable this in Project Settings):\n" + e.stdout) + + # Concatenate all our JS files (but not recursively), and only if any JS exists in the first place. + ctx.path.make_node('src/js/').mkdir() + js_paths = ctx.path.ant_glob(['src/*.js', 'src/**/*.js']) + if js_paths: + ctx(rule='cat ${SRC} > ${TGT}', source=js_paths, target='pebble-js-app.js') + has_js = True + else: + has_js = False + + ctx.load('pebble_sdk') + + build_worker = os.path.exists('worker_src') + binaries = [] + + for p in ctx.env.TARGET_PLATFORMS: + ctx.set_env(ctx.all_envs[p]) + ctx.set_group(ctx.env.PLATFORM_NAME) + app_elf='{}/pebble-app.elf'.format(p) + ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), + target=app_elf) + + if build_worker: + worker_elf='{}/pebble-worker.elf'.format(p) + binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf}) + ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), + target=worker_elf) + else: + binaries.append({'platform': p, 'app_elf': app_elf}) + + ctx.set_group('bundle') + ctx.pbl_bundle(binaries=binaries, js='pebble-js-app.js' if has_js else []) + \ No newline at end of file