diff --git a/applications/gui/modules/file_select.c b/applications/gui/modules/file_select.c index 1b565297..2c289457 100644 --- a/applications/gui/modules/file_select.c +++ b/applications/gui/modules/file_select.c @@ -1,6 +1,7 @@ #include "file_select.h" #include #include +#include #define FILENAME_COUNT 4 @@ -42,24 +43,30 @@ static void file_select_draw_callback(Canvas* canvas, void* _model) { canvas_clear(canvas); canvas_set_font(canvas, FontSecondary); - for(uint8_t i = 0; i < FILENAME_COUNT; i++) { - if(i == model->position) { - canvas_set_color(canvas, ColorBlack); - canvas_draw_box(canvas, 0, (i * item_height) + 1, item_width, item_height - 2); + if(model->file_count) { + for(uint8_t i = 0; i < MIN(FILENAME_COUNT, model->file_count); i++) { + if(i == model->position) { + canvas_set_color(canvas, ColorBlack); + canvas_draw_box(canvas, 0, (i * item_height) + 1, item_width, item_height - 2); - canvas_set_color(canvas, ColorWhite); - canvas_draw_dot(canvas, 0, (i * item_height) + 1); - canvas_draw_dot(canvas, 0, (i * item_height) + item_height - 2); - canvas_draw_dot(canvas, item_width - 1, (i * item_height) + 1); - canvas_draw_dot(canvas, item_width - 1, (i * item_height) + item_height - 2); - } else { - canvas_set_color(canvas, ColorBlack); + canvas_set_color(canvas, ColorWhite); + canvas_draw_dot(canvas, 0, (i * item_height) + 1); + canvas_draw_dot(canvas, 0, (i * item_height) + item_height - 2); + canvas_draw_dot(canvas, item_width - 1, (i * item_height) + 1); + canvas_draw_dot(canvas, item_width - 1, (i * item_height) + item_height - 2); + } else { + canvas_set_color(canvas, ColorBlack); + } + + canvas_draw_str( + canvas, + 6, + (i * item_height) + item_height - 4, + string_get_cstr(model->filename[i])); } - - canvas_draw_str( - canvas, 6, (i * item_height) + item_height - 4, string_get_cstr(model->filename[i])); + } else { + canvas_draw_str(canvas, 6, item_height, "Empty folder"); } - elements_scrollbar(canvas, model->first_file_index + model->position, model->file_count); } @@ -78,9 +85,10 @@ static bool file_select_input_callback(InputEvent* event, void* context) { if(model->position == 0) { if(model->first_file_index == 0) { // wrap - uint16_t max_first_file_index = model->file_count - FILENAME_COUNT; - model->position = FILENAME_COUNT - 1; - model->first_file_index = max_first_file_index; + int16_t max_first_file_index = model->file_count - FILENAME_COUNT; + model->position = MIN(FILENAME_COUNT - 1, model->file_count - 1); + model->first_file_index = + max_first_file_index < 0 ? 0 : max_first_file_index; } else { model->first_file_index--; } @@ -102,9 +110,11 @@ static bool file_select_input_callback(InputEvent* event, void* context) { } else if(event->key == InputKeyDown) { with_view_model( file_select->view, (FileSelectModel * model) { - uint16_t max_first_file_index = model->file_count - FILENAME_COUNT; + uint16_t max_first_file_index = model->file_count > FILENAME_COUNT ? + model->file_count - FILENAME_COUNT : + 0; - if(model->position >= (FILENAME_COUNT - 1)) { + if(model->position >= MIN(FILENAME_COUNT - 1, model->file_count - 1)) { if(model->first_file_index >= max_first_file_index) { // wrap model->position = 0; diff --git a/applications/ibutton/scene/ibutton-scene-read-crc-error.cpp b/applications/ibutton/scene/ibutton-scene-read-crc-error.cpp index 3a4796e1..00d03845 100644 --- a/applications/ibutton/scene/ibutton-scene-read-crc-error.cpp +++ b/applications/ibutton/scene/ibutton-scene-read-crc-error.cpp @@ -26,7 +26,7 @@ void iButtonSceneReadCRCError::on_enter(iButtonApp* app) { dialog_ex_set_header(dialog_ex, "CRC ERROR", 64, 10, AlignCenter, AlignCenter); dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop); - dialog_ex_set_left_button_text(dialog_ex, "Back"); + dialog_ex_set_left_button_text(dialog_ex, "Retry"); dialog_ex_set_right_button_text(dialog_ex, "More"); dialog_ex_set_result_callback(dialog_ex, callback); dialog_ex_set_context(dialog_ex, app); diff --git a/applications/ibutton/scene/ibutton-scene-read-not-key-error.cpp b/applications/ibutton/scene/ibutton-scene-read-not-key-error.cpp index aa175baa..8cd3cd00 100644 --- a/applications/ibutton/scene/ibutton-scene-read-not-key-error.cpp +++ b/applications/ibutton/scene/ibutton-scene-read-not-key-error.cpp @@ -26,7 +26,7 @@ void iButtonSceneReadNotKeyError::on_enter(iButtonApp* app) { dialog_ex_set_header(dialog_ex, "ERROR:", 64, 10, AlignCenter, AlignCenter); dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop); - dialog_ex_set_left_button_text(dialog_ex, "Back"); + dialog_ex_set_left_button_text(dialog_ex, "Retry"); dialog_ex_set_right_button_text(dialog_ex, "More"); dialog_ex_set_result_callback(dialog_ex, callback); dialog_ex_set_context(dialog_ex, app); diff --git a/applications/ibutton/scene/ibutton-scene-read-success.cpp b/applications/ibutton/scene/ibutton-scene-read-success.cpp index 4ae0a24c..28b38e61 100644 --- a/applications/ibutton/scene/ibutton-scene-read-success.cpp +++ b/applications/ibutton/scene/ibutton-scene-read-success.cpp @@ -15,7 +15,7 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) { switch(key->get_key_type()) { case iButtonKeyType::KeyDallas: app->set_text_store( - "%02X %02X %02X %02X\n%02X %02X %02X %02X\nDallas", + "Dallas\n%02X %02X %02X %02X\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], @@ -26,16 +26,16 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) { key_data[7]); break; case iButtonKeyType::KeyCyfral: - app->set_text_store("%02X %02X\nCyfral", key_data[0], key_data[1]); + app->set_text_store("Cyfral\n%02X %02X", key_data[0], key_data[1]); break; case iButtonKeyType::KeyMetakom: app->set_text_store( - "%02X %02X %02X %02X\nMetakom", key_data[0], key_data[1], key_data[2], key_data[3]); + "Metakom\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]); break; } dialog_ex_set_text(dialog_ex, app->get_text_store(), 95, 30, AlignCenter, AlignCenter); - dialog_ex_set_left_button_text(dialog_ex, "Back"); + dialog_ex_set_left_button_text(dialog_ex, "Retry"); dialog_ex_set_right_button_text(dialog_ex, "More"); dialog_ex_set_icon(dialog_ex, 0, 1, I_DolphinExcited_64x63); dialog_ex_set_result_callback(dialog_ex, callback); diff --git a/applications/ibutton/scene/ibutton-scene-readed-key-menu.cpp b/applications/ibutton/scene/ibutton-scene-readed-key-menu.cpp index c6e1b921..8a562be9 100644 --- a/applications/ibutton/scene/ibutton-scene-readed-key-menu.cpp +++ b/applications/ibutton/scene/ibutton-scene-readed-key-menu.cpp @@ -8,6 +8,7 @@ typedef enum { SubmenuIndexWrite, SubmenuIndexEmulate, SubmenuIndexNameAndSave, + SubmenuIndexReadNewKey, } SubmenuIndex; void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) { @@ -18,6 +19,7 @@ void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) { submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app); submenu_add_item(submenu, "Name and save", SubmenuIndexNameAndSave, callback, app); submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app); + submenu_add_item(submenu, "Read new key", SubmenuIndexReadNewKey, callback, app); view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu); } @@ -36,10 +38,13 @@ bool iButtonSceneReadedKeyMenu::on_event(iButtonApp* app, iButtonEvent* event) { case SubmenuIndexNameAndSave: app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName); break; + case SubmenuIndexReadNewKey: + app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneRead}); + break; } consumed = true; } else if(event->type == iButtonEvent::Type::EventTypeBack) { - app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneRead}); + app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneStart}); consumed = true; } diff --git a/applications/ibutton/scene/ibutton-scene-save-name.cpp b/applications/ibutton/scene/ibutton-scene-save-name.cpp index f7bbe4ed..61b3c931 100644 --- a/applications/ibutton/scene/ibutton-scene-save-name.cpp +++ b/applications/ibutton/scene/ibutton-scene-save-name.cpp @@ -48,7 +48,10 @@ bool iButtonSceneSaveName::on_event(iButtonApp* app, iButtonEvent* event) { 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); + app->search_and_switch_to_previous_scene( + {iButtonApp::Scene::SceneReadedKeyMenu, + iButtonApp::Scene::SceneSavedKeyMenu, + iButtonApp::Scene::SceneAddType}); } string_clear(key_file_name); consumed = true; diff --git a/applications/sd-filesystem/sd-filesystem.h b/applications/sd-filesystem/sd-filesystem.h index 15ff89bd..46d4e3c7 100644 --- a/applications/sd-filesystem/sd-filesystem.h +++ b/applications/sd-filesystem/sd-filesystem.h @@ -11,10 +11,6 @@ #define SD_FS_MAX_FILES _FS_LOCK #define SD_STATE_LINES_COUNT 6 -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#endif - /* api data */ typedef FIL SDFile; typedef DIR SDDir;