From 8cdeb849eb9209935eb09e1b40770d178eaec562 Mon Sep 17 00:00:00 2001 From: Tom Francis Date: Thu, 21 Dec 2017 08:44:43 -0500 Subject: [PATCH 1/5] Fixed 12-hour clock For a 12-hour clock, the hour should show as a single digit for hours 1 - 9, not as two digits. --- package.json | 2 +- src/c/main.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6b1d694..647f576 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "resources": { "media": [ { - "characterRegex": "[0-9\\.]", + "characterRegex": "[0-9 ]", "file": "fonts/LCARSGTJ3_58.ttf", "name": "LCARS_58", "targetPlatforms": [ diff --git a/src/c/main.c b/src/c/main.c index ff11ba5..c7ed769 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -678,7 +678,7 @@ static void update_time() { // Write the current hours and minutes into a buffer static char s_buffer[8]; strftime(s_buffer, sizeof(s_buffer), clock_is_24h_style() ? - "%H%M" : "%I%M", tick_time); + "%H%M" : "%l%M", tick_time); Current_Min=tick_time->tm_min; Current_Hour=tick_time->tm_hour; // Display this time on the TextLayer @@ -1238,4 +1238,4 @@ int main() { init(); app_event_loop(); deinit(); -} \ No newline at end of file +} From 8fbdf4c488eb4165625e85305c18afc8c6d2bc7a Mon Sep 17 00:00:00 2001 From: Tom Francis Date: Thu, 21 Dec 2017 08:53:11 -0500 Subject: [PATCH 2/5] Added ability to show quiet time Added indicator if quiet time is enabled. --- src/c/main.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/c/main.c b/src/c/main.c index c7ed769..6f223f7 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -5,7 +5,7 @@ static Window *s_main_window; static GFont s_time_font, s_date_font, s_weather_icon_font; -static TextLayer *s_date_layer, *s_stardate_layer, *s_batterypercent_layer, *s_lifesupport_text_layer, *s_temperature_layer, *s_city_layer, *icon_weather_layer, *s_time_layer, *s_weekname_layer, *s_weeknum_layer, *s_weatherdescript_layer; +static TextLayer *s_date_layer, *s_stardate_layer, *s_batterypercent_layer, *s_lifesupport_text_layer, *s_temperature_layer, *s_city_layer, *icon_weather_layer, *s_time_layer, *s_weekname_layer, *s_weeknum_layer, *s_weatherdescript_layer, *s_qt_layer; static BitmapLayer *s_enterprise_layer; static GBitmap *s_enterprise_bitmap; static char api_key[50]; @@ -481,6 +481,13 @@ static void window_load(Window *window) { layer_set_update_proc(s_bt_layer, bt_update_proc); layer_add_child(window_layer, s_bt_layer); + s_qt_layer = text_layer_create(GRect(3,bounds.size.h-(bounds.size.h/12+10)-22,bounds.size.w/6-3,19)); + text_layer_set_font(s_qt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); + text_layer_set_background_color(s_qt_layer, GColorClear); + text_layer_set_text_color(s_qt_layer, GColorBlack); + text_layer_set_text_alignment(s_qt_layer, GTextAlignmentCenter); + layer_add_child(window_layer, text_layer_get_layer(s_qt_layer)); + // Create GFonts s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_LCARS_32)); s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_LCARS_58)); @@ -749,9 +756,17 @@ static void update_steps(){ } } +static void update_qt(){ + if (quiet_time_is_active()) { + text_layer_set_text(s_qt_layer, "QT");} + else { + text_layer_set_text(s_qt_layer, " ");} +} + static void watchface_refresh(){ update_steps(); update_time(); + update_qt(); if ((strlen(ReplacementWeatherMessage)==0)&&(connection_service_peek_pebble_app_connection()==S_TRUE)) { generic_weather_fetch(weather_callback); } else { @@ -787,6 +802,7 @@ static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { if (!Watchface_Hibernate && !Watchface_Sleep) { //if we are no sleeping or hibernating if (tick_time->tm_sec==0) { update_steps(); } update_time(); + update_qt(); //every 30 minutes do the following if ((tick_time->tm_min % 30 == 0)&&(tick_time->tm_sec==0)) { @@ -1091,6 +1107,7 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) update_steps(); // APP_LOG(APP_LOG_LEVEL_DEBUG, "Inbox Updating time"); update_time(); + update_qt(); if (strlen(ReplacementWeatherMessage)==0) { if (WeatherSetupStatusKey&&WeatherSetupStatusProvider&&WeatherReadyRecieved) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "Calling Weather"); @@ -1137,6 +1154,7 @@ static void window_unload(Window *window) { text_layer_destroy(s_weeknum_layer); text_layer_destroy(s_weekname_layer); text_layer_destroy(s_weatherdescript_layer); + text_layer_destroy(s_qt_layer); // Unload GFont fonts_unload_custom_font(s_time_font); @@ -1203,6 +1221,7 @@ static void init() { // Make sure the time and steps are displayed from the start update_steps(); update_time(); + update_qt(); // Register for battery level updates events_battery_state_service_subscribe(battery_callback); From 882c5cc70a914d821b00e4674df62ee3d874ac79 Mon Sep 17 00:00:00 2001 From: Tom Francis Date: Thu, 21 Dec 2017 08:59:08 -0500 Subject: [PATCH 3/5] Revert "Added ability to show quiet time" This reverts commit 8fbdf4c488eb4165625e85305c18afc8c6d2bc7a. That commit was made on the wrong branch. --- src/c/main.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index 6f223f7..c7ed769 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -5,7 +5,7 @@ static Window *s_main_window; static GFont s_time_font, s_date_font, s_weather_icon_font; -static TextLayer *s_date_layer, *s_stardate_layer, *s_batterypercent_layer, *s_lifesupport_text_layer, *s_temperature_layer, *s_city_layer, *icon_weather_layer, *s_time_layer, *s_weekname_layer, *s_weeknum_layer, *s_weatherdescript_layer, *s_qt_layer; +static TextLayer *s_date_layer, *s_stardate_layer, *s_batterypercent_layer, *s_lifesupport_text_layer, *s_temperature_layer, *s_city_layer, *icon_weather_layer, *s_time_layer, *s_weekname_layer, *s_weeknum_layer, *s_weatherdescript_layer; static BitmapLayer *s_enterprise_layer; static GBitmap *s_enterprise_bitmap; static char api_key[50]; @@ -481,13 +481,6 @@ static void window_load(Window *window) { layer_set_update_proc(s_bt_layer, bt_update_proc); layer_add_child(window_layer, s_bt_layer); - s_qt_layer = text_layer_create(GRect(3,bounds.size.h-(bounds.size.h/12+10)-22,bounds.size.w/6-3,19)); - text_layer_set_font(s_qt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); - text_layer_set_background_color(s_qt_layer, GColorClear); - text_layer_set_text_color(s_qt_layer, GColorBlack); - text_layer_set_text_alignment(s_qt_layer, GTextAlignmentCenter); - layer_add_child(window_layer, text_layer_get_layer(s_qt_layer)); - // Create GFonts s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_LCARS_32)); s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_LCARS_58)); @@ -756,17 +749,9 @@ static void update_steps(){ } } -static void update_qt(){ - if (quiet_time_is_active()) { - text_layer_set_text(s_qt_layer, "QT");} - else { - text_layer_set_text(s_qt_layer, " ");} -} - static void watchface_refresh(){ update_steps(); update_time(); - update_qt(); if ((strlen(ReplacementWeatherMessage)==0)&&(connection_service_peek_pebble_app_connection()==S_TRUE)) { generic_weather_fetch(weather_callback); } else { @@ -802,7 +787,6 @@ static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { if (!Watchface_Hibernate && !Watchface_Sleep) { //if we are no sleeping or hibernating if (tick_time->tm_sec==0) { update_steps(); } update_time(); - update_qt(); //every 30 minutes do the following if ((tick_time->tm_min % 30 == 0)&&(tick_time->tm_sec==0)) { @@ -1107,7 +1091,6 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) update_steps(); // APP_LOG(APP_LOG_LEVEL_DEBUG, "Inbox Updating time"); update_time(); - update_qt(); if (strlen(ReplacementWeatherMessage)==0) { if (WeatherSetupStatusKey&&WeatherSetupStatusProvider&&WeatherReadyRecieved) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "Calling Weather"); @@ -1154,7 +1137,6 @@ static void window_unload(Window *window) { text_layer_destroy(s_weeknum_layer); text_layer_destroy(s_weekname_layer); text_layer_destroy(s_weatherdescript_layer); - text_layer_destroy(s_qt_layer); // Unload GFont fonts_unload_custom_font(s_time_font); @@ -1221,7 +1203,6 @@ static void init() { // Make sure the time and steps are displayed from the start update_steps(); update_time(); - update_qt(); // Register for battery level updates events_battery_state_service_subscribe(battery_callback); From 9a3dac9104ce9d0fd21516b0ed1ceb9f7b580aff Mon Sep 17 00:00:00 2001 From: Tom Francis Date: Thu, 21 Dec 2017 10:10:54 -0500 Subject: [PATCH 4/5] Restored . to characterRegex The removal of . was not intentional. It should remain. However, escaping . in a character class is not necessary, so I didn't restore the double \ in front of it. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 647f576..0aac413 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "resources": { "media": [ { - "characterRegex": "[0-9 ]", + "characterRegex": "[0-9. ]", "file": "fonts/LCARSGTJ3_58.ttf", "name": "LCARS_58", "targetPlatforms": [ From 0eca7f3d671cfb55a5299f5b969571e81b892e7b Mon Sep 17 00:00:00 2001 From: Tom Francis Date: Tue, 2 Jan 2018 08:22:47 -0500 Subject: [PATCH 5/5] Fixed crash with unloading window If both power saving options are off, the watchface will crash when unloading, because it tries to unsubscribe from the health service events, but it never subscribed in the first place! Also fixed unsubscribing from the tick timer service, since the wrong parameter was passed to unsubscribe when unloading the window, and it wasn't protected by a NULL pointer check (it shouldn't be NULL, but just in case, it's better to check). --- src/c/main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/c/main.c b/src/c/main.c index c7ed769..fee4280 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -18,7 +18,7 @@ static int loweracrossline = 90, upperacrossline = 50, textleft = 25, watchwidth static PropertyAnimation *image_property_animation; //1800000 static bool WeatherSetupStatusKey = S_FALSE, WeatherSetupStatusProvider = S_FALSE, WeatherReadyRecieved = S_FALSE, HibernateEnable = S_TRUE, SleepEnable = S_TRUE; GColor text_color; -static EventHandle s_health_event_handle, s_tick_timer_event_handle;//, s_idle_timer_event_handle; +static EventHandle s_health_event_handle=NULL, s_tick_timer_event_handle=NULL;//, s_idle_timer_event_handle; static void read_persist() { @@ -1023,7 +1023,9 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context) HibernateEnable = data->value->int32 == 1; //register to recieve significant updates of which we are looking for sleep updates - events_health_service_events_unsubscribe(s_health_event_handle); + if (s_health_event_handle != NULL) { + events_health_service_events_unsubscribe(s_health_event_handle); + } if (SleepEnable||HibernateEnable) { s_health_event_handle = events_health_service_events_subscribe(prv_health_event_handler, NULL); } @@ -1159,8 +1161,12 @@ static void window_unload(Window *window) { //unsubscribe from services events_battery_state_service_unsubscribe(battery_callback); events_connection_service_unsubscribe(bluetooth_callback); - events_tick_timer_service_unsubscribe(tick_handler); - events_health_service_events_unsubscribe(s_health_event_handle); + if (s_tick_timer_event_handle!=NULL) { + events_tick_timer_service_unsubscribe(s_tick_timer_event_handle); + } + if (s_health_event_handle != NULL) { + events_health_service_events_unsubscribe(s_health_event_handle); + } events_app_message_unsubscribe(inbox_received_callback); events_app_message_unsubscribe(inbox_dropped_callback); events_app_message_unsubscribe(outbox_failed_callback);