 7afdd14a4c
			
		
	
	
		7afdd14a4c
		
			
		
	
	
	
	
		
			
			* Gui: ported submenu and view_dispatcher_remove_view from iButton branch * App gui-test: use backported submenu api * App subghz: initial commit * App subghz: syntax fix * App gui-test: fix submenu callback * App subghz: add subfolders to build * Gui view: c++ verison of with_view_model * Subghz app: simple spectrum settings view * Subghz app: add spectrum settings view to view manager * Subghz app: spectrum settings scene Co-authored-by: coreglitch <mail@s3f.ru>
		
			
				
	
	
		
			90 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "subghz-app.h"
 | |
| #include <api-hal-power.h>
 | |
| #include <stdarg.h>
 | |
| 
 | |
| void SubghzApp::run(void) {
 | |
|     SubghzEvent event;
 | |
|     bool consumed;
 | |
|     bool exit = false;
 | |
| 
 | |
|     scenes[current_scene]->on_enter(this);
 | |
| 
 | |
|     while(!exit) {
 | |
|         view.receive_event(&event);
 | |
| 
 | |
|         consumed = scenes[current_scene]->on_event(this, &event);
 | |
| 
 | |
|         if(!consumed) {
 | |
|             if(event.type == SubghzEvent::Type::Back) {
 | |
|                 exit = switch_to_previous_scene();
 | |
|             }
 | |
|         }
 | |
|     };
 | |
| 
 | |
|     scenes[current_scene]->on_exit(this);
 | |
| }
 | |
| 
 | |
| SubghzApp::SubghzApp() {
 | |
|     api_hal_power_insomnia_enter();
 | |
| }
 | |
| 
 | |
| SubghzApp::~SubghzApp() {
 | |
|     api_hal_power_insomnia_exit();
 | |
| }
 | |
| 
 | |
| SubghzAppViewManager* SubghzApp::get_view_manager() {
 | |
|     return &view;
 | |
| }
 | |
| 
 | |
| void SubghzApp::switch_to_next_scene(Scene next_scene) {
 | |
|     previous_scenes_list.push_front(current_scene);
 | |
| 
 | |
|     if(next_scene != Scene::SceneExit) {
 | |
|         scenes[current_scene]->on_exit(this);
 | |
|         current_scene = next_scene;
 | |
|         scenes[current_scene]->on_enter(this);
 | |
|     }
 | |
| }
 | |
| 
 | |
| void SubghzApp::search_and_switch_to_previous_scene(std::initializer_list<Scene> scenes_list) {
 | |
|     Scene previous_scene = Scene::SceneStart;
 | |
|     bool scene_found = false;
 | |
| 
 | |
|     while(!scene_found) {
 | |
|         previous_scene = get_previous_scene();
 | |
|         for(Scene element : scenes_list) {
 | |
|             if(previous_scene == element || previous_scene == Scene::SceneStart) {
 | |
|                 scene_found = true;
 | |
|                 break;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     scenes[current_scene]->on_exit(this);
 | |
|     current_scene = previous_scene;
 | |
|     scenes[current_scene]->on_enter(this);
 | |
| }
 | |
| 
 | |
| bool SubghzApp::switch_to_previous_scene(uint8_t count) {
 | |
|     Scene previous_scene = Scene::SceneStart;
 | |
| 
 | |
|     for(uint8_t i = 0; i < count; i++) {
 | |
|         previous_scene = get_previous_scene();
 | |
|         if(previous_scene == Scene::SceneExit) break;
 | |
|     }
 | |
| 
 | |
|     if(previous_scene == Scene::SceneExit) {
 | |
|         return true;
 | |
|     } else {
 | |
|         scenes[current_scene]->on_exit(this);
 | |
|         current_scene = previous_scene;
 | |
|         scenes[current_scene]->on_enter(this);
 | |
|         return false;
 | |
|     }
 | |
| }
 | |
| 
 | |
| SubghzApp::Scene SubghzApp::get_previous_scene() {
 | |
|     Scene scene = previous_scenes_list.front();
 | |
|     previous_scenes_list.pop_front();
 | |
|     return scene;
 | |
| } |