From 2b631296d8d6d14816810825985832e14afd618d Mon Sep 17 00:00:00 2001 From: Ken Arromdee Date: Sat, 31 Oct 2020 16:29:08 -0400 Subject: [PATCH 01/10] 1) Fix daylight savings bug leading to 1 1 2 3 4 5 2) Add ability to make Saturday, Sunday, and US Federal holidays red --- package.json | 13 ++++++-- src/c/appendix/app_message.c | 13 ++++++-- src/c/appendix/config.h | 5 ++- src/c/appendix/persist.c | 7 +++-- src/c/layers/calendar_layer.c | 59 ++++++++++++++++++++++++++++++++--- src/pkjs/clay/config.js | 18 +++++++++++ src/pkjs/index.js | 5 ++- 7 files changed, 106 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index accec77..2b4b5cf 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,13 @@ "name": "ForecasWatch 2", "author": "Matt Rossman", "version": "1.14.0", - "keywords": ["pebble-app"], + "keywords": [ + "pebble-app" + ], "private": true, - "dependencies": {}, + "dependencies": { + "pebble-clay": "^1.0.4" + }, "pebble": { "displayName": "FCW2", "uuid": "7ed9b053-1521-4e49-be8b-6e12c68978ae", @@ -69,7 +73,10 @@ "CLAY_SHOW_BT", "CLAY_SHOW_BT_DISCONNECT", "CLAY_VIBE", - "CLAY_SHOW_AM_PM" + "CLAY_SHOW_AM_PM", + "CLAY_COLOR_SATURDAY", + "CLAY_COLOR_SUNDAY", + "CLAY_COLOR_US_FEDERAL" ] } } diff --git a/src/c/appendix/app_message.c b/src/c/appendix/app_message.c index c9efe0e..fdef4b7 100644 --- a/src/c/appendix/app_message.c +++ b/src/c/appendix/app_message.c @@ -29,6 +29,9 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) Tuple *clay_show_bt_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_BT); Tuple *clay_show_bt_disconnect_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_BT_DISCONNECT); Tuple *clay_show_am_pm_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_AM_PM); + Tuple *clay_color_saturday = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SATURDAY); + Tuple *clay_color_sunday = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SUNDAY); + Tuple *clay_color_us_federal = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_US_FEDERAL); if(temp_trend_tuple && temp_trend_tuple && forecast_start_tuple && num_entries_tuple && city_tuple && sun_events_tuple) { // Weather data received @@ -68,6 +71,9 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) bool show_am_pm = (bool) (clay_show_am_pm_tuple->value->int16); int16_t time_font = clay_time_font_tuple->value->int16; GColor color_today = GColorFromHEX(clay_color_today_tuple->value->int32); + bool color_saturday = (bool) (clay_color_saturday->value->int16); + bool color_sunday = (bool) (clay_color_sunday->value->int16); + bool color_us_federal = (bool) (clay_color_us_federal->value->int16); Config config = (Config) { .celsius = clay_celsius, .time_lead_zero = time_lead_zero, @@ -79,7 +85,10 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) .show_qt = show_qt, .show_bt = show_bt, .show_bt_disconnect = show_bt_disconnect, - .show_am_pm = show_am_pm + .show_am_pm = show_am_pm, + .color_saturday = color_saturday, + .color_sunday = color_sunday, + .color_us_federal = color_us_federal, }; persist_set_config(config); main_window_refresh(); @@ -99,4 +108,4 @@ void app_message_init() { const int inbox_size = 256; const int outbox_size = 0; app_message_open(inbox_size, outbox_size); -} \ No newline at end of file +} diff --git a/src/c/appendix/config.h b/src/c/appendix/config.h index 05b075a..efb29ba 100644 --- a/src/c/appendix/config.h +++ b/src/c/appendix/config.h @@ -15,6 +15,9 @@ typedef struct { bool show_am_pm; int16_t time_font; GColor color_today; + bool color_saturday; + bool color_sunday; + bool color_us_federal; } Config; Config *g_config; @@ -35,4 +38,4 @@ int config_n_today(); GColor config_today_color(); -GFont config_time_font(); \ No newline at end of file +GFont config_time_font(); diff --git a/src/c/appendix/persist.c b/src/c/appendix/persist.c index b26520e..6b355b9 100644 --- a/src/c/appendix/persist.c +++ b/src/c/appendix/persist.c @@ -53,7 +53,10 @@ void persist_init() { .show_bt = true, .show_bt_disconnect = true, .vibe = false, - .show_am_pm = false + .show_am_pm = false, + .color_saturday = false, + .color_sunday = false, + .color_us_federal = false }; persist_set_config(config); } @@ -146,4 +149,4 @@ void persist_set_sun_event_times(time_t *data, const size_t size) { void persist_set_config(Config config) { persist_write_data(CONFIG, &config, sizeof(Config)); config_refresh(); // Refresh global config variable -} \ No newline at end of file +} diff --git a/src/c/layers/calendar_layer.c b/src/c/layers/calendar_layer.c index f51d75c..062c3a1 100644 --- a/src/c/layers/calendar_layer.c +++ b/src/c/layers/calendar_layer.c @@ -8,6 +8,40 @@ static Layer *s_calendar_layer; static TextLayer *s_calendar_text_layers[NUM_WEEKS * DAYS_PER_WEEK]; +static struct tm *get_tm(int days_from_today); + +static bool is_colored_calendar_day(int i) +{ + const int i_today = config_n_today(); + tm *t = get_tm(i - i_today); + + if ((g_config->color_sunday && t->tm_wday == 0) || + (g_config->color_saturday && t->tm_wday == 6)) + return true; + if (g_config->color_us_federal) { + if (t->tm_mon == 0 && t->tm_mday == 1) + return true; + if (t->tm_mon == 0 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) + return true; + if (t->tm_mon == 1 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) + return true; + if (t->tm_mon == 4 && t->tm_mday >= 25 && t->tm_mday <= 31 && t->tm_wday == 1) + return true; + if (t->tm_mon == 6 && t->tm_mday == 4) + return true; + if (t->tm_mon == 8 && t->tm_mday >= 1 && t->tm_mday <= 7 && t->tm_wday == 1) + return true; + if (t->tm_mon == 9 && t->tm_mday >= 8 && t->tm_mday <= 14 && t->tm_wday == 1) + return true; + if (t->tm_mon == 10 && t->tm_mday == 11) + return true; + if (t->tm_mon == 10 && t->tm_mday >= 22 && t->tm_mday <= 28 && t->tm_wday == 4) + return true; + if (t->tm_mon == 11 && t->tm_mday == 25) + return true; + } + return false; +} static void calendar_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); @@ -19,7 +53,7 @@ static void calendar_update_proc(Layer *layer, GContext *ctx) { // Calculate which box holds today's date const int i_today = config_n_today(); - graphics_context_set_fill_color(ctx, PBL_IF_COLOR_ELSE(config_today_color(), GColorWhite)); + graphics_context_set_fill_color(ctx, is_colored_calendar_day(i_today) ? GColorSunsetOrange : PBL_IF_COLOR_ELSE(config_today_color(), GColorWhite)); graphics_fill_rect(ctx, GRect((i_today % DAYS_PER_WEEK) * box_w, (i_today / DAYS_PER_WEEK) * box_h, box_w, box_h), 1, GCornersAll); @@ -48,11 +82,21 @@ void calendar_layer_create(Layer* parent_layer, GRect frame) { layer_add_child(parent_layer, s_calendar_layer); } -static int relative_day_of_month(int days_from_today) { +static struct tm *get_tm(int days_from_today) +{ // What is the day of the month relative to today? time_t timestamp = time(NULL); - timestamp += days_from_today * SECONDS_PER_DAY; tm *local_time = localtime(×tamp); + // You get the next day by adding days * seconds, *unless* we're in the hour + // after midnight and daylight savings comes up. Set the hour to an + // arbitrary value that does not cause this to happen. + local_time->tm_hour = 5; + timestamp = mktime(local_time) + days_from_today * SECONDS_PER_DAY; + return localtime(×tamp); +} + +static int relative_day_of_month(int days_from_today) { + tm *local_time = get_tm(days_from_today); return local_time->tm_mday; } @@ -74,7 +118,12 @@ void calendar_layer_refresh() { fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); } else { - text_layer_set_text_color(s_calendar_text_layers[i], GColorWhite); + GColor8 color = GColorWhite; + + if (is_colored_calendar_day(i)) + color = GColorSunsetOrange; + + text_layer_set_text_color(s_calendar_text_layers[i], color); text_layer_set_font(s_calendar_text_layers[i], fonts_get_system_font(FONT_KEY_GOTHIC_18)); } @@ -88,4 +137,4 @@ void calendar_layer_destroy() { text_layer_destroy(s_calendar_text_layers[i]); } layer_destroy(s_calendar_layer); -} \ No newline at end of file +} diff --git a/src/pkjs/clay/config.js b/src/pkjs/clay/config.js index 4393854..caf500a 100644 --- a/src/pkjs/clay/config.js +++ b/src/pkjs/clay/config.js @@ -218,6 +218,24 @@ module.exports = [ } ] }, + { + "type": "toggle", + "label": "Show Sunday in color", + "messageKey": "colorSunday", + "defaultValue": false + }, + { + "type": "toggle", + "label": "Show Saturday in color", + "messageKey": "colorSaturday", + "defaultValue": false + }, + { + "type": "toggle", + "label": "Show US Federal holidays in color", + "messageKey": "colorUSFederal", + "defaultValue": false + }, ] }, { diff --git a/src/pkjs/index.js b/src/pkjs/index.js index eb61775..664c382 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -64,6 +64,9 @@ function sendClaySettings() { "CLAY_SHOW_BT_DISCONNECT": app.settings.btIcons === "disconnected" || app.settings.btIcons === "both", "CLAY_VIBE": app.settings.vibe, "CLAY_SHOW_AM_PM": app.settings.timeShowAmPm, + "CLAY_COLOR_SUNDAY": app.settings.colorSunday, + "CLAY_COLOR_SATURDAY": app.settings.colorSaturday, + "CLAY_COLOR_US_FEDERAL": app.settings.colorUSFederal, } Pebble.sendAppMessage(payload, function() { console.log('Message sent successfully: ' + JSON.stringify(payload)); @@ -177,4 +180,4 @@ function needRefresh() { } // If the most recent fetch is more than 30 minutes old return (Date.now() - roundDownMinutes(new Date(lastFetchSuccess.time), 30) > 1000 * 60 * 30); -} \ No newline at end of file +} From e4bd98941575ee8b59e6258a81baf1d73732adf3 Mon Sep 17 00:00:00 2001 From: Ken Arromdee Date: Sat, 31 Oct 2020 21:54:52 -0400 Subject: [PATCH 02/10] Fixes: -- Remove Clay dependency -- Holidays that fall on weekends get moved to Friday or Monday -- Weekend/holiday coloring not applicable on B&W Pebble --- package.json | 1 - src/c/layers/calendar_layer.c | 83 +++++++++++++++++++++++++---------- src/pkjs/clay/config.js | 38 ++++++++-------- 3 files changed, 78 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 2b4b5cf..bd70122 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ ], "private": true, "dependencies": { - "pebble-clay": "^1.0.4" }, "pebble": { "displayName": "FCW2", diff --git a/src/c/layers/calendar_layer.c b/src/c/layers/calendar_layer.c index 062c3a1..e55f39f 100644 --- a/src/c/layers/calendar_layer.c +++ b/src/c/layers/calendar_layer.c @@ -6,41 +6,79 @@ #define DAYS_PER_WEEK 7 #define FONT_OFFSET 5 +#define HOLIDAY_COLOR GColorSunsetOrange +#define SUNDAY_COLOR GColorSunsetOrange +#define SATURDAY_COLOR GColorPictonBlue + static Layer *s_calendar_layer; static TextLayer *s_calendar_text_layers[NUM_WEEKS * DAYS_PER_WEEK]; static struct tm *get_tm(int days_from_today); -static bool is_colored_calendar_day(int i) +static GColor8 get_colored_calendar_day(int i, GColor8 unchanged) { const int i_today = config_n_today(); tm *t = get_tm(i - i_today); - if ((g_config->color_sunday && t->tm_wday == 0) || - (g_config->color_saturday && t->tm_wday == 6)) - return true; +#ifdef PBL_COLOR if (g_config->color_us_federal) { - if (t->tm_mon == 0 && t->tm_mday == 1) - return true; + // Federal holidays that are on a specific day of the week if (t->tm_mon == 0 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) - return true; + return HOLIDAY_COLOR; if (t->tm_mon == 1 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) - return true; + return HOLIDAY_COLOR; if (t->tm_mon == 4 && t->tm_mday >= 25 && t->tm_mday <= 31 && t->tm_wday == 1) - return true; - if (t->tm_mon == 6 && t->tm_mday == 4) - return true; + return HOLIDAY_COLOR; if (t->tm_mon == 8 && t->tm_mday >= 1 && t->tm_mday <= 7 && t->tm_wday == 1) - return true; + return HOLIDAY_COLOR; if (t->tm_mon == 9 && t->tm_mday >= 8 && t->tm_mday <= 14 && t->tm_wday == 1) - return true; - if (t->tm_mon == 10 && t->tm_mday == 11) - return true; + return HOLIDAY_COLOR; if (t->tm_mon == 10 && t->tm_mday >= 22 && t->tm_mday <= 28 && t->tm_wday == 4) - return true; - if (t->tm_mon == 11 && t->tm_mday == 25) - return true; + return HOLIDAY_COLOR; + + // Federal holidays that are on a specific day of the month, which get + // moved if they fall on a weekend + switch(t->tm_wday) { + // weekend that would otherwise contain the holiday does not + case 0: case 6: + break; + // Friday if it matches (normal day of holiday - 1) + case 5: + if ((t->tm_mon == 11 && t->tm_mday == 31) || // New Years + (t->tm_mon == 6 && t->tm_mday == 3) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 10) || // Veterans' Day + (t->tm_mon == 11 && t->tm_mday == 24)) // Christmas + { + return HOLIDAY_COLOR; + } + break; + // Monday if the monday matches (normal day of holiday + 1) + case 1: + if ((t->tm_mon == 0 && t->tm_mday == 2) || // New Years + (t->tm_mon == 6 && t->tm_mday == 5) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 12) || // Veterans' Day + (t->tm_mon == 11 && t->tm_mday == 26)) // Christmas + { + return HOLIDAY_COLOR; + } + break; + default: + if ((t->tm_mon == 0 && t->tm_mday == 1) || // New Years + (t->tm_mon == 6 && t->tm_mday == 4) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 11) || // Veterans' Day + (t->tm_mon == 11 && t->tm_mday == 25)) // Christmas + { + return HOLIDAY_COLOR; + } + break; + } } - return false; + // Let holidays take precedence over weekends + if (g_config->color_sunday && t->tm_wday == 0) + return SUNDAY_COLOR; + if (g_config->color_saturday && t->tm_wday == 6) + return SATURDAY_COLOR; +#endif // PBL_COLOR + return unchanged; } static void calendar_update_proc(Layer *layer, GContext *ctx) { @@ -53,7 +91,7 @@ static void calendar_update_proc(Layer *layer, GContext *ctx) { // Calculate which box holds today's date const int i_today = config_n_today(); - graphics_context_set_fill_color(ctx, is_colored_calendar_day(i_today) ? GColorSunsetOrange : PBL_IF_COLOR_ELSE(config_today_color(), GColorWhite)); + graphics_context_set_fill_color(ctx, get_colored_calendar_day(i_today, PBL_IF_COLOR_ELSE(config_today_color(), GColorWhite))); graphics_fill_rect(ctx, GRect((i_today % DAYS_PER_WEEK) * box_w, (i_today / DAYS_PER_WEEK) * box_h, box_w, box_h), 1, GCornersAll); @@ -118,10 +156,7 @@ void calendar_layer_refresh() { fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); } else { - GColor8 color = GColorWhite; - - if (is_colored_calendar_day(i)) - color = GColorSunsetOrange; + GColor8 color = get_colored_calendar_day(i, GColorWhite); text_layer_set_text_color(s_calendar_text_layers[i], color); text_layer_set_font(s_calendar_text_layers[i], diff --git a/src/pkjs/clay/config.js b/src/pkjs/clay/config.js index caf500a..7796bfe 100644 --- a/src/pkjs/clay/config.js +++ b/src/pkjs/clay/config.js @@ -110,7 +110,25 @@ module.exports = [ "value": "curr" } ] - } + }, + { + "type": "toggle", + "label": "Show Sunday in color", + "messageKey": "colorSunday", + "defaultValue": false + }, + { + "type": "toggle", + "label": "Show Saturday in color", + "messageKey": "colorSaturday", + "defaultValue": false + }, + { + "type": "toggle", + "label": "Show US Federal holidays in color", + "messageKey": "colorUSFederal", + "defaultValue": false + }, ] }, { @@ -218,24 +236,6 @@ module.exports = [ } ] }, - { - "type": "toggle", - "label": "Show Sunday in color", - "messageKey": "colorSunday", - "defaultValue": false - }, - { - "type": "toggle", - "label": "Show Saturday in color", - "messageKey": "colorSaturday", - "defaultValue": false - }, - { - "type": "toggle", - "label": "Show US Federal holidays in color", - "messageKey": "colorUSFederal", - "defaultValue": false - }, ] }, { From 0fb6f5acc30279b72536764fe101f0174f2d7f2b Mon Sep 17 00:00:00 2001 From: Ken Arromdee Date: Sat, 31 Oct 2020 22:17:20 -0400 Subject: [PATCH 03/10] stupid comment --- src/c/layers/calendar_layer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/c/layers/calendar_layer.c b/src/c/layers/calendar_layer.c index e55f39f..bec4f16 100644 --- a/src/c/layers/calendar_layer.c +++ b/src/c/layers/calendar_layer.c @@ -72,7 +72,8 @@ static GColor8 get_colored_calendar_day(int i, GColor8 unchanged) break; } } - // Let holidays take precedence over weekends + // Since holidays that fall on weekends get pushed, it never matters whether + // we do weekends before or after if (g_config->color_sunday && t->tm_wday == 0) return SUNDAY_COLOR; if (g_config->color_saturday && t->tm_wday == 6) From 5fd16af2185cdcdc279b753f1e9a1f17b629f3af Mon Sep 17 00:00:00 2001 From: mattrossman Date: Sun, 1 Nov 2020 20:52:14 -0500 Subject: [PATCH 04/10] Swap toggles with colorpicker, cleanup --- src/c/appendix/app_message.c | 21 ++--- src/c/appendix/config.h | 6 +- src/c/appendix/persist.c | 6 +- src/c/layers/calendar_layer.c | 148 ++++++++++++++++------------------ src/pkjs/clay/config.js | 24 +++--- 5 files changed, 101 insertions(+), 104 deletions(-) diff --git a/src/c/appendix/app_message.c b/src/c/appendix/app_message.c index fdef4b7..fbf7857 100644 --- a/src/c/appendix/app_message.c +++ b/src/c/appendix/app_message.c @@ -29,9 +29,9 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) Tuple *clay_show_bt_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_BT); Tuple *clay_show_bt_disconnect_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_BT_DISCONNECT); Tuple *clay_show_am_pm_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_SHOW_AM_PM); - Tuple *clay_color_saturday = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SATURDAY); - Tuple *clay_color_sunday = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SUNDAY); - Tuple *clay_color_us_federal = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_US_FEDERAL); + Tuple *clay_color_saturday_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SATURDAY); + Tuple *clay_color_sunday_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SUNDAY); + Tuple *clay_color_us_federal_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_US_FEDERAL); if(temp_trend_tuple && temp_trend_tuple && forecast_start_tuple && num_entries_tuple && city_tuple && sun_events_tuple) { // Weather data received @@ -58,7 +58,8 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) weather_status_layer_refresh(); } if (clay_celsius_tuple && clay_axis_12h_tuple && clay_start_mon_tuple && clay_prev_week_tuple && clay_color_today_tuple - && clay_show_qt_tuple && clay_show_bt_tuple && clay_show_bt_disconnect_tuple && clay_show_am_pm_tuple) { + && clay_show_qt_tuple && clay_show_bt_tuple && clay_show_bt_disconnect_tuple && clay_show_am_pm_tuple + && clay_color_saturday_tuple && clay_color_sunday_tuple && clay_color_us_federal_tuple) { // Clay config data received bool clay_celsius = (bool) (clay_celsius_tuple->value->int16); bool time_lead_zero = (bool) (clay_time_lead_zero_tuple->value->int16); @@ -71,9 +72,9 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) bool show_am_pm = (bool) (clay_show_am_pm_tuple->value->int16); int16_t time_font = clay_time_font_tuple->value->int16; GColor color_today = GColorFromHEX(clay_color_today_tuple->value->int32); - bool color_saturday = (bool) (clay_color_saturday->value->int16); - bool color_sunday = (bool) (clay_color_sunday->value->int16); - bool color_us_federal = (bool) (clay_color_us_federal->value->int16); + GColor color_saturday = GColorFromHEX(clay_color_saturday_tuple->value->int32); + GColor color_sunday = GColorFromHEX(clay_color_sunday_tuple->value->int32); + GColor color_us_federal = GColorFromHEX(clay_color_us_federal_tuple->value->int32); Config config = (Config) { .celsius = clay_celsius, .time_lead_zero = time_lead_zero, @@ -86,9 +87,9 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) .show_bt = show_bt, .show_bt_disconnect = show_bt_disconnect, .show_am_pm = show_am_pm, - .color_saturday = color_saturday, - .color_sunday = color_sunday, - .color_us_federal = color_us_federal, + .color_saturday = color_saturday, + .color_sunday = color_sunday, + .color_us_federal = color_us_federal, }; persist_set_config(config); main_window_refresh(); diff --git a/src/c/appendix/config.h b/src/c/appendix/config.h index efb29ba..617f062 100644 --- a/src/c/appendix/config.h +++ b/src/c/appendix/config.h @@ -15,9 +15,9 @@ typedef struct { bool show_am_pm; int16_t time_font; GColor color_today; - bool color_saturday; - bool color_sunday; - bool color_us_federal; + GColor color_saturday; + GColor color_sunday; + GColor color_us_federal; } Config; Config *g_config; diff --git a/src/c/appendix/persist.c b/src/c/appendix/persist.c index 6b355b9..b5b9abb 100644 --- a/src/c/appendix/persist.c +++ b/src/c/appendix/persist.c @@ -54,9 +54,9 @@ void persist_init() { .show_bt_disconnect = true, .vibe = false, .show_am_pm = false, - .color_saturday = false, - .color_sunday = false, - .color_us_federal = false + .color_saturday = GColorWhite, + .color_sunday = GColorWhite, + .color_us_federal = GColorWhite }; persist_set_config(config); } diff --git a/src/c/layers/calendar_layer.c b/src/c/layers/calendar_layer.c index bec4f16..f1ecbdf 100644 --- a/src/c/layers/calendar_layer.c +++ b/src/c/layers/calendar_layer.c @@ -6,34 +6,41 @@ #define DAYS_PER_WEEK 7 #define FONT_OFFSET 5 -#define HOLIDAY_COLOR GColorSunsetOrange -#define SUNDAY_COLOR GColorSunsetOrange -#define SATURDAY_COLOR GColorPictonBlue - static Layer *s_calendar_layer; static TextLayer *s_calendar_text_layers[NUM_WEEKS * DAYS_PER_WEEK]; -static struct tm *get_tm(int days_from_today); -static GColor8 get_colored_calendar_day(int i, GColor8 unchanged) + +static struct tm *relative_tm(int days_from_today) { - const int i_today = config_n_today(); - tm *t = get_tm(i - i_today); - -#ifdef PBL_COLOR - if (g_config->color_us_federal) { - // Federal holidays that are on a specific day of the week - if (t->tm_mon == 0 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) - return HOLIDAY_COLOR; - if (t->tm_mon == 1 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) - return HOLIDAY_COLOR; - if (t->tm_mon == 4 && t->tm_mday >= 25 && t->tm_mday <= 31 && t->tm_wday == 1) - return HOLIDAY_COLOR; - if (t->tm_mon == 8 && t->tm_mday >= 1 && t->tm_mday <= 7 && t->tm_wday == 1) - return HOLIDAY_COLOR; - if (t->tm_mon == 9 && t->tm_mday >= 8 && t->tm_mday <= 14 && t->tm_wday == 1) - return HOLIDAY_COLOR; - if (t->tm_mon == 10 && t->tm_mday >= 22 && t->tm_mday <= 28 && t->tm_wday == 4) - return HOLIDAY_COLOR; + /* Get a time structure for n days from today (only accurate to the day) + Use this function to avoid edge cases from daylight savings time + */ + time_t timestamp = time(NULL); + tm *local_time = localtime(×tamp); + // You get the next day by adding days * seconds, *unless* we're in the hour + // after midnight and daylight savings comes up. Set the hour to an + // arbitrary value that does not cause this to happen. + local_time->tm_hour = 5; + timestamp = mktime(local_time) + days_from_today * SECONDS_PER_DAY; + return localtime(×tamp); +} + +static int relative_day_of_month(int days_from_today) { + // What is the day of the month n days from today? + tm *local_time = relative_tm(days_from_today); + return local_time->tm_mday; +} + +static bool is_us_federal_holiday(struct tm *t) +{ + // These holidays are on a specific weekday, so no special cases + if ((t->tm_mon == 0 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) || // MLK Day + (t->tm_mon == 1 && t->tm_mday >= 15 && t->tm_mday <= 21 && t->tm_wday == 1) || // Washington's Birthday + (t->tm_mon == 4 && t->tm_mday >= 25 && t->tm_mday <= 31 && t->tm_wday == 1) || // Memorial Day + (t->tm_mon == 8 && t->tm_mday >= 1 && t->tm_mday <= 7 && t->tm_wday == 1) || // Labor Day + (t->tm_mon == 9 && t->tm_mday >= 8 && t->tm_mday <= 14 && t->tm_wday == 1) || // Columbus Day + (t->tm_mon == 10 && t->tm_mday >= 22 && t->tm_mday <= 28 && t->tm_wday == 4)) // Thanksgiving + return true; // Federal holidays that are on a specific day of the month, which get // moved if they fall on a weekend @@ -43,43 +50,41 @@ static GColor8 get_colored_calendar_day(int i, GColor8 unchanged) break; // Friday if it matches (normal day of holiday - 1) case 5: - if ((t->tm_mon == 11 && t->tm_mday == 31) || // New Years - (t->tm_mon == 6 && t->tm_mday == 3) || // Independence Day - (t->tm_mon == 10 && t->tm_mday == 10) || // Veterans' Day - (t->tm_mon == 11 && t->tm_mday == 24)) // Christmas - { - return HOLIDAY_COLOR; - } - break; + if ((t->tm_mon == 11 && t->tm_mday == 31) || // New Years + (t->tm_mon == 6 && t->tm_mday == 3) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 10) || // Veterans Day + (t->tm_mon == 11 && t->tm_mday == 24)) // Christmas + { + return true; + } + break; // Monday if the monday matches (normal day of holiday + 1) case 1: - if ((t->tm_mon == 0 && t->tm_mday == 2) || // New Years - (t->tm_mon == 6 && t->tm_mday == 5) || // Independence Day - (t->tm_mon == 10 && t->tm_mday == 12) || // Veterans' Day - (t->tm_mon == 11 && t->tm_mday == 26)) // Christmas - { - return HOLIDAY_COLOR; - } - break; + if ((t->tm_mon == 0 && t->tm_mday == 2) || // New Years + (t->tm_mon == 6 && t->tm_mday == 5) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 12) || // Veterans Day + (t->tm_mon == 11 && t->tm_mday == 26)) // Christmas + return true; + break; default: - if ((t->tm_mon == 0 && t->tm_mday == 1) || // New Years - (t->tm_mon == 6 && t->tm_mday == 4) || // Independence Day - (t->tm_mon == 10 && t->tm_mday == 11) || // Veterans' Day - (t->tm_mon == 11 && t->tm_mday == 25)) // Christmas - { - return HOLIDAY_COLOR; - } - break; + if ((t->tm_mon == 0 && t->tm_mday == 1) || // New Years + (t->tm_mon == 6 && t->tm_mday == 4) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 11) || // Veterans Day + (t->tm_mon == 11 && t->tm_mday == 25)) // Christmas + return true; + break; } - } - // Since holidays that fall on weekends get pushed, it never matters whether - // we do weekends before or after - if (g_config->color_sunday && t->tm_wday == 0) - return SUNDAY_COLOR; - if (g_config->color_saturday && t->tm_wday == 6) - return SATURDAY_COLOR; -#endif // PBL_COLOR - return unchanged; + return false; +} + +static GColor date_color(struct tm *t) { + if (is_us_federal_holiday(t)) + return g_config->color_us_federal; + if (t->tm_wday == 0) + return g_config->color_sunday; + if (t->tm_wday == 6) + return g_config->color_saturday; + return GColorWhite; } static void calendar_update_proc(Layer *layer, GContext *ctx) { @@ -91,8 +96,10 @@ static void calendar_update_proc(Layer *layer, GContext *ctx) { // Calculate which box holds today's date const int i_today = config_n_today(); + struct tm *t = relative_tm(0); - graphics_context_set_fill_color(ctx, get_colored_calendar_day(i_today, PBL_IF_COLOR_ELSE(config_today_color(), GColorWhite))); + GColor background_color = PBL_IF_COLOR_ELSE(date_color(t), GColorWhite); + graphics_context_set_fill_color(ctx, background_color); graphics_fill_rect(ctx, GRect((i_today % DAYS_PER_WEEK) * box_w, (i_today / DAYS_PER_WEEK) * box_h, box_w, box_h), 1, GCornersAll); @@ -121,23 +128,6 @@ void calendar_layer_create(Layer* parent_layer, GRect frame) { layer_add_child(parent_layer, s_calendar_layer); } -static struct tm *get_tm(int days_from_today) -{ - // What is the day of the month relative to today? - time_t timestamp = time(NULL); - tm *local_time = localtime(×tamp); - // You get the next day by adding days * seconds, *unless* we're in the hour - // after midnight and daylight savings comes up. Set the hour to an - // arbitrary value that does not cause this to happen. - local_time->tm_hour = 5; - timestamp = mktime(local_time) + days_from_today * SECONDS_PER_DAY; - return localtime(×tamp); -} - -static int relative_day_of_month(int days_from_today) { - tm *local_time = get_tm(days_from_today); - return local_time->tm_mday; -} void calendar_layer_refresh() { static char s_calendar_box_buffers[NUM_WEEKS * DAYS_PER_WEEK][4]; @@ -150,6 +140,7 @@ void calendar_layer_refresh() { // Fill each box with an appropriate relative day number for (int i = 0; i < NUM_WEEKS * DAYS_PER_WEEK; ++i) { char *buffer = s_calendar_box_buffers[i]; + struct tm *t = relative_tm(i - i_today); if (i == i_today) { text_layer_set_text_color(s_calendar_text_layers[i], PBL_IF_COLOR_ELSE(gcolor_legible_over(config_today_color()), GColorBlack)); @@ -157,13 +148,12 @@ void calendar_layer_refresh() { fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); } else { - GColor8 color = get_colored_calendar_day(i, GColorWhite); - - text_layer_set_text_color(s_calendar_text_layers[i], color); + GColor text_color = PBL_IF_COLOR_ELSE(date_color(t), GColorWhite); + text_layer_set_text_color(s_calendar_text_layers[i], text_color); text_layer_set_font(s_calendar_text_layers[i], fonts_get_system_font(FONT_KEY_GOTHIC_18)); } - snprintf(buffer, 4, "%d", relative_day_of_month(i - i_today)); + snprintf(buffer, 4, "%d", t->tm_mday); text_layer_set_text(s_calendar_text_layers[i], buffer); } } diff --git a/src/pkjs/clay/config.js b/src/pkjs/clay/config.js index 7796bfe..18a24ba 100644 --- a/src/pkjs/clay/config.js +++ b/src/pkjs/clay/config.js @@ -112,22 +112,28 @@ module.exports = [ ] }, { - "type": "toggle", - "label": "Show Sunday in color", + "type": "color", + "label": "Sunday color", "messageKey": "colorSunday", - "defaultValue": false + "defaultValue": "#FF5555", + "sunlight": false, + "capabilities": ["COLOR"] }, { - "type": "toggle", - "label": "Show Saturday in color", + "type": "color", + "label": "Saturday color", "messageKey": "colorSaturday", - "defaultValue": false + "defaultValue": "#00AAFF", + "sunlight": false, + "capabilities": ["COLOR"] }, { - "type": "toggle", - "label": "Show US Federal holidays in color", + "type": "color", + "label": "US Federal holidays color", "messageKey": "colorUSFederal", - "defaultValue": false + "defaultValue": "#FF5555", + "sunlight": false, + "capabilities": ["COLOR"] }, ] }, From c00dbba0b05c97255f645a5b846f42a2b5087f53 Mon Sep 17 00:00:00 2001 From: mattrossman Date: Sun, 1 Nov 2020 21:08:42 -0500 Subject: [PATCH 05/10] Cleanup switch statement, ensure legible text --- src/c/layers/calendar_layer.c | 65 ++++++++++++++++------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/src/c/layers/calendar_layer.c b/src/c/layers/calendar_layer.c index f1ecbdf..377e167 100644 --- a/src/c/layers/calendar_layer.c +++ b/src/c/layers/calendar_layer.c @@ -17,10 +17,8 @@ static struct tm *relative_tm(int days_from_today) */ time_t timestamp = time(NULL); tm *local_time = localtime(×tamp); - // You get the next day by adding days * seconds, *unless* we're in the hour - // after midnight and daylight savings comes up. Set the hour to an - // arbitrary value that does not cause this to happen. - local_time->tm_hour = 5; + // Set arbitrary hour so there's no daylight savings rounding error: + local_time->tm_hour = 5; timestamp = mktime(local_time) + days_from_today * SECONDS_PER_DAY; return localtime(×tamp); } @@ -42,42 +40,36 @@ static bool is_us_federal_holiday(struct tm *t) (t->tm_mon == 10 && t->tm_mday >= 22 && t->tm_mday <= 28 && t->tm_wday == 4)) // Thanksgiving return true; - // Federal holidays that are on a specific day of the month, which get + // These remaining holidays are on a specific day of the month, which get // moved if they fall on a weekend - switch(t->tm_wday) { - // weekend that would otherwise contain the holiday does not - case 0: case 6: - break; - // Friday if it matches (normal day of holiday - 1) - case 5: - if ((t->tm_mon == 11 && t->tm_mday == 31) || // New Years - (t->tm_mon == 6 && t->tm_mday == 3) || // Independence Day - (t->tm_mon == 10 && t->tm_mday == 10) || // Veterans Day - (t->tm_mon == 11 && t->tm_mday == 24)) // Christmas - { - return true; - } - break; - // Monday if the monday matches (normal day of holiday + 1) - case 1: - if ((t->tm_mon == 0 && t->tm_mday == 2) || // New Years - (t->tm_mon == 6 && t->tm_mday == 5) || // Independence Day - (t->tm_mon == 10 && t->tm_mday == 12) || // Veterans Day - (t->tm_mon == 11 && t->tm_mday == 26)) // Christmas - return true; - break; - default: - if ((t->tm_mon == 0 && t->tm_mday == 1) || // New Years - (t->tm_mon == 6 && t->tm_mday == 4) || // Independence Day - (t->tm_mon == 10 && t->tm_mday == 11) || // Veterans Day - (t->tm_mon == 11 && t->tm_mday == 25)) // Christmas - return true; - break; - } + + // Friday special cases + if (t->tm_wday == 5 && ( + (t->tm_mon == 11 && t->tm_mday == 31) || // New Years + (t->tm_mon == 6 && t->tm_mday == 3) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 10) || // Veterans Day + (t->tm_mon == 11 && t->tm_mday == 24))) // Christmas + return true; + // Monday special cases + if (t->tm_wday == 1 && ( + (t->tm_mon == 0 && t->tm_mday == 2) || // New Years + (t->tm_mon == 6 && t->tm_mday == 5) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 12) || // Veterans Day + (t->tm_mon == 11 && t->tm_mday == 26))) // Christmas + return true; + // Non special cases + if ((t->tm_mon == 0 && t->tm_mday == 1) || // New Years + (t->tm_mon == 6 && t->tm_mday == 4) || // Independence Day + (t->tm_mon == 10 && t->tm_mday == 11) || // Veterans Day + (t->tm_mon == 11 && t->tm_mday == 25)) // Christmas + return true; + + // Default to no holiday return false; } static GColor date_color(struct tm *t) { + // Get color for a date, considering weekends and holidays if (is_us_federal_holiday(t)) return g_config->color_us_federal; if (t->tm_wday == 0) @@ -142,8 +134,9 @@ void calendar_layer_refresh() { char *buffer = s_calendar_box_buffers[i]; struct tm *t = relative_tm(i - i_today); if (i == i_today) { + GColor background_color = PBL_IF_COLOR_ELSE(date_color(t), GColorWhite); text_layer_set_text_color(s_calendar_text_layers[i], - PBL_IF_COLOR_ELSE(gcolor_legible_over(config_today_color()), GColorBlack)); + gcolor_legible_over(background_color)); text_layer_set_font(s_calendar_text_layers[i], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); } From b83092cbd5e7f1daec369ef6a0bff979b8288abc Mon Sep 17 00:00:00 2001 From: mattrossman Date: Sun, 1 Nov 2020 21:10:43 -0500 Subject: [PATCH 06/10] Tweak clay color defaults and ordering --- src/pkjs/clay/config.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pkjs/clay/config.js b/src/pkjs/clay/config.js index 18a24ba..65baed7 100644 --- a/src/pkjs/clay/config.js +++ b/src/pkjs/clay/config.js @@ -71,14 +71,6 @@ module.exports = [ "type": "heading", "defaultValue": "Calendar", }, - { - "type": "color", - "label": "Today highlight", - "messageKey": "colorToday", - "defaultValue": "#FFFFFF", - "sunlight": false, - "capabilities": ["COLOR"] - }, { "type": "select", "label": "Start week on", @@ -111,11 +103,19 @@ module.exports = [ } ] }, + { + "type": "color", + "label": "Today highlight", + "messageKey": "colorToday", + "defaultValue": "#FFFFFF", + "sunlight": false, + "capabilities": ["COLOR"] + }, { "type": "color", "label": "Sunday color", "messageKey": "colorSunday", - "defaultValue": "#FF5555", + "defaultValue": "#FFFFFF", "sunlight": false, "capabilities": ["COLOR"] }, @@ -123,15 +123,15 @@ module.exports = [ "type": "color", "label": "Saturday color", "messageKey": "colorSaturday", - "defaultValue": "#00AAFF", + "defaultValue": "#FFFFFF", "sunlight": false, "capabilities": ["COLOR"] }, { "type": "color", - "label": "US Federal holidays color", + "label": "US federal holidays color", "messageKey": "colorUSFederal", - "defaultValue": "#FF5555", + "defaultValue": "#FFFFFF", "sunlight": false, "capabilities": ["COLOR"] }, From 363c6d384e809609988f7981491a27c82790642f Mon Sep 17 00:00:00 2001 From: mattrossman Date: Sun, 1 Nov 2020 21:22:30 -0500 Subject: [PATCH 07/10] Remove unused config function --- src/c/appendix/config.c | 5 ----- src/c/appendix/config.h | 2 -- 2 files changed, 7 deletions(-) diff --git a/src/c/appendix/config.c b/src/c/appendix/config.c index 5fc5331..4267ecc 100644 --- a/src/c/appendix/config.c +++ b/src/c/appendix/config.c @@ -63,11 +63,6 @@ int config_n_today() { return wday; } -GColor config_today_color() { - GColor color = g_config->color_today; - return color; -} - GFont config_time_font() { const char *font_keys[] = { FONT_KEY_ROBOTO_BOLD_SUBSET_49, diff --git a/src/c/appendix/config.h b/src/c/appendix/config.h index 617f062..be870ce 100644 --- a/src/c/appendix/config.h +++ b/src/c/appendix/config.h @@ -36,6 +36,4 @@ int config_axis_hour(int hour); int config_n_today(); -GColor config_today_color(); - GFont config_time_font(); From 72a532b8312204d824c18dd56490721b61864188 Mon Sep 17 00:00:00 2001 From: mattrossman Date: Sun, 1 Nov 2020 21:33:23 -0500 Subject: [PATCH 08/10] Fix bad payload on bw models, add debug warning --- src/c/appendix/app_message.c | 5 ++++- src/pkjs/index.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/c/appendix/app_message.c b/src/c/appendix/app_message.c index fbf7857..284b3ab 100644 --- a/src/c/appendix/app_message.c +++ b/src/c/appendix/app_message.c @@ -57,7 +57,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) forecast_layer_refresh(); weather_status_layer_refresh(); } - if (clay_celsius_tuple && clay_axis_12h_tuple && clay_start_mon_tuple && clay_prev_week_tuple && clay_color_today_tuple + else if (clay_celsius_tuple && clay_axis_12h_tuple && clay_start_mon_tuple && clay_prev_week_tuple && clay_color_today_tuple && clay_show_qt_tuple && clay_show_bt_tuple && clay_show_bt_disconnect_tuple && clay_show_am_pm_tuple && clay_color_saturday_tuple && clay_color_sunday_tuple && clay_color_us_federal_tuple) { // Clay config data received @@ -94,6 +94,9 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) persist_set_config(config); main_window_refresh(); } + else { + APP_LOG(APP_LOG_LEVEL_WARNING, "Bad payload received in app_message.c"); + } } static void inbox_dropped_callback(AppMessageResult reason, void *context) { diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 664c382..4c94231 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -64,9 +64,9 @@ function sendClaySettings() { "CLAY_SHOW_BT_DISCONNECT": app.settings.btIcons === "disconnected" || app.settings.btIcons === "both", "CLAY_VIBE": app.settings.vibe, "CLAY_SHOW_AM_PM": app.settings.timeShowAmPm, - "CLAY_COLOR_SUNDAY": app.settings.colorSunday, - "CLAY_COLOR_SATURDAY": app.settings.colorSaturday, - "CLAY_COLOR_US_FEDERAL": app.settings.colorUSFederal, + "CLAY_COLOR_SUNDAY": app.settings.hasOwnProperty('colorSunday') ? app.settings.colorSunday : 16777215, + "CLAY_COLOR_SATURDAY": app.settings.hasOwnProperty('colorSaturday') ? app.settings.colorSaturday : 16777215, + "CLAY_COLOR_US_FEDERAL": app.settings.hasOwnProperty('colorUSFederal') ? app.settings.colorUSFederal : 16777215, } Pebble.sendAppMessage(payload, function() { console.log('Message sent successfully: ' + JSON.stringify(payload)); From 080792c4d246bb024802f0a0ab5a5def161a0254 Mon Sep 17 00:00:00 2001 From: mattrossman Date: Sun, 1 Nov 2020 21:40:58 -0500 Subject: [PATCH 09/10] Enable custom time color Related: #42 --- package.json | 3 ++- src/c/appendix/app_message.c | 5 ++++- src/c/appendix/config.h | 1 + src/c/appendix/persist.c | 3 ++- src/c/layers/time_layer.c | 2 +- src/pkjs/clay/config.js | 10 +++++++++- src/pkjs/index.js | 1 + 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bd70122..397f619 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,8 @@ "CLAY_SHOW_AM_PM", "CLAY_COLOR_SATURDAY", "CLAY_COLOR_SUNDAY", - "CLAY_COLOR_US_FEDERAL" + "CLAY_COLOR_US_FEDERAL", + "CLAY_COLOR_TIME" ] } } diff --git a/src/c/appendix/app_message.c b/src/c/appendix/app_message.c index 284b3ab..b4bbdbb 100644 --- a/src/c/appendix/app_message.c +++ b/src/c/appendix/app_message.c @@ -32,6 +32,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) Tuple *clay_color_saturday_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SATURDAY); Tuple *clay_color_sunday_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_SUNDAY); Tuple *clay_color_us_federal_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_US_FEDERAL); + Tuple *clay_color_time_tuple = dict_find(iterator, MESSAGE_KEY_CLAY_COLOR_TIME); if(temp_trend_tuple && temp_trend_tuple && forecast_start_tuple && num_entries_tuple && city_tuple && sun_events_tuple) { // Weather data received @@ -59,7 +60,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) } else if (clay_celsius_tuple && clay_axis_12h_tuple && clay_start_mon_tuple && clay_prev_week_tuple && clay_color_today_tuple && clay_show_qt_tuple && clay_show_bt_tuple && clay_show_bt_disconnect_tuple && clay_show_am_pm_tuple - && clay_color_saturday_tuple && clay_color_sunday_tuple && clay_color_us_federal_tuple) { + && clay_color_saturday_tuple && clay_color_sunday_tuple && clay_color_us_federal_tuple && clay_color_time_tuple) { // Clay config data received bool clay_celsius = (bool) (clay_celsius_tuple->value->int16); bool time_lead_zero = (bool) (clay_time_lead_zero_tuple->value->int16); @@ -75,6 +76,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) GColor color_saturday = GColorFromHEX(clay_color_saturday_tuple->value->int32); GColor color_sunday = GColorFromHEX(clay_color_sunday_tuple->value->int32); GColor color_us_federal = GColorFromHEX(clay_color_us_federal_tuple->value->int32); + GColor color_time = GColorFromHEX(clay_color_time_tuple->value->int32); Config config = (Config) { .celsius = clay_celsius, .time_lead_zero = time_lead_zero, @@ -90,6 +92,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) .color_saturday = color_saturday, .color_sunday = color_sunday, .color_us_federal = color_us_federal, + .color_time = color_time }; persist_set_config(config); main_window_refresh(); diff --git a/src/c/appendix/config.h b/src/c/appendix/config.h index be870ce..3e6f636 100644 --- a/src/c/appendix/config.h +++ b/src/c/appendix/config.h @@ -18,6 +18,7 @@ typedef struct { GColor color_saturday; GColor color_sunday; GColor color_us_federal; + GColor color_time; } Config; Config *g_config; diff --git a/src/c/appendix/persist.c b/src/c/appendix/persist.c index b5b9abb..aceca71 100644 --- a/src/c/appendix/persist.c +++ b/src/c/appendix/persist.c @@ -56,7 +56,8 @@ void persist_init() { .show_am_pm = false, .color_saturday = GColorWhite, .color_sunday = GColorWhite, - .color_us_federal = GColorWhite + .color_us_federal = GColorWhite, + .color_time = GColorWhite }; persist_set_config(config); } diff --git a/src/c/layers/time_layer.c b/src/c/layers/time_layer.c index 56cee15..8de376d 100644 --- a/src/c/layers/time_layer.c +++ b/src/c/layers/time_layer.c @@ -19,7 +19,6 @@ void time_layer_create(Layer* parent_layer, GRect frame) { // Main time formatting text_layer_set_background_color(s_time_layer, GColorClear); - text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_text(s_time_layer, "00:00"); text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft); @@ -79,6 +78,7 @@ void time_layer_tick() { void time_layer_refresh() { text_layer_set_font(s_time_layer, config_time_font()); + text_layer_set_text_color(s_time_layer, g_config->color_time); time_layer_tick(); // Update main time text and layer positions } diff --git a/src/pkjs/clay/config.js b/src/pkjs/clay/config.js index 65baed7..fad7392 100644 --- a/src/pkjs/clay/config.js +++ b/src/pkjs/clay/config.js @@ -61,7 +61,15 @@ module.exports = [ "value": "bitham" }, ] - } + }, + { + "type": "color", + "label": "Main time color", + "messageKey": "colorTime", + "defaultValue": "#FFFFFF", + "sunlight": false, + "capabilities": ["COLOR"] + }, ] }, { diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 4c94231..cd7fcbf 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -67,6 +67,7 @@ function sendClaySettings() { "CLAY_COLOR_SUNDAY": app.settings.hasOwnProperty('colorSunday') ? app.settings.colorSunday : 16777215, "CLAY_COLOR_SATURDAY": app.settings.hasOwnProperty('colorSaturday') ? app.settings.colorSaturday : 16777215, "CLAY_COLOR_US_FEDERAL": app.settings.hasOwnProperty('colorUSFederal') ? app.settings.colorUSFederal : 16777215, + "CLAY_COLOR_TIME": app.settings.hasOwnProperty('colorTime') ? app.settings.colorTime : 16777215, } Pebble.sendAppMessage(payload, function() { console.log('Message sent successfully: ' + JSON.stringify(payload)); From c1d1f35231f5bb1f9464d01518720dca67663fa9 Mon Sep 17 00:00:00 2001 From: mattrossman Date: Sun, 1 Nov 2020 21:42:09 -0500 Subject: [PATCH 10/10] Bump version to 1.15.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 397f619..a6375d1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ForecasWatch 2", "author": "Matt Rossman", - "version": "1.14.0", + "version": "1.15.0", "keywords": [ "pebble-app" ],