[FL-1307] iButton key files: ASCII encoding and .ibtn extension (#493)
* GUI module submenu: fix documentation * GUI module submenu: add submenu_set_selected_item fn * App iButton: use submenu_set_selected_item to store and set selected item in submenu * App iButton: swap write and emulate in "saved key menu" scene * App iButton: file select can now switch to the previous selected file * App iButton: swap write and emulate indexes in "saved key menu" scene * Gui module file_select: work with separate extension * iButton app: separate file managment, file error handling * SD card api: custom error message * iButton app: better file error handling Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -268,7 +268,7 @@ uint16_t fs_file_read(File* file, void* buff, uint16_t const bytes_to_read) {
|
||||
}
|
||||
|
||||
// Write data to the file
|
||||
uint16_t fs_file_write(File* file, void* buff, uint16_t const bytes_to_write) {
|
||||
uint16_t fs_file_write(File* file, const void* buff, uint16_t const bytes_to_write) {
|
||||
FileData* filedata = NULL;
|
||||
uint16_t bytes_written = 0;
|
||||
|
||||
|
@@ -34,6 +34,7 @@ typedef enum {
|
||||
SdAppEventTypeEject,
|
||||
SdAppEventTypeFileSelect,
|
||||
SdAppEventTypeCheckError,
|
||||
SdAppEventTypeShowError,
|
||||
} SdAppEventType;
|
||||
|
||||
typedef struct {
|
||||
@@ -52,6 +53,7 @@ typedef struct {
|
||||
SdAppEventType type;
|
||||
union {
|
||||
SdAppFileSelectData file_select_data;
|
||||
const char* error_text;
|
||||
} payload;
|
||||
} SdAppEvent;
|
||||
|
||||
@@ -64,6 +66,7 @@ bool sd_api_file_select(
|
||||
uint8_t result_size,
|
||||
char* selected_filename);
|
||||
void sd_api_check_error(SdApp* sd_app);
|
||||
void sd_api_show_error(SdApp* sd_app, const char* error_text);
|
||||
|
||||
/******************* Allocators *******************/
|
||||
|
||||
@@ -125,6 +128,8 @@ SdApp* sd_app_alloc() {
|
||||
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_card_api.show_error = sd_api_show_error;
|
||||
|
||||
sd_app->sd_app_state = SdAppStateBackground;
|
||||
string_init(sd_app->text_holder);
|
||||
|
||||
@@ -455,6 +460,7 @@ bool sd_api_file_select(
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!retval) {
|
||||
sd_api_check_error(sd_app);
|
||||
}
|
||||
@@ -467,6 +473,11 @@ void sd_api_check_error(SdApp* sd_app) {
|
||||
furi_check(osMessageQueuePut(sd_app->event_queue, &message, 0, osWaitForever) == osOK);
|
||||
}
|
||||
|
||||
void sd_api_show_error(SdApp* sd_app, const char* error_text) {
|
||||
SdAppEvent message = {.type = SdAppEventTypeShowError, .payload.error_text = error_text};
|
||||
furi_check(osMessageQueuePut(sd_app->event_queue, &message, 0, osWaitForever) == osOK);
|
||||
}
|
||||
|
||||
/******************* View callbacks *******************/
|
||||
|
||||
void app_view_back_callback(void* context) {
|
||||
@@ -904,11 +915,16 @@ int32_t sd_filesystem(void* p) {
|
||||
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,
|
||||
"SD card\nnot found",
|
||||
88,
|
||||
y_1_line,
|
||||
AlignCenter,
|
||||
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, "SD card\nerror", 88, y_1_line, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_icon(dialog, 5, 10, I_SDError_43x35);
|
||||
}
|
||||
sd_app->sd_app_state = SdAppStateCheckError;
|
||||
@@ -916,6 +932,17 @@ int32_t sd_filesystem(void* p) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SdAppEventTypeShowError:
|
||||
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");
|
||||
dialog_ex_set_text(
|
||||
dialog, event.payload.error_text, 88, y_1_line, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_icon(dialog, 5, 6, I_SDQuestion_35x43);
|
||||
sd_app->sd_app_state = SdAppStateShowError;
|
||||
view_holder_start(sd_app->view_holder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -87,6 +87,7 @@ typedef enum {
|
||||
SdAppStateEjected,
|
||||
SdAppStateFileSelect,
|
||||
SdAppStateCheckError,
|
||||
SdAppStateShowError,
|
||||
} SdAppState;
|
||||
|
||||
struct SdApp {
|
||||
@@ -115,7 +116,7 @@ SDError _fs_status(SdFsInfo* fs_info);
|
||||
bool fs_file_open(File* file, const char* path, FS_AccessMode access_mode, FS_OpenMode open_mode);
|
||||
bool fs_file_close(File* file);
|
||||
uint16_t fs_file_read(File* file, void* buff, uint16_t bytes_to_read);
|
||||
uint16_t fs_file_write(File* file, void* buff, uint16_t bytes_to_write);
|
||||
uint16_t fs_file_write(File* file, const void* buff, uint16_t bytes_to_write);
|
||||
bool fs_file_seek(File* file, uint32_t offset, bool from_start);
|
||||
uint64_t fs_file_tell(File* file);
|
||||
bool fs_file_truncate(File* file);
|
||||
|
Reference in New Issue
Block a user