[FL-1299] iButton fix previous scene transition #480
This commit is contained in:
		
							parent
							
								
									6d93f04f13
								
							
						
					
					
						commit
						89d1b0546e
					
				| @ -22,6 +22,7 @@ | |||||||
| #include "scene/ibutton-scene-save-name.h" | #include "scene/ibutton-scene-save-name.h" | ||||||
| #include "scene/ibutton-scene-save-success.h" | #include "scene/ibutton-scene-save-success.h" | ||||||
| #include "scene/ibutton-scene-info.h" | #include "scene/ibutton-scene-info.h" | ||||||
|  | #include "scene/ibutton-scene-select-key.h" | ||||||
| #include "scene/ibutton-scene-add-type.h" | #include "scene/ibutton-scene-add-type.h" | ||||||
| #include "scene/ibutton-scene-add-value.h" | #include "scene/ibutton-scene-add-value.h" | ||||||
| 
 | 
 | ||||||
| @ -62,6 +63,7 @@ public: | |||||||
|         SceneSaveName, |         SceneSaveName, | ||||||
|         SceneSaveSuccess, |         SceneSaveSuccess, | ||||||
|         SceneInfo, |         SceneInfo, | ||||||
|  |         SceneSelectKey, | ||||||
|         SceneAddType, |         SceneAddType, | ||||||
|         SceneAddValue, |         SceneAddValue, | ||||||
|     }; |     }; | ||||||
| @ -140,6 +142,7 @@ private: | |||||||
|         {Scene::SceneSaveName, new iButtonSceneSaveName()}, |         {Scene::SceneSaveName, new iButtonSceneSaveName()}, | ||||||
|         {Scene::SceneSaveSuccess, new iButtonSceneSaveSuccess()}, |         {Scene::SceneSaveSuccess, new iButtonSceneSaveSuccess()}, | ||||||
|         {Scene::SceneInfo, new iButtonSceneInfo()}, |         {Scene::SceneInfo, new iButtonSceneInfo()}, | ||||||
|  |         {Scene::SceneSelectKey, new iButtonSceneSelectKey()}, | ||||||
|         {Scene::SceneAddType, new iButtonSceneAddType()}, |         {Scene::SceneAddType, new iButtonSceneAddType()}, | ||||||
|         {Scene::SceneAddValue, new iButtonSceneAddValue()}, |         {Scene::SceneAddValue, new iButtonSceneAddValue()}, | ||||||
|     }; |     }; | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ bool iButtonSceneDeleteSuccess::on_event(iButtonApp* app, iButtonEvent* event) { | |||||||
|     bool consumed = false; |     bool consumed = false; | ||||||
| 
 | 
 | ||||||
|     if(event->type == iButtonEvent::Type::EventTypeBack) { |     if(event->type == iButtonEvent::Type::EventTypeBack) { | ||||||
|         app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneStart}); |         app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneSelectKey}); | ||||||
|         consumed = true; |         consumed = true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								applications/ibutton/scene/ibutton-scene-select-key.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								applications/ibutton/scene/ibutton-scene-select-key.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | #include "ibutton-scene-select-key.h" | ||||||
|  | #include "../ibutton-app.h" | ||||||
|  | #include "../ibutton-event.h" | ||||||
|  | #include "../ibutton-key.h" | ||||||
|  | 
 | ||||||
