From 9a1629ee4e7c4f6b9e140a1b67583a6641fd539d Mon Sep 17 00:00:00 2001 From: RogueMaster Date: Sun, 18 Sep 2022 00:31:48 -0400 Subject: [PATCH] updates from non-bin --- ReadMe.md | 1 + .../scenes/storage_settings_scene_sd_info.c | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 3ab5bed10..a9d0e8708 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -161,6 +161,7 @@ $ ./fbt plugin_dist FIRMWARE_APP_SET=ext_apps - [dummy mode #1739 (By nminaylov)](https://github.com/flipperdevices/flipperzero-firmware/pull/1739) - [picopass se identify #1701 (By bettse/pcunning)](https://github.com/flipperdevices/flipperzero-firmware/pull/1701) - [Picopass plugin fixed #1742 (By bettse/pcunning)](https://github.com/flipperdevices/flipperzero-firmware/pull/1742) +- [SD info: Add dynamic units and free % #1634 (By non-bin)](https://github.com/flipperdevices/flipperzero-firmware/pull/1634) diff --git a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c index cfb4f310d..497455529 100644 --- a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c +++ b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c @@ -24,13 +24,44 @@ void storage_settings_scene_sd_info_on_enter(void* context) { dialog_ex, "Try to reinsert\nor format SD\ncard.", 3, 19, AlignLeft, AlignTop); dialog_ex_set_center_button_text(dialog_ex, "Ok"); } else { + char unit_kb[] = "KB"; + char unit_mb[] = "MB"; + char unit_gb[] = "GB"; + + double sd_total_val = (double)sd_info.kb_total; + char* sd_total_unit = unit_kb; + double sd_free_val = (double)sd_info.kb_free; + char* sd_free_unit = unit_kb; + + if(sd_total_val > 1024) { + sd_total_val /= 1024; + sd_total_unit = unit_mb; + } + if(sd_total_val > 1024) { + sd_total_val /= 1024; + sd_total_unit = unit_gb; + } + + if(sd_free_val > 1024) { + sd_free_val /= 1024; + sd_free_unit = unit_mb; + } + if(sd_free_val > 1024) { + sd_free_val /= 1024; + sd_free_unit = unit_gb; + } + string_printf( app->text_string, - "Label: %s\nType: %s\n%lu KB total\n%lu KB free", + "Label: %s\nType: %s\n%.2f %s total\n%.2f %s free\n%.2f%% free", sd_info.label, sd_api_get_fs_type_text(sd_info.fs_type), - sd_info.kb_total, - sd_info.kb_free); + sd_total_val, + sd_total_unit, + sd_free_val, + sd_free_unit, + (double)(((int)sd_info.kb_free * 100.0) / (int)sd_info.kb_total)); + dialog_ex_set_text( dialog_ex, string_get_cstr(app->text_string), 4, 4, AlignLeft, AlignTop); }