From 014a30d8bfd10e0cc27d9318c05a4d6644a6210a Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 31 May 2023 18:14:30 +0100 Subject: [PATCH] Fix xtreme settings values handling --- .../main/archive/helpers/favorite_timeout.c | 2 +- .../xtreme_app_scene_interface_graphics.c | 8 +- .../xtreme_app_scene_interface_statusbar.c | 2 +- .../xtreme_app/scenes/xtreme_app_scene_misc.c | 8 +- .../desktop/animations/animation_storage.c | 2 +- applications/services/dolphin/dolphin.c | 4 +- .../services/power/power_service/power.c | 3 +- lib/xtreme/settings.c | 103 +++++++++++++----- lib/xtreme/xtreme.h | 2 +- 9 files changed, 94 insertions(+), 40 deletions(-) diff --git a/applications/main/archive/helpers/favorite_timeout.c b/applications/main/archive/helpers/favorite_timeout.c index 7643ebfc8..25385614e 100644 --- a/applications/main/archive/helpers/favorite_timeout.c +++ b/applications/main/archive/helpers/favorite_timeout.c @@ -17,7 +17,7 @@ void favorite_timeout_callback(void* _ctx) { } void favorite_timeout_run(ViewDispatcher* view_dispatcher, SceneManager* scene_manager) { - int32_t timeout = XTREME_SETTINGS()->favorite_timeout; + uint32_t timeout = XTREME_SETTINGS()->favorite_timeout; if(timeout == 0) { view_dispatcher_run(view_dispatcher); return; diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c index 462f7c6d3..7b698b182 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_graphics.c @@ -28,7 +28,7 @@ static void xtreme_app_scene_interface_graphics_asset_pack_changed(VariableItem* const char* const anim_speed_names[] = {"25%", "50%", "75%", "100%", "125%", "150%", "175%", "200%", "225%", "250%", "275%", "300%"}; -const int32_t anim_speed_values[COUNT_OF(anim_speed_names)] = +const uint32_t anim_speed_values[COUNT_OF(anim_speed_names)] = {25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300}; static void xtreme_app_scene_interface_graphics_anim_speed_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); @@ -104,8 +104,8 @@ void xtreme_app_scene_interface_graphics_on_enter(void* context) { COUNT_OF(anim_speed_names), xtreme_app_scene_interface_graphics_anim_speed_changed, app); - value_index = value_index_int32( - xtreme_settings->anim_speed, anim_speed_values, COUNT_OF(anim_speed_names)); + value_index = value_index_uint32( + xtreme_settings->anim_speed, anim_speed_values, COUNT_OF(anim_speed_values)); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, anim_speed_names[value_index]); @@ -116,7 +116,7 @@ void xtreme_app_scene_interface_graphics_on_enter(void* context) { xtreme_app_scene_interface_graphics_cycle_anims_changed, app); value_index = value_index_int32( - xtreme_settings->cycle_anims, cycle_anims_values, COUNT_OF(cycle_anims_names)); + xtreme_settings->cycle_anims, cycle_anims_values, COUNT_OF(cycle_anims_values)); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, cycle_anims_names[value_index]); diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c index b0f6f9a05..1a3eb36b1 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_statusbar.c @@ -12,7 +12,7 @@ void xtreme_app_scene_interface_statusbar_var_item_list_callback(void* context, view_dispatcher_send_custom_event(app->view_dispatcher, index); } -const char* const battery_icon_names[] = +const char* const battery_icon_names[BatteryIconCount] = {"OFF", "Bar", "%", "Inv. %", "Retro 3", "Retro 5", "Bar %"}; static void xtreme_app_scene_interface_statusbar_battery_icon_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c index b54ef152b..84bb37886 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c @@ -35,8 +35,8 @@ static void xtreme_app_scene_misc_dolphin_angry_changed(VariableItem* item) { const char* const butthurt_timer_names[] = {"OFF", "30 M", "1 H", "2 H", "4 H", "6 H", "8 H", "12 H", "24 H", "48 H"}; -const int32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] = - {-1, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 172800}; +const uint32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] = + {0, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 172800}; static void xtreme_app_scene_misc_butthurt_timer_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -103,8 +103,8 @@ void xtreme_app_scene_misc_on_enter(void* context) { COUNT_OF(butthurt_timer_names), xtreme_app_scene_misc_butthurt_timer_changed, app); - value_index = value_index_int32( - xtreme_settings->butthurt_timer, butthurt_timer_values, COUNT_OF(butthurt_timer_names)); + value_index = value_index_uint32( + xtreme_settings->butthurt_timer, butthurt_timer_values, COUNT_OF(butthurt_timer_values)); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, butthurt_timer_names[value_index]); diff --git a/applications/services/desktop/animations/animation_storage.c b/applications/services/desktop/animations/animation_storage.c index b412d175b..a173de2a3 100644 --- a/applications/services/desktop/animations/animation_storage.c +++ b/applications/services/desktop/animations/animation_storage.c @@ -521,7 +521,7 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) { if(!flipper_format_read_uint32(ff, "Active cycles", &u32value, 1)) break; //-V779 animation->active_cycles = u32value; if(!flipper_format_read_uint32(ff, "Frame rate", &u32value, 1)) break; - uint16_t anim_speed = XTREME_SETTINGS()->anim_speed; + uint32_t anim_speed = XTREME_SETTINGS()->anim_speed; u32value = (u32value * anim_speed) / 100; FURI_CONST_ASSIGN(animation->icon_animation.frame_rate, u32value < 1 ? 1 : u32value); if(!flipper_format_read_uint32(ff, "Duration", &u32value, 1)) break; diff --git a/applications/services/dolphin/dolphin.c b/applications/services/dolphin/dolphin.c index baa1736fd..64fa41332 100644 --- a/applications/services/dolphin/dolphin.c +++ b/applications/services/dolphin/dolphin.c @@ -80,10 +80,10 @@ Dolphin* dolphin_alloc() { dolphin->state = dolphin_state_alloc(); dolphin->event_queue = furi_message_queue_alloc(8, sizeof(DolphinEvent)); dolphin->pubsub = furi_pubsub_alloc(); - int32_t butthurt = XTREME_SETTINGS()->butthurt_timer; + uint32_t butthurt_timer = XTREME_SETTINGS()->butthurt_timer; dolphin->butthurt_timer = xTimerCreate( NULL, - (butthurt > 0) ? (butthurt * 1000) : -1, + butthurt_timer ? ((int32_t)butthurt_timer * 1000) : -1, pdTRUE, dolphin, dolphin_butthurt_timer_callback); diff --git a/applications/services/power/power_service/power.c b/applications/services/power/power_service/power.c index 423f767b9..0810c84d6 100644 --- a/applications/services/power/power_service/power.c +++ b/applications/services/power/power_service/power.c @@ -473,7 +473,8 @@ static void power_check_battery_level_change(Power* power) { } static void power_check_charge_cap(Power* power) { - if(power->info.charge >= XTREME_SETTINGS()->charge_cap) { + uint32_t cap = XTREME_SETTINGS()->charge_cap; + if(power->info.charge >= cap && cap < 100) { if(!power->info.is_charge_capped) { // Suppress charging if charge reaches custom cap power->info.is_charge_capped = true; furi_hal_power_suppress_charge_enter(); diff --git a/lib/xtreme/settings.c b/lib/xtreme/settings.c index 2ced296a4..f87e30f5f 100644 --- a/lib/xtreme/settings.c +++ b/lib/xtreme/settings.c @@ -46,54 +46,107 @@ void XTREME_SETTINGS_LOAD() { x->is_nsfw = strncmp(x->asset_pack, "NSFW", strlen("NSFW")) == 0; } furi_string_free(string); + uint32_t u; + int32_t i; + bool b; flipper_format_rewind(file); - flipper_format_read_uint32(file, "anim_speed", &x->anim_speed, 1); + if(flipper_format_read_uint32(file, "anim_speed", &u, 1)) { + x->anim_speed = CLAMP(u, 300U, 25U); + } flipper_format_rewind(file); - flipper_format_read_int32(file, "cycle_anims", &x->cycle_anims, 1); + if(flipper_format_read_int32(file, "cycle_anims", &i, 1)) { + x->cycle_anims = CLAMP(i, 86400, -1); + } flipper_format_rewind(file); - flipper_format_read_bool(file, "unlock_anims", &x->unlock_anims, 1); + if(flipper_format_read_bool(file, "unlock_anims", &b, 1)) { + x->unlock_anims = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "fallback_anim", &x->fallback_anim, 1); + if(flipper_format_read_bool(file, "fallback_anim", &b, 1)) { + x->fallback_anim = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "wii_menu", &x->wii_menu, 1); + if(flipper_format_read_bool(file, "wii_menu", &b, 1)) { + x->wii_menu = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "bad_pins_format", &x->bad_pins_format, 1); + if(flipper_format_read_bool(file, "bad_pins_format", &b, 1)) { + x->bad_pins_format = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "lock_on_boot", &x->lock_on_boot, 1); + if(flipper_format_read_bool(file, "lock_on_boot", &b, 1)) { + x->lock_on_boot = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "lockscreen_time", &x->lockscreen_time, 1); + if(flipper_format_read_bool(file, "lockscreen_time", &b, 1)) { + x->lockscreen_time = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "lockscreen_seconds", &x->lockscreen_seconds, 1); + if(flipper_format_read_bool(file, "lockscreen_seconds", &b, 1)) { + x->lockscreen_seconds = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "lockscreen_date", &x->lockscreen_date, 1); + if(flipper_format_read_bool(file, "lockscreen_date", &b, 1)) { + x->lockscreen_date = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "lockscreen_statusbar", &x->lockscreen_statusbar, 1); + if(flipper_format_read_bool(file, "lockscreen_statusbar", &b, 1)) { + x->lockscreen_statusbar = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "lockscreen_prompt", &x->lockscreen_prompt, 1); + if(flipper_format_read_bool(file, "lockscreen_prompt", &b, 1)) { + x->lockscreen_prompt = b; + } flipper_format_rewind(file); - flipper_format_read_uint32(file, "battery_icon", (uint32_t*)&x->battery_icon, 1); + if(flipper_format_read_uint32(file, "battery_icon", &u, 1)) { + x->battery_icon = CLAMP(u, BatteryIconCount - 1U, 0U); + } flipper_format_rewind(file); - flipper_format_read_bool(file, "status_icons", &x->status_icons, 1); + if(flipper_format_read_bool(file, "status_icons", &b, 1)) { + x->status_icons = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "bar_borders", &x->bar_borders, 1); + if(flipper_format_read_bool(file, "bar_borders", &b, 1)) { + x->bar_borders = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "bar_background", &x->bar_background, 1); + if(flipper_format_read_bool(file, "bar_background", &b, 1)) { + x->bar_background = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "sort_dirs_first", &x->sort_dirs_first, 1); + if(flipper_format_read_bool(file, "sort_dirs_first", &b, 1)) { + x->sort_dirs_first = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "dark_mode", &x->dark_mode, 1); + if(flipper_format_read_bool(file, "dark_mode", &b, 1)) { + { + x->dark_mode = b; + } + } flipper_format_rewind(file); - flipper_format_read_uint32(file, "favorite_timeout", &x->favorite_timeout, 1); + if(flipper_format_read_uint32(file, "favorite_timeout", &u, 1)) { + x->favorite_timeout = CLAMP(u, 60U, 0U); + } flipper_format_rewind(file); - flipper_format_read_bool(file, "bad_bt", &x->bad_bt, 1); + if(flipper_format_read_bool(file, "bad_bt", &b, 1)) { + x->bad_bt = b; + } flipper_format_rewind(file); - flipper_format_read_bool(file, "bad_bt_remember", &x->bad_bt_remember, 1); + if(flipper_format_read_bool(file, "bad_bt_remember", &b, 1)) { + x->bad_bt_remember = b; + } flipper_format_rewind(file); - flipper_format_read_int32(file, "butthurt_timer", &x->butthurt_timer, 1); + if(flipper_format_read_uint32(file, "butthurt_timer", &u, 1)) { + x->butthurt_timer = CLAMP(u, 172800U, 0U); + } flipper_format_rewind(file); - flipper_format_read_uint32(file, "charge_cap", &x->charge_cap, 1); + if(flipper_format_read_uint32(file, "charge_cap", &u, 1)) { + x->charge_cap = CLAMP(u, 100U, 5U); + } flipper_format_rewind(file); - flipper_format_read_bool(file, "rgb_backlight", &x->rgb_backlight, 1); + if(flipper_format_read_bool(file, "rgb_backlight", &b, 1)) { + x->rgb_backlight = b; + } } flipper_format_free(file); furi_record_close(RECORD_STORAGE); @@ -128,7 +181,7 @@ void XTREME_SETTINGS_SAVE() { flipper_format_write_uint32(file, "favorite_timeout", &x->favorite_timeout, 1); flipper_format_write_bool(file, "bad_bt", &x->bad_bt, 1); flipper_format_write_bool(file, "bad_bt_remember", &x->bad_bt_remember, 1); - flipper_format_write_int32(file, "butthurt_timer", &x->butthurt_timer, 1); + flipper_format_write_uint32(file, "butthurt_timer", &x->butthurt_timer, 1); flipper_format_write_uint32(file, "charge_cap", &x->charge_cap, 1); flipper_format_write_bool(file, "rgb_backlight", &x->rgb_backlight, 1); } diff --git a/lib/xtreme/xtreme.h b/lib/xtreme/xtreme.h index bb5b265e9..a827730f8 100644 --- a/lib/xtreme/xtreme.h +++ b/lib/xtreme/xtreme.h @@ -36,7 +36,7 @@ typedef struct { uint32_t favorite_timeout; bool bad_bt; bool bad_bt_remember; - int32_t butthurt_timer; + uint32_t butthurt_timer; uint32_t charge_cap; bool rgb_backlight; } XtremeSettings;