[FL-1050] SD card error view (#399)

* 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: あく <alleteam@gmail.com>
This commit is contained in:
gornekich 2021-04-07 10:37:10 +03:00 committed by GitHub
parent 5cd73ac97b
commit 8ce5af1be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 10 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -89,6 +89,7 @@ typedef enum {
SdAppStateEject,
SdAppStateEjected,
SdAppStateFileSelect,
SdAppStateCheckError,
} SdAppState;
struct SdApp {

View File

@ -15,6 +15,7 @@ typedef struct {
const char* extension,
char* result,
uint8_t result_size);
void (*check_error)(SdApp* context);
} SdCard_Api;
#ifdef __cplusplus