Settable face color

I hope the time I sank into this pays off in an installed base of >1
This commit is contained in:
Neale Pickett 2016-05-18 14:56:28 -06:00
parent a23fed6fbe
commit f348006bcc
5 changed files with 121 additions and 20 deletions

View File

@ -1,7 +1,9 @@
{ {
"appKeys": {}, "appKeys": {
"color-face": 0
},
"capabilities": [ "capabilities": [
"" "configurable"
], ],
"companyName": "dartcatcher@gmail.com", "companyName": "dartcatcher@gmail.com",
"enableMultiJS": true, "enableMultiJS": true,
@ -33,7 +35,7 @@
"chalk" "chalk"
], ],
"uuid": "f00033b1-2e6c-490c-a650-99d9399b2163", "uuid": "f00033b1-2e6c-490c-a650-99d9399b2163",
"versionLabel": "1.2", "versionLabel": "1.3",
"watchapp": { "watchapp": {
"watchface": true "watchface": true
} }

28
src/js/app.js Normal file
View File

@ -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);
});

View File

@ -1,4 +1,5 @@
#include <pebble.h> #include <pebble.h>
#include "settings.h"
#define HAND_OUT 200 #define HAND_OUT 200
#define HAND_IN 45 #define HAND_IN 45
@ -10,8 +11,9 @@
static Window *window; static Window *window;
static Layer *s_bg_layer, *s_hands_layer; static Layer *s_bg_layer, *s_hands_layer;
static TextLayer *s_day_label, *s_bt_label; static TextLayer *s_day_label, *s_bt_label;
static GColor face_color;
static GColor accent_color; static GColor accent_color;
static GColor text_color; static GColor hand_color;
static char s_day_buffer[15]; 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) { static void bg_update_proc(Layer *layer, GContext *ctx) {
// Draw Background, which is just blackness // Draw Background, which is just a solid color
graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_fill_color(ctx, face_color);
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
if (bt_connected) { if (bt_connected) {
@ -48,7 +50,7 @@ static void hands_update_proc(Layer *layer, GContext *ctx) {
// hour hand // hour hand
graphics_context_set_stroke_width(ctx, HOUR_WIDTH); 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, 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_IN),
point_of_polar(TRIG_MAX_ANGLE * (t->tm_hour % 12) / 12, HAND_OUT)); 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); 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) { static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window); Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_bounds(window_layer); GRect bounds = layer_get_bounds(window_layer);
@ -115,7 +138,7 @@ static void window_load(Window *window) {
// Hands // Hands
s_hands_layer = layer_create(bounds); s_hands_layer = layer_create(bounds);
layer_set_update_proc(s_hands_layer, hands_update_proc); 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 // Day
#ifdef PBL_ROUND #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_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_text(s_day_label, s_day_buffer);
text_layer_set_background_color(s_day_label, GColorClear); 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)); layer_add_child(s_hands_layer, text_layer_get_layer(s_day_label));
// Missing phone // 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_alignment(s_bt_label, GTextAlignmentCenter);
text_layer_set_text(s_bt_label, ""); text_layer_set_text(s_bt_label, "");
text_layer_set_background_color(s_bt_label, GColorClear); 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))); 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)); layer_add_child(s_bg_layer, text_layer_get_layer(s_bt_label));
set_colors();
} }
static void window_unload(Window *window) { static void window_unload(Window *window) {
@ -166,16 +189,8 @@ static void tick_subscribe() {
static void init() { static void init() {
// Pick out a color // Pick out a color
#ifdef PBL_COLOR face_color = GColorBlack;
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);
s_day_buffer[0] = '\0'; s_day_buffer[0] = '\0';
@ -194,6 +209,8 @@ static void init() {
bluetooth_connection_service_subscribe(bt_handler); bluetooth_connection_service_subscribe(bt_handler);
bt_connected = bluetooth_connection_service_peek(); bt_connected = bluetooth_connection_service_peek();
settings_init(set_colors);
} }
static void deinit() { static void deinit() {

44
src/settings.c Normal file
View File

@ -0,0 +1,44 @@
#include <pebble.h>
#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);
}

10
src/settings.h Normal file
View File

@ -0,0 +1,10 @@
#include <pebble.h>
#pragma once
typedef enum {
KEY_COLOR_FACE = 0,
KEY_SENTRY
} MessageKey;
GColor settings_get_color(MessageKey idx);
void settings_init(void (*cb)(void));