From 8ce5af1be22613fe300b03f6d26501b09dc7088e Mon Sep 17 00:00:00 2001 From: gornekich <44112859+gornekich@users.noreply.github.com> Date: Wed, 7 Apr 2021 10:37:10 +0300 Subject: [PATCH] [FL-1050] SD card error view (#399) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * sd-filesystem: add check error to api * sd-filesystem: call error check from file select * ibutton: process sd card error on key saving Co-authored-by: rusdacent <57439765+rusdacent@users.noreply.github.com> Co-authored-by: あく --- .../ibutton/scene/ibutton-scene-save-name.cpp | 6 ++- applications/sd-filesystem/sd-filesystem.c | 40 ++++++++++++++----- applications/sd-filesystem/sd-filesystem.h | 1 + lib/common-api/sd-card-api.h | 1 + 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/applications/ibutton/scene/ibutton-scene-save-name.cpp b/applications/ibutton/scene/ibutton-scene-save-name.cpp index e84cf2f2..f7bbe4ed 100644 --- a/applications/ibutton/scene/ibutton-scene-save-name.cpp +++ b/applications/ibutton/scene/ibutton-scene-save-name.cpp @@ -41,12 +41,16 @@ bool iButtonSceneSaveName::on_event(iButtonApp* app, iButtonEvent* event) { app->get_fs_api()->common.mkdir("ibutton"); bool res = app->get_fs_api()->file.open( &key_file, string_get_cstr(key_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS); + // TODO process file system errors from file system service if(res) { res = app->get_fs_api()->file.write(&key_file, key_data, IBUTTON_KEY_SIZE + 1); res = app->get_fs_api()->file.close(&key_file); + app->switch_to_next_scene(iButtonApp::Scene::SceneSaveSuccess); + } else { + app->get_sd_ex_api()->check_error(app->get_sd_ex_api()->context); + app->switch_to_next_scene(iButtonApp::Scene::SceneStart); } string_clear(key_file_name); - app->switch_to_next_scene(iButtonApp::Scene::SceneSaveSuccess); consumed = true; } diff --git a/applications/sd-filesystem/sd-filesystem.c b/applications/sd-filesystem/sd-filesystem.c index af468e03..ea1bf136 100644 --- a/applications/sd-filesystem/sd-filesystem.c +++ b/applications/sd-filesystem/sd-filesystem.c @@ -49,7 +49,6 @@ typedef struct { typedef struct { SdAppEventType type; - osMessageQueueId_t result_receiver; union { SdAppFileSelectData file_select_data; } payload; @@ -62,6 +61,7 @@ bool sd_api_file_select( const char* extension, char* result, uint8_t result_size); +void sd_api_check_error(SdApp* sd_app); /******************* Allocators *******************/ @@ -109,6 +109,7 @@ SdApp* sd_app_alloc() { furi_check(_fs_init(&sd_app->info)); sd_app->event_queue = osMessageQueueNew(8, sizeof(SdAppEvent), NULL); + sd_app->result_receiver = osMessageQueueNew(1, sizeof(SdAppFileSelectResultEvent), NULL); // init icon view_port sd_app->icon.view_port = view_port_alloc(); @@ -121,6 +122,7 @@ SdApp* sd_app_alloc() { // init sd card api sd_app->sd_card_api.context = sd_app; sd_app->sd_card_api.file_select = sd_api_file_select; + sd_app->sd_card_api.check_error = sd_api_check_error; sd_app->sd_app_state = SdAppStateBackground; string_init(sd_app->text_holder); @@ -383,12 +385,8 @@ bool sd_api_file_select( uint8_t result_size) { bool retval = false; - osMessageQueueId_t return_event_queue = - osMessageQueueNew(1, sizeof(SdAppFileSelectResultEvent), NULL); - SdAppEvent message = { .type = SdAppEventTypeFileSelect, - .result_receiver = return_event_queue, .payload = { .file_select_data = { .path = path, @@ -401,16 +399,24 @@ bool sd_api_file_select( SdAppFileSelectResultEvent event; while(1) { osStatus_t event_status = - osMessageQueueGet(return_event_queue, &event, NULL, osWaitForever); + osMessageQueueGet(sd_app->result_receiver, &event, NULL, osWaitForever); if(event_status == osOK) { retval = event.result; break; } } + if(!retval) { + sd_api_check_error(sd_app); + } return retval; } +void sd_api_check_error(SdApp* sd_app) { + SdAppEvent message = {.type = SdAppEventTypeCheckError}; + furi_check(osMessageQueuePut(sd_app->event_queue, &message, 0, osWaitForever) == osOK); +} + /******************* View callbacks *******************/ void app_view_back_callback(void* context) { @@ -811,10 +817,9 @@ int32_t sd_filesystem(void* p) { furi_check( osMessageQueuePut(sd_app->result_receiver, &retval, 0, osWaitForever) == osOK); - app_reset_state(sd_app); + break; } if(try_to_alloc_view_holder(sd_app, gui)) { - sd_app->result_receiver = event.result_receiver; FileSelect* file_select = alloc_and_attach_file_select(sd_app); file_select_set_api(file_select, fs_api); file_select_set_filter( @@ -838,11 +843,28 @@ int32_t sd_filesystem(void* p) { } else { SdAppFileSelectResultEvent retval = {.result = false}; furi_check( - osMessageQueuePut(event.result_receiver, &retval, 0, osWaitForever) == + osMessageQueuePut(sd_app->result_receiver, &retval, 0, osWaitForever) == osOK); } break; case SdAppEventTypeCheckError: + if(sd_app->info.status != SD_OK) { + if(try_to_alloc_view_holder(sd_app, gui)) { + DialogEx* dialog = alloc_and_attach_dialog(sd_app); + dialog_ex_set_left_button_text(dialog, "Back"); + if(sd_app->info.status == SD_NO_CARD) { + dialog_ex_set_text( + dialog, "SD card\nnot found", 64, y_1_line, AlignLeft, AlignCenter); + dialog_ex_set_icon(dialog, 5, 6, I_SDQuestion_35x43); + } else { + dialog_ex_set_text( + dialog, "SD card\nerror", 64, y_1_line, AlignLeft, AlignCenter); + dialog_ex_set_icon(dialog, 5, 10, I_SDError_43x35); + } + sd_app->sd_app_state = SdAppStateCheckError; + view_holder_start(sd_app->view_holder); + } + } break; } } diff --git a/applications/sd-filesystem/sd-filesystem.h b/applications/sd-filesystem/sd-filesystem.h index 11b56fe7..15ff89bd 100644 --- a/applications/sd-filesystem/sd-filesystem.h +++ b/applications/sd-filesystem/sd-filesystem.h @@ -89,6 +89,7 @@ typedef enum { SdAppStateEject, SdAppStateEjected, SdAppStateFileSelect, + SdAppStateCheckError, } SdAppState; struct SdApp { diff --git a/lib/common-api/sd-card-api.h b/lib/common-api/sd-card-api.h index ed0ba521..61589088 100644 --- a/lib/common-api/sd-card-api.h +++ b/lib/common-api/sd-card-api.h @@ -15,6 +15,7 @@ typedef struct { const char* extension, char* result, uint8_t result_size); + void (*check_error)(SdApp* context); } SdCard_Api; #ifdef __cplusplus