irda-app.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #include "irda-app.hpp"
  2. #include <irda_worker.h>
  3. #include <furi.h>
  4. #include <gui/gui.h>
  5. #include <input/input.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. void IrdaApp::set_text_store(uint8_t index, const char* text...) {
  81. furi_check(index < text_store_max);
  82. va_list args;
  83. va_start(args, text);
  84. vsnprintf(text_store[index], text_store_size, text, args);
  85. va_end(args);
  86. }
  87. char* IrdaApp::get_text_store(uint8_t index) {
  88. furi_check(index < text_store_max);
  89. return text_store[index];
  90. }
  91. uint8_t IrdaApp::get_text_store_size() {
  92. return text_store_size;
  93. }
  94. void IrdaApp::text_input_callback(void* context) {
  95. IrdaApp* app = static_cast<IrdaApp*>(context);
  96. IrdaAppEvent event;
  97. event.type = IrdaAppEvent::Type::TextEditDone;
  98. app->get_view_manager()->send_event(&event);
  99. }
  100. void IrdaApp::popup_callback(void* context) {
  101. IrdaApp* app = static_cast<IrdaApp*>(context);
  102. IrdaAppEvent event;
  103. event.type = IrdaAppEvent::Type::PopupTimer;
  104. app->get_view_manager()->send_event(&event);
  105. }
  106. void IrdaApp::set_edit_element(IrdaApp::EditElement value) {
  107. element = value;
  108. }
  109. IrdaApp::EditElement IrdaApp::get_edit_element(void) {
  110. return element;
  111. }
  112. void IrdaApp::set_edit_action(IrdaApp::EditAction value) {
  113. action = value;
  114. }
  115. IrdaApp::EditAction IrdaApp::get_edit_action(void) {
  116. return action;
  117. }
  118. void IrdaApp::set_current_button(int value) {
  119. current_button = value;
  120. }
  121. int IrdaApp::get_current_button() {
  122. return current_button;
  123. }
  124. void IrdaApp::notify_success() {
  125. notification_message(notification, &sequence_success);
  126. }
  127. void IrdaApp::notify_red_blink() {
  128. notification_message(notification, &sequence_blink_red_10);
  129. }
  130. void IrdaApp::notify_space_blink() {
  131. static const NotificationSequence sequence = {
  132. &message_green_0,
  133. &message_delay_50,
  134. &message_green_255,
  135. &message_do_not_reset,
  136. NULL,
  137. };
  138. notification_message_block(notification, &sequence);
  139. }
  140. void IrdaApp::notify_click() {
  141. static const NotificationSequence sequence = {
  142. &message_click,
  143. &message_delay_1,
  144. &message_sound_off,
  145. NULL,
  146. };
  147. notification_message_block(notification, &sequence);
  148. }
  149. void IrdaApp::notify_click_and_blink() {
  150. static const NotificationSequence sequence = {
  151. &message_click,
  152. &message_delay_1,
  153. &message_sound_off,
  154. &message_red_0,
  155. &message_green_255,
  156. &message_blue_0,
  157. &message_delay_10,
  158. &message_green_0,
  159. NULL,
  160. };
  161. notification_message_block(notification, &sequence);
  162. }
  163. void IrdaApp::notify_double_vibro() {
  164. notification_message(notification, &sequence_double_vibro);
  165. }
  166. void IrdaApp::notify_green_on() {
  167. notification_message(notification, &sequence_set_only_green_255);
  168. }
  169. void IrdaApp::notify_green_off() {
  170. notification_message(notification, &sequence_reset_green);
  171. }
  172. IrdaWorker* IrdaApp::get_irda_worker() {
  173. return irda_worker;
  174. }
  175. const IrdaAppSignal& IrdaApp::get_received_signal() const {
  176. return received_signal;
  177. }
  178. void IrdaApp::set_received_signal(const IrdaAppSignal& signal) {
  179. received_signal = signal;
  180. }