infrared_app_scene.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /**
  2. * @file infrared_app_scene.h
  3. * Infrared: Application scenes
  4. */
  5. #pragma once
  6. #include "../infrared_app_event.h"
  7. #include <furi_hal_infrared.h>
  8. #include "infrared.h"
  9. #include <vector>
  10. #include <string>
  11. #include "../infrared_app_brute_force.h"
  12. /** Anonymous class */
  13. class InfraredApp;
  14. /** Base Scene class */
  15. class InfraredAppScene {
  16. public:
  17. /** Called when enter scene */
  18. virtual void on_enter(InfraredApp* app) = 0;
  19. /** Events handler callback */
  20. virtual bool on_event(InfraredApp* app, InfraredAppEvent* event) = 0;
  21. /** Called when exit scene */
  22. virtual void on_exit(InfraredApp* app) = 0;
  23. /** Virtual destructor of base class */
  24. virtual ~InfraredAppScene(){};
  25. private:
  26. };
  27. /** Start scene
  28. * Main Infrared application menu
  29. */
  30. class InfraredAppSceneStart : public InfraredAppScene {
  31. public:
  32. /** Called when enter scene */
  33. void on_enter(InfraredApp* app) final;
  34. /** Events handler callback */
  35. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  36. /** Called when exit scene */
  37. void on_exit(InfraredApp* app) final;
  38. private:
  39. /** Save previously selected submenu index
  40. * to highlight it when get back */
  41. uint32_t submenu_item_selected = 0;
  42. };
  43. /** Universal menu scene
  44. * Scene to select universal remote
  45. */
  46. class InfraredAppSceneUniversal : public InfraredAppScene {
  47. public:
  48. /** Called when enter scene */
  49. void on_enter(InfraredApp* app) final;
  50. /** Events handler callback */
  51. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  52. /** Called when exit scene */
  53. void on_exit(InfraredApp* app) final;
  54. private:
  55. /** Save previously selected submenu index
  56. * to highlight it when get back */
  57. uint32_t submenu_item_selected = 0;
  58. };
  59. /** Learn new signal scene
  60. * On this scene catching new IR signal performed.
  61. */
  62. class InfraredAppSceneLearn : public InfraredAppScene {
  63. public:
  64. /** Called when enter scene */
  65. void on_enter(InfraredApp* app) final;
  66. /** Events handler callback */
  67. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  68. /** Called when exit scene */
  69. void on_exit(InfraredApp* app) final;
  70. };
  71. /** New signal learn succeeded scene
  72. */
  73. class InfraredAppSceneLearnSuccess : public InfraredAppScene {
  74. public:
  75. /** Called when enter scene */
  76. void on_enter(InfraredApp* app) final;
  77. /** Events handler callback */
  78. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  79. /** Called when exit scene */
  80. void on_exit(InfraredApp* app) final;
  81. bool button_pressed = false;
  82. };
  83. /** Scene to enter name for new button in remote
  84. */
  85. class InfraredAppSceneLearnEnterName : public InfraredAppScene {
  86. public:
  87. /** Called when enter scene */
  88. void on_enter(InfraredApp* app) final;
  89. /** Events handler callback */
  90. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  91. /** Called when exit scene */
  92. void on_exit(InfraredApp* app) final;
  93. };
  94. /** Scene where signal is learnt
  95. */
  96. class InfraredAppSceneLearnDone : public InfraredAppScene {
  97. public:
  98. /** Called when enter scene */
  99. void on_enter(InfraredApp* app) final;
  100. /** Events handler callback */
  101. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  102. /** Called when exit scene */
  103. void on_exit(InfraredApp* app) final;
  104. };
  105. /** Remote interface scene
  106. * On this scene you can send IR signals from selected remote
  107. */
  108. class InfraredAppSceneRemote : public InfraredAppScene {
  109. public:
  110. /** Called when enter scene */
  111. void on_enter(InfraredApp* app) final;
  112. /** Events handler callback */
  113. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  114. /** Called when exit scene */
  115. void on_exit(InfraredApp* app) final;
  116. private:
  117. /** container of button names in current remote. */
  118. std::vector<std::string> buttons_names;
  119. /** Save previously selected index
  120. * to highlight it when get back */
  121. uint32_t buttonmenu_item_selected = 0;
  122. /** state flag to show button is pressed.
  123. * As long as send-signal button pressed no other button
  124. * events are handled. */
  125. bool button_pressed = false;
  126. };
  127. /** List of remotes scene
  128. * Every remote is a file, located on internal/external storage.
  129. * Every file has same format, and same extension.
  130. * Files are parsed as you enter 'Remote scene' and showed
  131. * as a buttons.
  132. */
  133. class InfraredAppSceneRemoteList : public InfraredAppScene {
  134. public:
  135. /** Called when enter scene */
  136. void on_enter(InfraredApp* app) final;
  137. /** Events handler callback */
  138. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  139. /** Called when exit scene */
  140. void on_exit(InfraredApp* app) final;
  141. private:
  142. /** Save previously selected index
  143. * to highlight it when get back */
  144. uint32_t submenu_item_selected = 0;
  145. /** Remote names to show them in submenu */
  146. std::vector<std::string> remote_names;
  147. };
  148. class InfraredAppSceneAskBack : public InfraredAppScene {
  149. public:
  150. /** Called when enter scene */
  151. void on_enter(InfraredApp* app) final;
  152. /** Events handler callback */
  153. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  154. /** Called when exit scene */
  155. void on_exit(InfraredApp* app) final;
  156. };
  157. class InfraredAppSceneEdit : public InfraredAppScene {
  158. public:
  159. /** Called when enter scene */
  160. void on_enter(InfraredApp* app) final;
  161. /** Events handler callback */
  162. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  163. /** Called when exit scene */
  164. void on_exit(InfraredApp* app) final;
  165. private:
  166. /** Save previously selected index
  167. * to highlight it when get back */
  168. uint32_t submenu_item_selected = 0;
  169. };
  170. class InfraredAppSceneEditKeySelect : public InfraredAppScene {
  171. public:
  172. /** Called when enter scene */
  173. void on_enter(InfraredApp* app) final;
  174. /** Events handler callback */
  175. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  176. /** Called when exit scene */
  177. void on_exit(InfraredApp* app) final;
  178. private:
  179. /** Button names to show them in submenu */
  180. std::vector<std::string> buttons_names;
  181. };
  182. class InfraredAppSceneEditRename : public InfraredAppScene {
  183. public:
  184. /** Called when enter scene */
  185. void on_enter(InfraredApp* app) final;
  186. /** Events handler callback */
  187. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  188. /** Called when exit scene */
  189. void on_exit(InfraredApp* app) final;
  190. };
  191. class InfraredAppSceneEditDelete : public InfraredAppScene {
  192. public:
  193. /** Called when enter scene */
  194. void on_enter(InfraredApp* app) final;
  195. /** Events handler callback */
  196. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  197. /** Called when exit scene */
  198. void on_exit(InfraredApp* app) final;
  199. };
  200. class InfraredAppSceneEditRenameDone : public InfraredAppScene {
  201. public:
  202. /** Called when enter scene */
  203. void on_enter(InfraredApp* app) final;
  204. /** Events handler callback */
  205. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  206. /** Called when exit scene */
  207. void on_exit(InfraredApp* app) final;
  208. };
  209. class InfraredAppSceneEditDeleteDone : public InfraredAppScene {
  210. public:
  211. /** Called when enter scene */
  212. void on_enter(InfraredApp* app) final;
  213. /** Events handler callback */
  214. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  215. /** Called when exit scene */
  216. void on_exit(InfraredApp* app) final;
  217. };
  218. class InfraredAppSceneUniversalCommon : public InfraredAppScene {
  219. /** Brute force started flag */
  220. bool brute_force_started = false;
  221. protected:
  222. /** Events handler callback */
  223. bool on_event(InfraredApp* app, InfraredAppEvent* event) final;
  224. /** Called when exit scene */
  225. void on_exit(InfraredApp* app) final;
  226. /** Show popup window
  227. *
  228. * @param app - application instance
  229. */
  230. void show_popup(InfraredApp* app, int record_amount);
  231. /** Hide popup window
  232. *
  233. * @param app - application instance
  234. */
  235. void hide_popup(InfraredApp* app);
  236. /** Propagate progress in popup window
  237. *
  238. * @param app - application instance
  239. */
  240. bool progress_popup(InfraredApp* app);
  241. /** Item selected callback
  242. *
  243. * @param context - context
  244. * @param index - selected item index
  245. */
  246. static void infrared_app_item_callback(void* context, uint32_t index);
  247. /** Brute Force instance */
  248. InfraredAppBruteForce brute_force;
  249. /** Constructor */
  250. InfraredAppSceneUniversalCommon(const char* filename)
  251. : brute_force(filename) {
  252. }
  253. /** Destructor */
  254. ~InfraredAppSceneUniversalCommon() {
  255. }
  256. };
  257. class InfraredAppSceneUniversalTV : public InfraredAppSceneUniversalCommon {
  258. public:
  259. /** Called when enter scene */
  260. void on_enter(InfraredApp* app) final;
  261. /** Constructor
  262. * Specifies path to brute force db library */
  263. InfraredAppSceneUniversalTV()
  264. : InfraredAppSceneUniversalCommon("/ext/infrared/assets/tv.ir") {
  265. }
  266. /** Destructor */
  267. ~InfraredAppSceneUniversalTV() {
  268. }
  269. };