-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SD info: Add dynamic units and free % #1634
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using float point math here is kinda overkill. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Especially using double. Float should be more than enough, use cast at the last moment when passing it to string_printf. |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better solution will be to implement formatting function that takes double* and const char** |
||
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%lu%% 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, | ||
(sd_info.kb_free * 100) / sd_info.kb_total); | ||
|
||
dialog_ex_set_text( | ||
dialog_ex, string_get_cstr(app->text_string), 4, 4, AlignLeft, AlignTop); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to put it in ram, use const.