diff --git a/appinfo.json b/appinfo.json index 149ca47..3b6c589 100644 --- a/appinfo.json +++ b/appinfo.json @@ -1,7 +1,9 @@ { - "appKeys": {}, + "appKeys": { + "color-face": 0 + }, "capabilities": [ - "" + "configurable" ], "companyName": "dartcatcher@gmail.com", "enableMultiJS": true, @@ -33,7 +35,7 @@ "chalk" ], "uuid": "f00033b1-2e6c-490c-a650-99d9399b2163", - "versionLabel": "1.2", + "versionLabel": "1.3", "watchapp": { "watchface": true } diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..0986ff5 --- /dev/null +++ b/src/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/neale/misc/twatch-config/chalice.html'); +}); + +Pebble.addEventListener("webviewclosed", function(e) { + console.log("configuration closed"); + // webview closed + var options = JSON.parse(decodeURIComponent(e.response)); + console.log("Options = " + options); + Pebble.sendAppMessage(options, appMessageAck, appMessageNak); +}); diff --git a/src/main.c b/src/main.c index f431fb6..a30e2e8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include "settings.h" #define HAND_OUT 200 #define HAND_IN 45 @@ -10,8 +11,9 @@ static Window *window; static Layer *s_bg_layer, *s_hands_layer; static TextLayer *s_day_label, *s_bt_label; +static GColor face_color; static GColor accent_color; -static GColor text_color; +static GColor hand_color; static char s_day_buffer[15]; @@ -30,8 +32,8 @@ static GPoint point_of_polar(int32_t theta, int r) { } static void bg_update_proc(Layer *layer, GContext *ctx) { - // Draw Background, which is just blackness - graphics_context_set_fill_color(ctx, GColorBlack); + // Draw Background, which is just a solid color + graphics_context_set_fill_color(ctx, face_color); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); if (bt_connected) { @@ -48,7 +50,7 @@ static void hands_update_proc(Layer *layer, GContext *ctx) { // hour hand graphics_context_set_stroke_width(ctx, HOUR_WIDTH); - graphics_context_set_stroke_color(ctx, GColorWhite); + graphics_context_set_stroke_color(ctx, hand_color); graphics_draw_line(ctx, point_of_polar(TRIG_MAX_ANGLE * (t->tm_hour % 12) / 12, HAND_IN), point_of_polar(TRIG_MAX_ANGLE * (t->tm_hour % 12) / 12, HAND_OUT)); @@ -103,6 +105,27 @@ static void handle_tick(struct tm *tick_time, TimeUnits units_changed) { layer_mark_dirty(s_hands_layer); } +static void set_colors() { + face_color = settings_get_color(KEY_COLOR_FACE); + layer_mark_dirty(s_bg_layer); + +#ifdef PBL_COLOR + do { + uint8_t argb = rand() % 0b00111111; + accent_color = (GColor8){ .argb = argb | 0b11000000 }; + } while (gcolor_equal(accent_color, face_color)); +#else + accent_color = gcolor_legible_over(face_color); +#endif + hand_color = gcolor_legible_over(face_color); + layer_mark_dirty(s_hands_layer); + + APP_LOG(APP_LOG_LEVEL_DEBUG, "Holy crap! Colors are %06x and %06x!", face_color.argb, accent_color.argb); + + text_layer_set_text_color(s_day_label, gcolor_legible_over(accent_color)); + text_layer_set_text_color(s_bt_label, gcolor_legible_over(face_color)); +} + static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); @@ -115,7 +138,7 @@ static void window_load(Window *window) { // Hands s_hands_layer = layer_create(bounds); layer_set_update_proc(s_hands_layer, hands_update_proc); - layer_add_child(window_layer, s_hands_layer); + layer_add_child(s_bg_layer, s_hands_layer); // Day #ifdef PBL_ROUND @@ -128,7 +151,6 @@ static void window_load(Window *window) { text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text(s_day_label, s_day_buffer); text_layer_set_background_color(s_day_label, GColorClear); - text_layer_set_text_color(s_day_label, text_color); layer_add_child(s_hands_layer, text_layer_get_layer(s_day_label)); // Missing phone @@ -140,9 +162,10 @@ static void window_load(Window *window) { text_layer_set_text_alignment(s_bt_label, GTextAlignmentCenter); text_layer_set_text(s_bt_label, ""); text_layer_set_background_color(s_bt_label, GColorClear); - text_layer_set_text_color(s_bt_label, COLOR_FALLBACK(GColorDarkGray, GColorWhite)); text_layer_set_font(s_bt_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYMBOLS_64))); layer_add_child(s_bg_layer, text_layer_get_layer(s_bt_label)); + + set_colors(); } static void window_unload(Window *window) { @@ -166,16 +189,8 @@ static void tick_subscribe() { static void init() { // Pick out a color -#ifdef PBL_COLOR - uint32_t argb = 0; - while (argb == 0) { - argb = rand() % 0b00111111; - } - accent_color = (GColor8){ .argb = argb + 0b11000000 }; -#else - accent_color = GColorWhite; -#endif - text_color = gcolor_legible_over(accent_color); + face_color = GColorBlack; + s_day_buffer[0] = '\0'; @@ -194,6 +209,8 @@ static void init() { bluetooth_connection_service_subscribe(bt_handler); bt_connected = bluetooth_connection_service_peek(); + + settings_init(set_colors); } static void deinit() { diff --git a/src/settings.c b/src/settings.c new file mode 100644 index 0000000..a011413 --- /dev/null +++ b/src/settings.c @@ -0,0 +1,44 @@ +#include +#include "settings.h" + +static void (*callback)(void); + +GColor settings_get_color(MessageKey key) { + if (! persist_exists(key)) { + return GColorBlack; + } + + return GColorFromHEX(persist_read_int(key)); +} + +static void in_received_handler(DictionaryIterator *rec, void *context) { + int i; + + for (i = 0; i < KEY_SENTRY; i += 1) { + Tuple *cur = dict_find(rec, i); + + if (! cur) { + APP_LOG(APP_LOG_LEVEL_DEBUG, "Holy crap! Key %i isn't around!", i); + continue; + } + + switch (i) { + case KEY_COLOR_FACE: + persist_write_int(i, cur->value->int32); + break; + } + } + + callback(); +} + +static void in_dropped_handler(AppMessageResult reason, void *context) { + // XXX: I don't understand what we could possibly do here +} + +void settings_init(void (*cb)(void)) { + callback = cb; + app_message_register_inbox_received(in_received_handler); + app_message_register_inbox_dropped(in_dropped_handler); + app_message_open(256, 64); +} \ No newline at end of file diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..a7319da --- /dev/null +++ b/src/settings.h @@ -0,0 +1,10 @@ +#include +#pragma once + +typedef enum { + KEY_COLOR_FACE = 0, + KEY_SENTRY +} MessageKey; + +GColor settings_get_color(MessageKey idx); +void settings_init(void (*cb)(void)); \ No newline at end of file