#include "subghz-app.h" #include #include 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 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; }