[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:
		
							parent
							
								
									5cd73ac97b
								
							
						
					
					
						commit
						8ce5af1be2
					
				@ -41,12 +41,16 @@ bool iButtonSceneSaveName::on_event(iButtonApp* app, iButtonEvent* event) {
 | 
				
			|||||||
        app->get_fs_api()->common.mkdir("ibutton");
 | 
					        app->get_fs_api()->common.mkdir("ibutton");
 | 
				
			||||||
        bool res = app->get_fs_api()->file.open(
 | 
					        bool res = app->get_fs_api()->file.open(
 | 
				
			||||||
            &key_file, string_get_cstr(key_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS);
 | 
					            &key_file, string_get_cstr(key_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS);
 | 
				
			||||||
 | 
					        // TODO process file system errors from file system service
 | 
				
			||||||
        if(res) {
 | 
					        if(res) {
 | 
				
			||||||
            res = app->get_fs_api()->file.write(&key_file, key_data, IBUTTON_KEY_SIZE + 1);
 | 
					            res = app->get_fs_api()->file.write(&key_file, key_data, IBUTTON_KEY_SIZE + 1);
 | 
				
			||||||
            res = app->get_fs_api()->file.close(&key_file);
 | 
					            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);
 | 
					        string_clear(key_file_name);
 | 
				
			||||||
        app->switch_to_next_scene(iButtonApp::Scene::SceneSaveSuccess);
 | 
					 | 
				
			||||||
        consumed = true;
 | 
					        consumed = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -49,7 +49,6 @@ typedef struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
    SdAppEventType type;
 | 
					    SdAppEventType type;
 | 
				
			||||||
    osMessageQueueId_t result_receiver;
 | 
					 | 
				
			||||||
    union {
 | 
					    union {
 | 
				
			||||||
        SdAppFileSelectData file_select_data;
 | 
					        SdAppFileSelectData file_select_data;
 | 
				
			||||||
    } payload;
 | 
					    } payload;
 | 
				
			||||||
@ -62,6 +61,7 @@ bool sd_api_file_select(
 | 
				
			|||||||
    const char* extension,
 | 
					    const char* extension,
 | 
				
			||||||
    char* result,
 | 
					    char* result,
 | 
				
			||||||
    uint8_t result_size);
 | 
					    uint8_t result_size);
 | 
				
			||||||
 | 
					void sd_api_check_error(SdApp* sd_app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/******************* Allocators *******************/
 | 
					/******************* Allocators *******************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -109,6 +109,7 @@ SdApp* sd_app_alloc() {
 | 
				
			|||||||
    furi_check(_fs_init(&sd_app->info));
 | 
					    furi_check(_fs_init(&sd_app->info));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sd_app->event_queue = osMessageQueueNew(8, sizeof(SdAppEvent), NULL);
 | 
					    sd_app->event_queue = osMessageQueueNew(8, sizeof(SdAppEvent), NULL);
 | 
				
			||||||
 | 
					    sd_app->result_receiver = osMessageQueueNew(1, sizeof(SdAppFileSelectResultEvent), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // init icon view_port
 | 
					    // init icon view_port
 | 
				
			||||||
    sd_app->icon.view_port = view_port_alloc();
 | 
					    sd_app->icon.view_port = view_port_alloc();
 | 
				
			||||||
@ -121,6 +122,7 @@ SdApp* sd_app_alloc() {
 | 
				
			|||||||
    // init sd card api
 | 
					    // init sd card api
 | 
				
			||||||
    sd_app->sd_card_api.context = sd_app;
 | 
					    sd_app->sd_card_api.context = sd_app;
 | 
				
			||||||
    sd_app->sd_card_api.file_select = sd_api_file_select;
 | 
					    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;
 | 
					    sd_app->sd_app_state = SdAppStateBackground;
 | 
				
			||||||
    string_init(sd_app->text_holder);
 | 
					    string_init(sd_app->text_holder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -383,12 +385,8 @@ bool sd_api_file_select(
 | 
				
			|||||||
    uint8_t result_size) {
 | 
					    uint8_t result_size) {
 | 
				
			||||||
    bool retval = false;
 | 
					    bool retval = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    osMessageQueueId_t return_event_queue =
 | 
					 | 
				
			||||||
        osMessageQueueNew(1, sizeof(SdAppFileSelectResultEvent), NULL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    SdAppEvent message = {
 | 
					    SdAppEvent message = {
 | 
				
			||||||
        .type = SdAppEventTypeFileSelect,
 | 
					        .type = SdAppEventTypeFileSelect,
 | 
				
			||||||
        .result_receiver = return_event_queue,
 | 
					 | 
				
			||||||
        .payload = {
 | 
					        .payload = {
 | 
				
			||||||
            .file_select_data = {
 | 
					            .file_select_data = {
 | 
				
			||||||
                .path = path,
 | 
					                .path = path,
 | 
				
			||||||
@ -401,16 +399,24 @@ bool sd_api_file_select(
 | 
				
			|||||||
    SdAppFileSelectResultEvent event;
 | 
					    SdAppFileSelectResultEvent event;
 | 
				
			||||||
    while(1) {
 | 
					    while(1) {
 | 
				
			||||||
        osStatus_t event_status =
 | 
					        osStatus_t event_status =
 | 
				
			||||||
            osMessageQueueGet(return_event_queue, &event, NULL, osWaitForever);
 | 
					            osMessageQueueGet(sd_app->result_receiver, &event, NULL, osWaitForever);
 | 
				
			||||||
        if(event_status == osOK) {
 | 
					        if(event_status == osOK) {
 | 
				
			||||||
            retval = event.result;
 | 
					            retval = event.result;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if(!retval) {
 | 
				
			||||||
 | 
					        sd_api_check_error(sd_app);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return retval;
 | 
					    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 *******************/
 | 
					/******************* View callbacks *******************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void app_view_back_callback(void* context) {
 | 
					void app_view_back_callback(void* context) {
 | 
				
			||||||
@ -811,10 +817,9 @@ int32_t sd_filesystem(void* p) {
 | 
				
			|||||||
                    furi_check(
 | 
					                    furi_check(
 | 
				
			||||||
                        osMessageQueuePut(sd_app->result_receiver, &retval, 0, osWaitForever) ==
 | 
					                        osMessageQueuePut(sd_app->result_receiver, &retval, 0, osWaitForever) ==
 | 
				
			||||||
                        osOK);
 | 
					                        osOK);
 | 
				
			||||||
                    app_reset_state(sd_app);
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if(try_to_alloc_view_holder(sd_app, gui)) {
 | 
					                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);
 | 
					                    FileSelect* file_select = alloc_and_attach_file_select(sd_app);
 | 
				
			||||||
                    file_select_set_api(file_select, fs_api);
 | 
					                    file_select_set_api(file_select, fs_api);
 | 
				
			||||||
                    file_select_set_filter(
 | 
					                    file_select_set_filter(
 | 
				
			||||||
@ -838,11 +843,28 @@ int32_t sd_filesystem(void* p) {
 | 
				
			|||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    SdAppFileSelectResultEvent retval = {.result = false};
 | 
					                    SdAppFileSelectResultEvent retval = {.result = false};
 | 
				
			||||||
                    furi_check(
 | 
					                    furi_check(
 | 
				
			||||||
                        osMessageQueuePut(event.result_receiver, &retval, 0, osWaitForever) ==
 | 
					                        osMessageQueuePut(sd_app->result_receiver, &retval, 0, osWaitForever) ==
 | 
				
			||||||
                        osOK);
 | 
					                        osOK);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case SdAppEventTypeCheckError:
 | 
					            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;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -89,6 +89,7 @@ typedef enum {
 | 
				
			|||||||
    SdAppStateEject,
 | 
					    SdAppStateEject,
 | 
				
			||||||
    SdAppStateEjected,
 | 
					    SdAppStateEjected,
 | 
				
			||||||
    SdAppStateFileSelect,
 | 
					    SdAppStateFileSelect,
 | 
				
			||||||
 | 
					    SdAppStateCheckError,
 | 
				
			||||||
} SdAppState;
 | 
					} SdAppState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct SdApp {
 | 
					struct SdApp {
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,7 @@ typedef struct {
 | 
				
			|||||||
        const char* extension,
 | 
					        const char* extension,
 | 
				
			||||||
        char* result,
 | 
					        char* result,
 | 
				
			||||||
        uint8_t result_size);
 | 
					        uint8_t result_size);
 | 
				
			||||||
 | 
					    void (*check_error)(SdApp* context);
 | 
				
			||||||
} SdCard_Api;
 | 
					} SdCard_Api;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user