[FL-1108] iButton fix navigation (#404)
* file_select: process zero file counter * file_select: process file select view for less than 4 files * ibutton: change application navigation * ibutton: add read new key submenu * file_select: use standart MIN() function * sd-filesystem: remove unused min() define
This commit is contained in:
		
							parent
							
								
									8ce5af1be2
								
							
						
					
					
						commit
						2fe44e1b11
					
				| @ -1,6 +1,7 @@ | ||||
| #include "file_select.h" | ||||
| #include <gui/elements.h> | ||||
| #include <m-string.h> | ||||
| #include <sys/param.h> | ||||
| 
 | ||||
| #define FILENAME_COUNT 4 | ||||
| 
 | ||||
| @ -42,7 +43,8 @@ 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(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); | ||||
| @ -57,9 +59,14 @@ static void file_select_draw_callback(Canvas* canvas, void* _model) { | ||||
|             } | ||||
| 
 | ||||
|             canvas_draw_str( | ||||
|             canvas, 6, (i * item_height) + item_height - 4, string_get_cstr(model->filename[i])); | ||||
|                 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; | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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); | ||||
|  | ||||
| @ -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; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 gornekich
						gornekich