xremote_app.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*!
  2. * @file flipper-xremote/xremote_app.h
  3. @license This project is released under the GNU GPLv3 License
  4. * @copyright (c) 2023 Sandro Kalatozishvili (s.kalatoz@gmail.com)
  5. *
  6. * @brief Shared functionality and data types between the apps.
  7. */
  8. #pragma once
  9. #include <furi.h>
  10. #include <gui/gui.h>
  11. #include <gui/view.h>
  12. #include <gui/view_dispatcher.h>
  13. #include <gui/modules/submenu.h>
  14. #include <gui/modules/dialog_ex.h>
  15. #include <gui/modules/text_input.h>
  16. #include <gui/modules/variable_item_list.h>
  17. #include <notification/notification.h>
  18. #include <notification/notification_messages.h>
  19. #include <flipper_format/flipper_format.h>
  20. #include <storage/storage.h>
  21. #include <dialogs/dialogs.h>
  22. #include <infrared_worker.h>
  23. #include "views/xremote_common_view.h"
  24. #include "xc_icons.h"
  25. #include <assets_icons.h>
  26. //////////////////////////////////////////////////////////////////////////////
  27. // XRemote generic functions and definitions
  28. //////////////////////////////////////////////////////////////////////////////
  29. #define XREMOTE_APP_EXTENSION ".ir"
  30. #define XREMOTE_APP_FOLDER ANY_PATH("infrared")
  31. #define XREMOTE_APP_TEXT_MAX 128
  32. #define xremote_app_assert_void(cond) \
  33. if(!cond) return
  34. #define xremote_app_assert(cond, var) \
  35. if(!cond) return var
  36. typedef enum { XRemoteAppExitPress, XRemoteAppExitHold } XRemoteAppExit;
  37. XRemoteAppExit xremote_app_get_exit_behavior(uint8_t exit_index);
  38. const char* xremote_app_get_exit_str(XRemoteAppExit exit_behavior);
  39. uint32_t xremote_app_get_exit_index(XRemoteAppExit exit_behavior);
  40. ViewOrientation xremote_app_get_orientation(uint8_t orientation_index);
  41. const char* xremote_app_get_orientation_str(ViewOrientation view_orientation);
  42. uint32_t xremote_app_get_orientation_index(ViewOrientation view_orientation);
  43. //////////////////////////////////////////////////////////////////////////////
  44. // XRemote application settings
  45. //////////////////////////////////////////////////////////////////////////////
  46. typedef struct {
  47. ViewOrientation orientation;
  48. XRemoteAppExit exit_behavior;
  49. uint32_t repeat_count;
  50. } XRemoteAppSettings;
  51. XRemoteAppSettings* xremote_app_settings_alloc();
  52. void xremote_app_settings_free(XRemoteAppSettings* settings);
  53. bool xremote_app_settings_store(XRemoteAppSettings* settings);
  54. bool xremote_app_settings_load(XRemoteAppSettings* settings);
  55. //////////////////////////////////////////////////////////////////////////////
  56. // XRemote gloal context shared between every child application
  57. //////////////////////////////////////////////////////////////////////////////
  58. typedef struct {
  59. XRemoteAppSettings* app_settings;
  60. NotificationApp* notifications;
  61. ViewDispatcher* view_dispatcher;
  62. FuriString* file_path;
  63. void* app_argument;
  64. Gui* gui;
  65. } XRemoteAppContext;
  66. XRemoteAppContext* xremote_app_context_alloc(void* arg);
  67. void xremote_app_context_free(XRemoteAppContext* ctx);
  68. const char* xremote_app_context_get_exit_str(XRemoteAppContext* app_ctx);
  69. void xremote_app_context_notify_led(XRemoteAppContext* app_ctx);
  70. void xremote_app_notification_blink(NotificationApp* notifications);
  71. bool xremote_app_send_signal(XRemoteAppContext* app_ctx, InfraredSignal* signal);
  72. bool xremote_app_browser_select_file(XRemoteAppContext* app_ctx, const char* extension);
  73. //////////////////////////////////////////////////////////////////////////////
  74. // XRemote buttons and custom button pairs
  75. //////////////////////////////////////////////////////////////////////////////
  76. typedef struct {
  77. XRemoteAppContext* app_ctx;
  78. InfraredRemote* remote;
  79. FuriString* custom_up;
  80. FuriString* custom_down;
  81. FuriString* custom_left;
  82. FuriString* custom_right;
  83. FuriString* custom_ok;
  84. FuriString* custom_up_hold;
  85. FuriString* custom_down_hold;
  86. FuriString* custom_left_hold;
  87. FuriString* custom_right_hold;
  88. FuriString* custom_ok_hold;
  89. } XRemoteAppButtons;
  90. void xremote_app_buttons_free(XRemoteAppButtons* buttons);
  91. XRemoteAppButtons* xremote_app_buttons_alloc();
  92. XRemoteAppButtons* xremote_app_buttons_load(XRemoteAppContext* app_ctx);
  93. bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path);
  94. bool xremote_app_extension_load(XRemoteAppButtons* buttons, FuriString* path);
  95. //////////////////////////////////////////////////////////////////////////////
  96. // XRemote application factory
  97. //////////////////////////////////////////////////////////////////////////////
  98. typedef struct {
  99. XRemoteClearCallback on_clear;
  100. XRemoteAppContext* app_ctx;
  101. XRemoteViewID submenu_id;
  102. XRemoteViewID view_id;
  103. XRemoteView* view_ctx;
  104. Submenu* submenu;
  105. void* context;
  106. } XRemoteApp;
  107. void xremote_app_submenu_add(
  108. XRemoteApp* app,
  109. const char* name,
  110. uint32_t index,
  111. SubmenuItemCallback callback);
  112. void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCallback prev_cb);
  113. void xremote_app_submenu_free(XRemoteApp* app);
  114. void xremote_app_view_alloc2(
  115. XRemoteApp* app,
  116. uint32_t view_id,
  117. XRemoteViewAllocator2 allocator,
  118. void* model_ctx);
  119. void xremote_app_view_alloc(XRemoteApp* app, uint32_t view_id, XRemoteViewAllocator allocator);
  120. void xremote_app_view_free(XRemoteApp* app);
  121. void xremote_app_view_set_previous_callback(XRemoteApp* app, ViewNavigationCallback callback);
  122. void xremote_app_set_view_context(XRemoteApp* app, void* context, XRemoteClearCallback on_clear);
  123. void xremote_app_set_user_context(XRemoteApp* app, void* context, XRemoteClearCallback on_clear);
  124. void xremote_app_user_context_free(XRemoteApp* app);
  125. bool xremote_app_has_view(XRemoteApp* app, uint32_t view_id);
  126. void xremote_app_switch_to_view(XRemoteApp* app, uint32_t view_id);
  127. void xremote_app_switch_to_submenu(XRemoteApp* app);
  128. XRemoteApp* xremote_app_alloc(XRemoteAppContext* ctx);
  129. void xremote_app_free(XRemoteApp* app);