diff --git a/package.json b/package.json index 15846de..ff8174f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ForecasWatch 2", "author": "Matt Rossman", - "version": "1.10.0", + "version": "1.11.0", "keywords": ["pebble-app"], "private": true, "dependencies": {}, diff --git a/src/c/appendix/config.c b/src/c/appendix/config.c index 55bd680..423520c 100644 --- a/src/c/appendix/config.c +++ b/src/c/appendix/config.c @@ -2,67 +2,63 @@ #include "persist.h" #include "math.h" +// NOTE: g_config is a global config variable + +void config_load() { + g_config = (Config*) malloc(sizeof(Config)); + persist_get_config(g_config); +} + +void config_unload() { + free(g_config); +} + int config_localize_temp(int temp_f) { // Convert temperatures as desired - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); int result; - if (config->celsius) + if (g_config->celsius) result = f_to_c(temp_f); else result = temp_f; - free(config); return result; } int config_format_time(char *s, size_t maxsize, const struct tm * tm_p) { - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); int res = strftime(s, maxsize, clock_is_24h_style() ? "%H:%M" : "%I:%M", tm_p); - if (!config->time_lead_zero) { + if (!g_config->time_lead_zero) { // Remove leading zero if configured as such if (s[0] == '0') memmove(s, s+1, strlen(s)); } - free(config); return res; } int config_axis_hour(int hour) { - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); - if (config->axis_12h) { + if (g_config->axis_12h) { hour = hour % 12; hour = hour == 0 ? 12 : hour; } else hour = hour % 24; - free(config); return hour; } int config_n_today() { // Returns the index of the calendar box that holds today's date - - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); + time_t today = time(NULL); struct tm *tm_today = localtime(&today); int wday = tm_today->tm_wday; // Offset if user wants to start the week on monday - wday = config->start_mon ? (wday + 6) % 7 : wday; + wday = g_config->start_mon ? (wday + 6) % 7 : wday; // Offset if user wants to show the previous week first - if (config->prev_week) + if (g_config->prev_week) wday += 7; - free(config); return wday; } GColor config_today_color() { - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); - GColor color = config->color_today; - free(config); + GColor color = g_config->color_today; return color; } @@ -72,41 +68,6 @@ GFont config_time_font() { FONT_KEY_LECO_42_NUMBERS, FONT_KEY_BITHAM_42_MEDIUM_NUMBERS }; - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); - int16_t font_index = config->time_font; - free(config); + int16_t font_index = g_config->time_font; return fonts_get_system_font(font_keys[font_index]); -} - -bool config_show_qt() { - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); - bool show_qt = config->show_qt; - free(config); - return show_qt; -} - -bool config_show_bt() { - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); - bool show_bt = config->show_bt; - free(config); - return show_bt; -} - -bool config_show_bt_disconnect() { - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); - bool show_bt_disconnect = config->show_bt_disconnect; - free(config); - return show_bt_disconnect; -} - -bool config_vibe() { - Config *config = (Config*) malloc(sizeof(Config)); - persist_get_config(config); - bool vibe = config->vibe; - free(config); - return vibe; } \ No newline at end of file diff --git a/src/c/appendix/config.h b/src/c/appendix/config.h index 571740a..97d27b1 100644 --- a/src/c/appendix/config.h +++ b/src/c/appendix/config.h @@ -16,6 +16,12 @@ typedef struct { GColor color_today; } Config; +Config *g_config; + +void config_load(); + +void config_unload(); + int config_localize_temp(int temp_f); int config_format_time(char *s, size_t maxsize, const struct tm * tm_p); @@ -26,12 +32,4 @@ int config_n_today(); GColor config_today_color(); -GFont config_time_font(); - -bool config_show_qt(); - -bool config_show_bt(); - -bool config_show_bt_disconnect(); - -bool config_vibe(); \ No newline at end of file +GFont config_time_font(); \ No newline at end of file diff --git a/src/c/appendix/persist.c b/src/c/appendix/persist.c index 76b4c06..2ee7246 100644 --- a/src/c/appendix/persist.c +++ b/src/c/appendix/persist.c @@ -4,7 +4,7 @@ enum key { TEMP_LO, TEMP_HI, TEMP_TREND, PRECIP_TREND, FORECAST_START, CITY, SUN_EVENT_START_TYPE, SUN_EVENT_TIMES, NUM_ENTRIES, CURRENT_TEMP, BATTERY_LEVEL, CONFIG -}; +}; // Deprecated: BATTERY_LEVEL void persist_init() { if (!persist_exists(TEMP_LO)) { @@ -33,10 +33,6 @@ void persist_init() { if (!persist_exists(CITY)) { persist_write_string(CITY, "Koji"); } - if (!persist_exists(BATTERY_LEVEL)) { - BatteryChargeState charge = battery_state_service_peek(); - persist_write_int(BATTERY_LEVEL, charge.charge_percent); - } if (!persist_exists(SUN_EVENT_START_TYPE)) { persist_write_int(SUN_EVENT_START_TYPE, 0); } @@ -102,10 +98,6 @@ int persist_get_sun_event_times(time_t *buffer, const size_t buffer_size) { return persist_read_data(SUN_EVENT_TIMES, (void*) buffer, buffer_size * sizeof(time_t)); } -int persist_get_battery_level() { - return persist_read_int(BATTERY_LEVEL); -} - int persist_get_config(Config *config) { return persist_read_data(CONFIG, config, sizeof(Config)); } @@ -150,10 +142,7 @@ void persist_set_sun_event_times(time_t *data, const size_t size) { persist_write_data(SUN_EVENT_TIMES, (void*) data, size * sizeof(time_t)); } -void persist_set_battery_level(int val) { - persist_write_int(BATTERY_LEVEL, val); -} - void persist_set_config(Config config) { persist_write_data(CONFIG, &config, sizeof(Config)); + config_load(); // Refresh global config variable } \ No newline at end of file diff --git a/src/c/appendix/persist.h b/src/c/appendix/persist.h index 0f4be46..de4dfa0 100644 --- a/src/c/appendix/persist.h +++ b/src/c/appendix/persist.h @@ -26,8 +26,6 @@ int persist_get_sun_event_start_type(); int persist_get_sun_event_times(time_t *buffer, const size_t buffer_size); -int persist_get_battery_level(); - int persist_get_config(Config *config); void persist_set_temp_lo(int val); @@ -50,6 +48,4 @@ void persist_set_sun_event_start_type(int val); void persist_set_sun_event_times(time_t *data, const size_t size); -void persist_set_battery_level(int val); - void persist_set_config(Config config); \ No newline at end of file diff --git a/src/c/layers/battery_layer.c b/src/c/layers/battery_layer.c index e60d630..06f7a22 100644 --- a/src/c/layers/battery_layer.c +++ b/src/c/layers/battery_layer.c @@ -10,7 +10,6 @@ static Layer *s_battery_layer; static void battery_state_handler(BatteryChargeState charge) { - persist_set_battery_level(charge.charge_percent); battery_layer_refresh(); } @@ -28,7 +27,8 @@ static void battery_update_proc(Layer *layer, GContext *ctx) { int w = bounds.size.w; int h = bounds.size.h; int battery_w = w - BATTERY_NUB_W; - int battery_level = persist_get_battery_level(); + BatteryChargeState battery_state = battery_state_service_peek(); + int battery_level = battery_state.charge_percent; // Fill the battery level GRect color_bounds = GRect( @@ -63,4 +63,4 @@ void battery_layer_refresh() { void battery_layer_destroy() { battery_state_service_unsubscribe(); layer_destroy(s_battery_layer); -} \ No newline at end of file +} diff --git a/src/c/layers/calendar_layer.c b/src/c/layers/calendar_layer.c index 581927b..f51d75c 100644 --- a/src/c/layers/calendar_layer.c +++ b/src/c/layers/calendar_layer.c @@ -26,7 +26,6 @@ static void calendar_update_proc(Layer *layer, GContext *ctx) { } void calendar_layer_create(Layer* parent_layer, GRect frame) { - APP_LOG(APP_LOG_LEVEL_INFO, "Creating calendar layer..."); s_calendar_layer = layer_create(frame); GRect bounds = layer_get_bounds(s_calendar_layer); int w = bounds.size.w; @@ -47,7 +46,6 @@ void calendar_layer_create(Layer* parent_layer, GRect frame) { layer_set_update_proc(s_calendar_layer, calendar_update_proc); calendar_layer_refresh(); layer_add_child(parent_layer, s_calendar_layer); - // APP_LOG(APP_LOG_LEVEL_DEBUG, "The DOM 0 days from today is: %d", relative_day_of_month(0)); } static int relative_day_of_month(int days_from_today) { diff --git a/src/c/layers/calendar_status_layer.c b/src/c/layers/calendar_status_layer.c index 351a5b2..cccb9f0 100644 --- a/src/c/layers/calendar_status_layer.c +++ b/src/c/layers/calendar_status_layer.c @@ -89,20 +89,20 @@ void calendar_status_layer_create(Layer* parent_layer, GRect frame) { } void bluetooth_icons_refresh(bool connected) { - bool show_bt = connected && config_show_bt(); - bool show_bt_disconnect = !connected && config_show_bt_disconnect(); + bool show_bt = connected && g_config->show_bt; + bool show_bt_disconnect = !connected && g_config->show_bt_disconnect; layer_set_hidden(bitmap_layer_get_layer(s_bt_bitmap_layer), !show_bt); layer_set_hidden(bitmap_layer_get_layer(s_bt_disconnect_bitmap_layer), !show_bt_disconnect); } void bluetooth_callback(bool connected) { bluetooth_icons_refresh(connected); - if (!connected && config_vibe()) + if (!connected && g_config->vibe) vibes_double_pulse(); } bool show_qt_icon() { - return config_show_qt() && quiet_time_is_active(); + return g_config->show_qt && quiet_time_is_active(); } void status_icons_refresh() { diff --git a/src/c/watchface.c b/src/c/watchface.c index 8106b88..86d7fa5 100644 --- a/src/c/watchface.c +++ b/src/c/watchface.c @@ -2,15 +2,18 @@ #include "windows/main_window.h" #include "appendix/app_message.h" #include "appendix/persist.h" +#include "appendix/config.h" static void init() { app_message_init(); persist_init(); + config_load(); main_window_create(); } static void deinit() { + config_unload(); main_window_destroy(); } diff --git a/src/pkjs/clay/config.js b/src/pkjs/clay/config.js index 2d7c448..06d08b1 100644 --- a/src/pkjs/clay/config.js +++ b/src/pkjs/clay/config.js @@ -163,7 +163,10 @@ module.exports = [ "type": "input", "label": "Location override", "messageKey": "location", - "description": "Leave this blank to use GPS" + "description": "Example: \"Manhattan\" or \"123 Oak St Plainsville KY\".
Click here to test out your location query.
To use GPS, leave this blank and ensure GPS is enabled on your device.", + "attributes": { + "placeholder": "Using GPS", + } } ] }, @@ -220,4 +223,4 @@ module.exports = [ "type": "text", "defaultValue": "v" + meta.version } -] \ No newline at end of file +]