Fix need for face restart when changing warning color if a warning indicator is already on

This commit is contained in:
2026-06-13 17:09:48 -04:00
parent d067194cb5
commit 0e44c32577
+75 -65
View File
@@ -16,20 +16,17 @@ static Layer *s_fuel_mg_layer;
static Layer *s_fuel_layer;
static const uint8_t s_x_r = (PBL_DISPLAY_WIDTH / 2) + 2;
static const uint8_t s_x_l = (s_x_r - 2 * (69 / 2)) - 5;
#if PBL_DISPLAY_HEIGHT == 260
static const GRect s_time_grects[4] = {GRect(s_x_l, 18, 69, 110), GRect(s_x_r, 18, 69, 110), GRect(s_x_l, 132, 69, 110), GRect(s_x_r, 132, 69, 110)};
#elif PBL_DISPLAY_HEIGHT == 180
static const GRect s_time_grects[4] = {GRect(s_x_l, -22, 69, 110), GRect(s_x_r, -22, 69, 110), GRect(s_x_l, 92, 69, 110), GRect(s_x_r, 92, 69, 110)};
#else
static const GRect s_time_grects[4] = {GRect(s_x_l, 2, 69, 110), GRect(s_x_r, 2, 69, 110), GRect(s_x_l, 116, 69, 110), GRect(s_x_r, 116, 69, 110)};
#endif
static const GRect s_time_grects[4] = {GRect(s_x_l, 2, 69, 110), GRect(s_x_r, 2, 69, 110), GRect(s_x_l, 116, 69, 110), GRect(s_x_r, 116, 69, 110)}; // emery
static const uint8_t s_temp_guage_x_pos = 6;
static const uint16_t s_fuel_guage_x_pos = PBL_DISPLAY_WIDTH - 23;
// settings statics
static ClaySettings settings;
static GColor s_applied_fg = GColorWhite;
static GColor s_applied_time_mg = GColorDarkGray;
static GColor s_applied_f = GColorWhite; // only foreground element to not change color for warnings, so it is used as the base fg color
static GColor s_applied_e = GColorWhite;
static GColor s_applied_c_h = GColorWhite;
static GColor s_applied_time_date = GColorWhite;
// bitmap statics
static GBitmap *s_font_bitmaps[10];
@@ -40,10 +37,11 @@ static GBitmap *s_e_icon;
static GBitmap *s_f_icon;
// tracking statics
static bool s_first_settings_application = true;
static bool s_showing_date = false;
static AppTimer *s_date_timer = NULL;
static bool s_pkjs_ready = false;
static bool s_low_fuel_indicator = false;
static bool s_fuel_is_warning = false;
static int s_batt_level;
static bool s_temp_is_warning = false;
static uint8_t s_temp_level;
@@ -53,29 +51,55 @@ static const uint8_t s_bar_height = 8;
static const uint8_t s_bar_width = 17;
static const uint8_t s_bar_spacing = s_bar_height + 1;
static void batt_callback(BatteryChargeState state) {
s_batt_level = state.charge_percent / 5;
layer_mark_dirty(s_fuel_layer);
if (!s_low_fuel_indicator && state.charge_percent <= settings.LowFuelPercent) {
replace_gbitmap_color(s_applied_fg, settings.ColorWarning, s_e_icon, s_e_layer);
s_low_fuel_indicator = true;
} else if (s_low_fuel_indicator && state.charge_percent > settings.LowFuelPercent) {
replace_gbitmap_color(settings.ColorWarning, s_applied_fg, s_e_icon, s_e_layer);
s_low_fuel_indicator = false;
static void toggle_fuel_warning_state(bool enable_warning, bool force) {
GColor dst = enable_warning ? settings.ColorWarning : settings.ColorFG;
if ((!force && (enable_warning == s_fuel_is_warning)) || (s_first_settings_application && !enable_warning && dst.argb == s_applied_e.argb)) {
// at startup, s_applied_e.argb is GColorWhite
// for those using white fg, do not pointlessly replace white at startup if that is the destination anyway
return;
}
replace_gbitmap_color(s_applied_e, dst, s_e_icon, s_e_layer);
s_applied_e = dst;
s_fuel_is_warning = enable_warning;
}
static void toggle_temp_warning_state(bool enable_warning, bool force) {
GColor dst = enable_warning ? settings.ColorWarning : settings.ColorFG;
if ((!force && (enable_warning == s_temp_is_warning)) || (s_first_settings_application && !enable_warning && dst.argb == s_applied_c_h.argb)) {
// at startup, s_applied_c_h.argb is GColorWhite
// for those using white fg, do not pointlessly replace white at startup if that is the destination anyway
return;
}
replace_gbitmap_color(s_applied_c_h, dst, s_c_icon, s_c_layer);
replace_gbitmap_color(s_applied_c_h, dst, s_h_icon, s_h_layer);
s_applied_c_h = dst;
s_temp_is_warning = enable_warning;
}
static void bt_callback(bool connected) {
GColor src = connected ? settings.ColorWarning : s_applied_fg;
GColor dst = connected ? s_applied_fg : settings.ColorWarning;
GColor dst = connected ? settings.ColorFG : settings.ColorWarning;
if (s_first_settings_application && connected && dst.argb == s_applied_time_date.argb) {
// at startup, s_applied_time_date.argb is GColorWhite
// for those using white fg, do not pointlessly replace white at startup if that is the destination anyway
return;
}
for (int i = 0; i < 10; ++i) {
replace_gbitmap_color(src, dst, s_font_bitmaps[i], NULL);
replace_gbitmap_color(s_applied_time_date, dst, s_font_bitmaps[i], NULL);
}
for (int i = 0; i < 4; ++i) {
layer_mark_dirty(bitmap_layer_get_layer(s_time_fg_layers[i]));
}
s_applied_time_date = dst;
}
static void batt_callback(BatteryChargeState state) {
s_batt_level = state.charge_percent / 5;
layer_mark_dirty(s_fuel_layer);
if (state.charge_percent <= settings.LowFuelPercent) {
toggle_fuel_warning_state(true, false);
} else {
toggle_fuel_warning_state(false, false);
}
}
static void temp_update_proc(Layer *layer, GContext *ctx) {
@@ -127,20 +151,6 @@ static void fuel_mg_update_proc(Layer *layer, GContext *ctx) {
temp_fuel_mg_update_proc_helper(layer, ctx, true);
}
static void toggle_temp_warning_state(bool enable_warning) {
if (enable_warning == s_temp_is_warning) {
return;
}
GColor src = enable_warning ? s_applied_fg : settings.ColorWarning;
GColor dst = enable_warning ? settings.ColorWarning : s_applied_fg;
replace_gbitmap_color(src, dst, s_c_icon, s_c_layer);
replace_gbitmap_color(src, dst, s_h_icon, s_h_layer);
s_temp_is_warning = enable_warning;
}
static void update_temperature() {
if (!s_pkjs_ready) {
return;
@@ -149,16 +159,16 @@ static void update_temperature() {
DictionaryIterator *out;
AppMessageResult result = app_message_outbox_begin(&out);
if (result != APP_MSG_OK) {
toggle_temp_warning_state(true);
toggle_temp_warning_state(true, false);
return;
}
dict_write_int8(out, MESSAGE_KEY_PKJS_TEMP_BAR_COUNT, 1);
result = app_message_outbox_send();
if (result != APP_MSG_OK) {
toggle_temp_warning_state(true);
toggle_temp_warning_state(true, false);
return;
}
toggle_temp_warning_state(false);
toggle_temp_warning_state(false, false);
}
static void update_minute_1() {
@@ -216,7 +226,7 @@ static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
s_date_timer = app_timer_register(settings.DateTimeoutSecs * 1000, date_timeout, NULL);
}
static void apply_settings(bool first_run) {
static void apply_settings() {
// LED&BG
if (settings.UseCustomLED) {
light_set_color(settings.ColorLED); // no-op on unsupported platforms
@@ -234,7 +244,7 @@ static void apply_settings(bool first_run) {
}
//// create and insert any mg layer that does not already exist
Layer *sibling_layer = NULL;
if (first_run) {
if (s_first_settings_application) {
sibling_layer = window_get_root_layer(s_main_window);
} else {
sibling_layer = bitmap_layer_get_layer(s_time_fg_layers[0]);
@@ -244,7 +254,7 @@ static void apply_settings(bool first_run) {
s_time_mg_layers[i] = bitmap_layer_create(s_time_grects[i]);
bitmap_layer_set_bitmap(s_time_mg_layers[i], s_time_mg_super8);
bitmap_layer_set_compositing_mode(s_time_mg_layers[i], GCompOpSet);
if (first_run) {
if (s_first_settings_application) {
layer_add_child(sibling_layer, bitmap_layer_get_layer(s_time_mg_layers[i]));
} else {
layer_insert_below_sibling(bitmap_layer_get_layer(s_time_mg_layers[i]), sibling_layer);
@@ -276,21 +286,26 @@ static void apply_settings(bool first_run) {
layer_mark_dirty(s_temp_mg_layer);
layer_mark_dirty(s_fuel_mg_layer);
// FG
if (settings.ColorFG.argb != s_applied_fg.argb) {
for (int i = 0; i < 10; ++i) {
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_font_bitmaps[i], NULL);
}
for (int i = 0; i < 4; ++i) {
layer_mark_dirty(bitmap_layer_get_layer(s_time_fg_layers[i]));
}
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_c_icon, s_c_layer);
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_h_icon, s_h_layer);
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_e_icon, s_e_layer);
replace_gbitmap_color(s_applied_fg, settings.ColorFG, s_f_icon, s_f_layer);
s_applied_fg = settings.ColorFG;
// FG & warning indicators
// time+date (re-sub bt tracking)
connection_service_unsubscribe();
if (settings.TrackBTStatus) {
connection_service_subscribe((ConnectionHandlers){.pebble_app_connection_handler = bt_callback});
bt_callback(connection_service_peek_pebble_app_connection());
} else {
bt_callback(true);
}
// temp (c & h icons)
toggle_temp_warning_state(s_temp_is_warning, true);
// fuel (e icon)
toggle_fuel_warning_state(s_fuel_is_warning, true);
// f icon (always fg color, never a warning indicator)
replace_gbitmap_color(s_applied_f, settings.ColorFG, s_f_icon, s_f_layer);
s_applied_f = settings.ColorFG;
// changes to temperature range
update_temperature();
@@ -303,13 +318,8 @@ static void apply_settings(bool first_run) {
accel_tap_service_subscribe(accel_tap_handler);
}
// re-sub bt tracking
connection_service_unsubscribe();
if (settings.TrackBTStatus) {
connection_service_subscribe((ConnectionHandlers){.pebble_app_connection_handler = bt_callback});
bt_callback(connection_service_peek_pebble_app_connection());
} else {
bt_callback(true);
if (s_first_settings_application) {
s_first_settings_application = false;
}
}
@@ -334,7 +344,7 @@ static void main_window_load() {
bitmap_layer_set_compositing_mode(s_e_layer, GCompOpSet);
bitmap_layer_set_compositing_mode(s_f_layer, GCompOpSet);
apply_settings(true);
apply_settings();
for (int i = 0; i < 4; ++i) {
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_fg_layers[i]));
@@ -436,7 +446,7 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
settings.ColorWarning = GColorFromHEX(color_warning_tuple->value->int32);
}
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
apply_settings(false);
apply_settings();
}
static void init() {