irda-app.cpp 5.2 KB

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