xremote_control.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. * @file flipper-xremote/xremote_control.c
  3. @license This project is released under the GNU GPLv3 License
  4. * @copyright (c) 2023 Sandro Kalatozishvili (s.kalatoz@gmail.com)
  5. *
  6. * @brief Remote controller application menu and view factory.
  7. */
  8. #include "xremote_control.h"
  9. #include "xremote_edit.h"
  10. #include "infrared/infrared_remote.h"
  11. #include "views/xremote_general_view.h"
  12. #include "views/xremote_control_view.h"
  13. #include "views/xremote_navigation_view.h"
  14. #include "views/xremote_player_view.h"
  15. #include "views/xremote_custom_view.h"
  16. static uint32_t xremote_control_submenu_exit_callback(void* context) {
  17. UNUSED(context);
  18. return XRemoteViewSubmenu;
  19. }
  20. static uint32_t xremote_control_view_exit_callback(void* context) {
  21. UNUSED(context);
  22. return XRemoteViewIRSubmenu;
  23. }
  24. static void xremote_buttons_clear_callback(void* context) {
  25. xremote_app_assert_void(context);
  26. xremote_app_buttons_free((XRemoteAppButtons*)context);
  27. }
  28. static void xremote_control_submenu_callback(void* context, uint32_t index) {
  29. furi_assert(context);
  30. XRemoteApp* app = context;
  31. /* Allocate new view based on selection */
  32. if(index == XRemoteViewIRGeneral)
  33. xremote_app_view_alloc(app, index, xremote_general_view_alloc);
  34. else if(index == XRemoteViewIRControl)
  35. xremote_app_view_alloc(app, index, xremote_control_view_alloc);
  36. else if(index == XRemoteViewIRNavigation)
  37. xremote_app_view_alloc(app, index, xremote_navigation_view_alloc);
  38. else if(index == XRemoteViewIRPlayback)
  39. xremote_app_view_alloc(app, index, xremote_player_view_alloc);
  40. else if(index == XRemoteViewIRCustomPage)
  41. xremote_app_view_alloc2(app, index, xremote_custom_view_alloc, app->context);
  42. else if(index == XRemoteViewIRCustomEditPage)
  43. xremote_edit_view_alloc(app, index, app->context);
  44. if(app->view_ctx != NULL) {
  45. if(index != XRemoteViewIRCustomEditPage) {
  46. xremote_app_view_set_previous_callback(app, xremote_control_view_exit_callback);
  47. xremote_app_set_view_context(app, app->context, NULL);
  48. }
  49. xremote_app_switch_to_view(app, index);
  50. }
  51. }
  52. XRemoteApp* xremote_control_alloc(XRemoteAppContext* app_ctx) {
  53. /* Open file browser and load buttons from selected file */
  54. XRemoteAppButtons* buttons = xremote_app_buttons_load(app_ctx);
  55. xremote_app_assert(buttons, NULL);
  56. /* Allocate remote controller app with submenu */
  57. XRemoteApp* app = xremote_app_alloc(app_ctx);
  58. xremote_app_set_user_context(app, buttons, xremote_buttons_clear_callback);
  59. xremote_app_submenu_alloc(app, XRemoteViewIRSubmenu, xremote_control_submenu_exit_callback);
  60. xremote_app_submenu_add(
  61. app, "General", XRemoteViewIRGeneral, xremote_control_submenu_callback);
  62. xremote_app_submenu_add(
  63. app, "Control", XRemoteViewIRControl, xremote_control_submenu_callback);
  64. xremote_app_submenu_add(
  65. app, "Navigation", XRemoteViewIRNavigation, xremote_control_submenu_callback);
  66. xremote_app_submenu_add(
  67. app, "Playback", XRemoteViewIRPlayback, xremote_control_submenu_callback);
  68. xremote_app_submenu_add(
  69. app, "Custom", XRemoteViewIRCustomPage, xremote_control_submenu_callback);
  70. xremote_app_submenu_add(
  71. app, "Edit", XRemoteViewIRCustomEditPage, xremote_control_submenu_callback);
  72. return app;
  73. }