storage-settings-scene-internal-info.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "../storage-settings.h"
  2. #include <api-hal-version.h>
  3. static void
  4. storage_settings_scene_internal_info_dialog_callback(DialogExResult result, void* context) {
  5. StorageSettings* app = context;
  6. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  7. }
  8. void storage_settings_scene_internal_info_on_enter(void* context) {
  9. StorageSettings* app = context;
  10. uint64_t total_space;
  11. uint64_t free_space;
  12. FS_Error error = storage_common_fs_info(app->fs_api, "/int", &total_space, &free_space);
  13. DialogEx* dialog_ex = app->dialog_ex;
  14. dialog_ex_set_context(dialog_ex, app);
  15. dialog_ex_set_result_callback(dialog_ex, storage_settings_scene_internal_info_dialog_callback);
  16. dialog_ex_set_left_button_text(dialog_ex, "Back");
  17. if(error != FSE_OK) {
  18. dialog_ex_set_header(
  19. dialog_ex, "Internal storage error", 64, 10, AlignCenter, AlignCenter);
  20. dialog_ex_set_text(
  21. dialog_ex, storage_error_get_desc(error), 64, 32, AlignCenter, AlignCenter);
  22. } else {
  23. string_printf(
  24. app->text_string,
  25. "Label: %s\nType: LittleFS\n%lu KB total\n%lu KB free",
  26. api_hal_version_get_name_ptr(),
  27. (uint32_t)(total_space / 1024),
  28. (uint32_t)(free_space / 1024));
  29. dialog_ex_set_text(
  30. dialog_ex, string_get_cstr(app->text_string), 4, 4, AlignLeft, AlignTop);
  31. }
  32. view_dispatcher_switch_to_view(app->view_dispatcher, StorageSettingsViewDialogEx);
  33. }
  34. bool storage_settings_scene_internal_info_on_event(void* context, SceneManagerEvent event) {
  35. StorageSettings* app = context;
  36. bool consumed = false;
  37. if(event.type == SceneManagerEventTypeCustom) {
  38. switch(event.event) {
  39. case DialogExResultLeft:
  40. consumed = scene_manager_previous_scene(app->scene_manager);
  41. break;
  42. }
  43. }
  44. return consumed;
  45. }
  46. void storage_settings_scene_internal_info_on_exit(void* context) {
  47. StorageSettings* app = context;
  48. DialogEx* dialog_ex = app->dialog_ex;
  49. dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
  50. dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
  51. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  52. dialog_ex_set_left_button_text(dialog_ex, NULL);
  53. dialog_ex_set_right_button_text(dialog_ex, NULL);
  54. dialog_ex_set_result_callback(dialog_ex, NULL);
  55. dialog_ex_set_context(dialog_ex, NULL);
  56. string_clean(app->text_string);
  57. }