irda-app.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #include "irda-app.hpp"
  2. #include <furi.h>
  3. #include <gui/gui.h>
  4. #include <input/input.h>
  5. #include <stdio.h>
  6. #include <callback-connector.h>
  7. void IrdaApp::run(void) {
  8. IrdaAppEvent event;
  9. bool consumed;
  10. bool exit = false;
  11. scenes[current_scene]->on_enter(this);
  12. while(!exit) {
  13. view_manager.receive_event(&event);
  14. consumed = scenes[current_scene]->on_event(this, &event);
  15. if(!consumed) {
  16. if(event.type == IrdaAppEvent::Type::Back) {
  17. exit = switch_to_previous_scene();
  18. }
  19. }
  20. };
  21. scenes[current_scene]->on_exit(this);
  22. };
  23. IrdaAppViewManager* IrdaApp::get_view_manager() {
  24. return &view_manager;
  25. }
  26. void IrdaApp::set_learn_new_remote(bool value) {
  27. learn_new_remote = value;
  28. }
  29. bool IrdaApp::get_learn_new_remote() {
  30. return learn_new_remote;
  31. }
  32. void IrdaApp::switch_to_next_scene(Scene next_scene) {
  33. previous_scenes_list.push_front(current_scene);
  34. switch_to_next_scene_without_saving(next_scene);
  35. }
  36. void IrdaApp::switch_to_next_scene_without_saving(Scene next_scene) {
  37. if(next_scene != Scene::Exit) {
  38. scenes[current_scene]->on_exit(this);
  39. current_scene = next_scene;
  40. scenes[current_scene]->on_enter(this);
  41. }
  42. }
  43. void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_list<Scene>& scenes_list) {
  44. Scene previous_scene = Scene::Start;
  45. bool scene_found = false;
  46. while(!scene_found) {
  47. previous_scene = get_previous_scene();
  48. for(Scene element : scenes_list) {
  49. if(previous_scene == element) {
  50. scene_found = true;
  51. break;
  52. }
  53. }
  54. }
  55. scenes[current_scene]->on_exit(this);
  56. current_scene = previous_scene;
  57. scenes[current_scene]->on_enter(this);
  58. }
  59. bool IrdaApp::switch_to_previous_scene(uint8_t count) {
  60. Scene previous_scene = Scene::Start;
  61. for(uint8_t i = 0; i < count; i++) previous_scene = get_previous_scene();
  62. if(previous_scene == Scene::Exit) return true;
  63. scenes[current_scene]->on_exit(this);
  64. current_scene = previous_scene;
  65. scenes[current_scene]->on_enter(this);
  66. return false;
  67. }
  68. IrdaApp::Scene IrdaApp::get_previous_scene() {
  69. Scene scene = Scene::Exit;
  70. if(!previous_scenes_list.empty()) {
  71. scene = previous_scenes_list.front();
  72. previous_scenes_list.pop_front();
  73. }
  74. return scene;
  75. }
  76. IrdaAppRemoteManager* IrdaApp::get_remote_manager() {
  77. return &remote_manager;
  78. }
  79. IrdaAppSignalTransceiver* IrdaApp::get_transceiver() {
  80. return &transceiver;
  81. }
  82. void IrdaApp::set_text_store(uint8_t index, const char* text...) {
  83. furi_check(index < text_store_max);
  84. va_list args;
  85. va_start(args, text);
  86. vsnprintf(text_store[index], text_store_size, text, args);
  87. va_end(args);
  88. }
  89. char* IrdaApp::get_text_store(uint8_t index) {
  90. furi_check(index < text_store_max);
  91. return text_store[index];
  92. }
  93. uint8_t IrdaApp::get_text_store_size() {
  94. return text_store_size;
  95. }
  96. void IrdaApp::text_input_callback(void* context) {
  97. IrdaApp* app = static_cast<IrdaApp*>(context);
  98. IrdaAppEvent event;
  99. event.type = IrdaAppEvent::Type::TextEditDone;
  100. app->get_view_manager()->send_event(&event);
  101. }
  102. void IrdaApp::popup_callback(void* context) {
  103. IrdaApp* app = static_cast<IrdaApp*>(context);
  104. IrdaAppEvent event;
  105. event.type = IrdaAppEvent::Type::PopupTimer;
  106. app->get_view_manager()->send_event(&event);
  107. }
  108. void IrdaApp::set_edit_element(IrdaApp::EditElement value) {
  109. element = value;
  110. }
  111. IrdaApp::EditElement IrdaApp::get_edit_element(void) {
  112. return element;
  113. }
  114. void IrdaApp::set_edit_action(IrdaApp::EditAction value) {
  115. action = value;
  116. }
  117. IrdaApp::EditAction IrdaApp::get_edit_action(void) {
  118. return action;
  119. }
  120. void IrdaApp::set_current_button(int value) {
  121. current_button = value;
  122. }
  123. int IrdaApp::get_current_button() {
  124. return current_button;
  125. }
  126. void IrdaApp::notify_success() {
  127. notification_message(notification, &sequence_success);
  128. }
  129. void IrdaApp::notify_red_blink() {
  130. notification_message(notification, &sequence_blink_red_10);
  131. }
  132. void IrdaApp::notify_space_blink() {
  133. static const NotificationSequence sequence = {
  134. &message_green_0,
  135. &message_delay_50,
  136. &message_green_255,
  137. &message_do_not_reset,
  138. NULL,
  139. };
  140. notification_message_block(notification, &sequence);
  141. }
  142. void IrdaApp::notify_click() {
  143. static const NotificationSequence sequence = {
  144. &message_click,
  145. &message_delay_1,
  146. &message_sound_off,
  147. NULL,
  148. };
  149. notification_message_block(notification, &sequence);
  150. }
  151. void IrdaApp::notify_click_and_blink() {
  152. static const NotificationSequence sequence = {
  153. &message_click,
  154. &message_delay_1,
  155. &message_sound_off,
  156. &message_red_0,
  157. &message_green_255,
  158. &message_blue_0,
  159. &message_delay_10,
  160. &message_green_0,
  161. NULL,
  162. };
  163. notification_message_block(notification, &sequence);
  164. }
  165. void IrdaApp::notify_double_vibro() {
  166. notification_message(notification, &sequence_double_vibro);
  167. }
  168. void IrdaApp::notify_green_on() {
  169. notification_message(notification, &sequence_set_only_green_255);
  170. }
  171. void IrdaApp::notify_green_off() {
  172. notification_message(notification, &sequence_reset_green);
  173. }