irda-app.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "irda-app.hpp"
  2. #include <furi.h>
  3. #include <gui/gui.h>
  4. #include <input/input.h>
  5. #include <stdarg.h>
  6. #include <stdio.h>
  7. #include <callback-connector.h>
  8. void IrdaApp::run(void) {
  9. IrdaAppEvent event;
  10. bool consumed;
  11. bool exit = false;
  12. scenes[current_scene]->on_enter(this);
  13. while(!exit) {
  14. view_manager.receive_event(&event);
  15. consumed = scenes[current_scene]->on_event(this, &event);
  16. if(!consumed) {
  17. if(event.type == IrdaAppEvent::Type::Back) {
  18. exit = switch_to_previous_scene();
  19. }
  20. }
  21. };
  22. scenes[current_scene]->on_exit(this);
  23. };
  24. IrdaAppViewManager* IrdaApp::get_view_manager() {
  25. return &view_manager;
  26. }
  27. void IrdaApp::set_learn_new_remote(bool value) {
  28. learn_new_remote = value;
  29. }
  30. bool IrdaApp::get_learn_new_remote() {
  31. return learn_new_remote;
  32. }
  33. void IrdaApp::switch_to_next_scene(Scene next_scene) {
  34. previous_scenes_list.push_front(current_scene);
  35. switch_to_next_scene_without_saving(next_scene);
  36. }
  37. void IrdaApp::switch_to_next_scene_without_saving(Scene next_scene) {
  38. if(next_scene != Scene::Exit) {
  39. scenes[current_scene]->on_exit(this);
  40. current_scene = next_scene;
  41. scenes[current_scene]->on_enter(this);
  42. }
  43. }
  44. void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_list<Scene>& scenes_list) {
  45. Scene previous_scene = Scene::Start;
  46. bool scene_found = false;
  47. while(!scene_found) {
  48. previous_scene = get_previous_scene();
  49. for(Scene element : scenes_list) {
  50. if(previous_scene == element) {
  51. scene_found = true;
  52. break;
  53. }
  54. }
  55. }
  56. scenes[current_scene]->on_exit(this);
  57. current_scene = previous_scene;
  58. scenes[current_scene]->on_enter(this);
  59. }
  60. bool IrdaApp::switch_to_previous_scene(uint8_t count) {
  61. Scene previous_scene = Scene::Start;
  62. for(uint8_t i = 0; i < count; i++) previous_scene = get_previous_scene();
  63. if(previous_scene == Scene::Exit) return true;
  64. scenes[current_scene]->on_exit(this);
  65. current_scene = previous_scene;
  66. scenes[current_scene]->on_enter(this);
  67. return false;
  68. }
  69. IrdaApp::Scene IrdaApp::get_previous_scene() {
  70. Scene scene = Scene::Exit;
  71. if(!previous_scenes_list.empty()) {
  72. scene = previous_scenes_list.front();
  73. previous_scenes_list.pop_front();
  74. }
  75. return scene;
  76. }
  77. IrdaAppRemoteManager* IrdaApp::get_remote_manager() {
  78. return &remote_manager;
  79. }
  80. IrdaAppSignalReceiver* IrdaApp::get_receiver() {
  81. return &receiver;
  82. }
  83. void IrdaApp::set_text_store(uint8_t index, const char* text...) {
  84. furi_check(index < text_store_max);
  85. va_list args;
  86. va_start(args, text);
  87. vsnprintf(text_store[index], text_store_size, text, args);
  88. va_end(args);
  89. }
  90. char* IrdaApp::get_text_store(uint8_t index) {
  91. furi_check(index < text_store_max);
  92. return text_store[index];
  93. }
  94. uint8_t IrdaApp::get_text_store_size() {
  95. return text_store_size;
  96. }
  97. void IrdaApp::text_input_callback(void* context, char* text) {
  98. IrdaApp* app = static_cast<IrdaApp*>(context);
  99. IrdaAppEvent event;
  100. event.type = IrdaAppEvent::Type::TextEditDone;
  101. app->get_view_manager()->send_event(&event);
  102. }
  103. void IrdaApp::popup_callback(void* context) {
  104. IrdaApp* app = static_cast<IrdaApp*>(context);
  105. IrdaAppEvent event;
  106. event.type = IrdaAppEvent::Type::PopupTimer;
  107. app->get_view_manager()->send_event(&event);
  108. }
  109. void IrdaApp::set_edit_element(IrdaApp::EditElement value) {
  110. element = value;
  111. }
  112. IrdaApp::EditElement IrdaApp::get_edit_element(void) {
  113. return element;
  114. }
  115. void IrdaApp::set_edit_action(IrdaApp::EditAction value) {
  116. action = value;
  117. }
  118. IrdaApp::EditAction IrdaApp::get_edit_action(void) {
  119. return action;
  120. }