|  | void iButtonSceneSelectKey::on_enter(iButtonApp* app) { | ||||||
|  |     // Input events and views are managed by file_select
 | ||||||
|  |     bool res = app->get_sd_ex_api()->file_select( | ||||||
|  |         app->get_sd_ex_api()->context, | ||||||
|  |         "ibutton", | ||||||
|  |         "*", | ||||||
|  |         app->get_file_name(), | ||||||
|  |         app->get_file_name_size()); | ||||||
|  | 
 | ||||||
|  |     // Process file_select return
 | ||||||
|  |     if(res) { | ||||||
|  |         // Get key file path
 | ||||||
|  |         string_t key_str; | ||||||
|  |         string_init_set_str(key_str, "ibutton/"); | ||||||
|  |         string_cat_str(key_str, app->get_file_name()); | ||||||
|  | 
 | ||||||
|  |         // Read data from file
 | ||||||
|  |         File key_file; | ||||||
|  |         uint8_t key_data[IBUTTON_KEY_DATA_SIZE + 1] = {}; | ||||||
|  |         // TODO process false result from file system service
 | ||||||
|  |         app->get_fs_api()->file.open( | ||||||
|  |             &key_file, string_get_cstr(key_str), FSAM_READ, FSOM_OPEN_EXISTING); | ||||||
|  |         app->get_fs_api()->file.read(&key_file, key_data, IBUTTON_KEY_DATA_SIZE + 1); | ||||||
|  |         app->get_fs_api()->file.close(&key_file); | ||||||
|  |         string_clear(key_str); | ||||||
|  | 
 | ||||||
|  |         // Set key data
 | ||||||
|  |         iButtonKeyType key_type = static_cast<iButtonKeyType>(key_data[0]); | ||||||
|  |         if(key_type > iButtonKeyType::KeyMetakom) { | ||||||
|  |             app->switch_to_next_scene(iButtonApp::Scene::SceneStart); | ||||||
|  |         } | ||||||
|  |         app->get_key()->set_name(app->get_file_name()); | ||||||
|  |         app->get_key()->set_type(key_type); | ||||||
|  |         app->get_key()->set_data(key_data + 1, IBUTTON_KEY_DATA_SIZE); | ||||||
|  |         app->switch_to_next_scene(iButtonApp::Scene::SceneSavedKeyMenu); | ||||||
|  |     } else { | ||||||
|  |         app->switch_to_previous_scene(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool iButtonSceneSelectKey::on_event(iButtonApp* app, iButtonEvent* event) { | ||||||
|  |     return false; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void iButtonSceneSelectKey::on_exit(iButtonApp* app) { | ||||||
|  | } | ||||||
							
								
								
									
										9
									
								
								applications/ibutton/scene/ibutton-scene-select-key.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								applications/ibutton/scene/ibutton-scene-select-key.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | #pragma once | ||||||
|  | #include "ibutton-scene-generic.h" | ||||||
|  | 
 | ||||||
|  | class iButtonSceneSelectKey : public iButtonScene { | ||||||
|  | public: | ||||||
|  |     void on_enter(iButtonApp* app) final; | ||||||
|  |     bool on_event(iButtonApp* app, iButtonEvent* event) final; | ||||||
|  |     void on_exit(iButtonApp* app) final; | ||||||
|  | }; | ||||||
| @ -31,40 +31,9 @@ bool iButtonSceneStart::on_event(iButtonApp* app, iButtonEvent* event) { | |||||||
|         case SubmenuIndexRead: |         case SubmenuIndexRead: | ||||||
|             app->switch_to_next_scene(iButtonApp::Scene::SceneRead); |             app->switch_to_next_scene(iButtonApp::Scene::SceneRead); | ||||||
|             break; |             break; | ||||||
|         case SubmenuIndexSaved: { |         case SubmenuIndexSaved: | ||||||
|             bool res = app->get_sd_ex_api()->file_select( |             app->switch_to_next_scene(iButtonApp::Scene::SceneSelectKey); | ||||||
|                 app->get_sd_ex_api()->context, |             break; | ||||||
|                 "ibutton", |  | ||||||
|                 "*", |  | ||||||
|                 app->get_file_name(), |  | ||||||
|                 app->get_file_name_size()); |  | ||||||
|             if(res) { |  | ||||||
|                 string_t key_str; |  | ||||||
|                 string_init_set_str(key_str, "ibutton/"); |  | ||||||
|                 string_cat_str(key_str, app->get_file_name()); |  | ||||||
|                 File key_file; |  | ||||||
|                 uint8_t key_data[IBUTTON_KEY_DATA_SIZE + 1] = {}; |  | ||||||
|                 // Read data from file
 |  | ||||||
|                 // TODO handle false return
 |  | ||||||
|                 res = app->get_fs_api()->file.open( |  | ||||||
|                     &key_file, string_get_cstr(key_str), FSAM_READ, FSOM_OPEN_EXISTING); |  | ||||||
|                 res = app->get_fs_api()->file.read(&key_file, key_data, IBUTTON_KEY_DATA_SIZE + 1); |  | ||||||
|                 res = app->get_fs_api()->file.close(&key_file); |  | ||||||
|                 string_clear(key_str); |  | ||||||
|                 // Set key
 |  | ||||||
|                 iButtonKeyType key_type = static_cast<iButtonKeyType>(key_data[0]); |  | ||||||
|                 if(key_type > iButtonKeyType::KeyMetakom) { |  | ||||||
|                     app->switch_to_next_scene(iButtonApp::Scene::SceneStart); |  | ||||||
|                 } |  | ||||||
|                 app->get_key()->set_name(app->get_file_name()); |  | ||||||
|                 app->get_key()->set_type(key_type); |  | ||||||
|                 app->get_key()->set_data(key_data + 1, IBUTTON_KEY_DATA_SIZE); |  | ||||||
|                 app->switch_to_next_scene(iButtonApp::Scene::SceneSavedKeyMenu); |  | ||||||
|             } else { |  | ||||||
|                 // TODO add error scene
 |  | ||||||
|                 app->switch_to_next_scene(iButtonApp::Scene::SceneStart); |  | ||||||
|             } |  | ||||||
|         }; break; |  | ||||||
|         case SubmenuIndexAdd: |         case SubmenuIndexAdd: | ||||||
|             app->switch_to_next_scene(iButtonApp::Scene::SceneAddType); |             app->switch_to_next_scene(iButtonApp::Scene::SceneAddType); | ||||||
|             break; |             break; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 gornekich
						gornekich