xremote_app.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_TEXT_MAX 128
  30. #define XREMOTE_APP_EXTENSION ".ir"
  31. #define XREMOTE_APP_TAG "XRemoteApp"
  32. #define XREMOTE_APP_FOLDER ANY_PATH("infrared")
  33. #define XREMOTE_APP_SETTINGS APP_DATA_PATH("xremote.cfg")
  34. #define XREMOTE_ALT_NAMES APP_DATA_PATH("alt_names.txt")
  35. #define xremote_app_assert_void(cond) \
  36. if(!cond) return
  37. #define xremote_app_assert(cond, var) \
  38. if(!cond) return var
  39. typedef enum {
  40. XRemoteAppExitPress,
  41. XRemoteAppExitHold
  42. } XRemoteAppExit;
  43. XRemoteAppExit xremote_app_get_exit_behavior(uint8_t exit_index);
  44. const char* xremote_app_get_exit_str(XRemoteAppExit exit_behavior);
  45. uint32_t xremote_app_get_exit_index(XRemoteAppExit exit_behavior);
  46. ViewOrientation xremote_app_get_orientation(uint8_t orientation_index);
  47. const char* xremote_app_get_orientation_str(ViewOrientation view_orientation);
  48. const char* xremote_app_get_alt_names_str(uint8_t alt_names_index);
  49. uint32_t xremote_app_get_orientation_index(ViewOrientation view_orientation);
  50. //////////////////////////////////////////////////////////////////////////////
  51. // XRemote application settings
  52. //////////////////////////////////////////////////////////////////////////////
  53. typedef struct {
  54. ViewOrientation orientation;
  55. XRemoteAppExit exit_behavior;
  56. uint32_t repeat_count;
  57. uint32_t alt_names;
  58. } XRemoteAppSettings;
  59. XRemoteAppSettings* xremote_app_settings_alloc();
  60. void xremote_app_settings_free(XRemoteAppSettings* settings);
  61. bool xremote_app_settings_store(XRemoteAppSettings* settings);
  62. bool xremote_app_settings_load(XRemoteAppSettings* settings);
  63. //////////////////////////////////////////////////////////////////////////////
  64. // XRemote gloal context shared between every child application
  65. //////////////////////////////////////////////////////////////////////////////
  66. typedef struct {
  67. XRemoteAppSettings* app_settings;
  68. NotificationApp* notifications;
  69. ViewDispatcher* view_dispatcher;
  70. FuriString* file_path;
  71. void* app_argument;
  72. Gui* gui;
  73. } XRemoteAppContext;
  74. XRemoteAppContext* xremote_app_context_alloc(void* arg);
  75. void xremote_app_context_free(XRemoteAppContext* ctx);
  76. const char* xremote_app_context_get_exit_str(XRemoteAppContext* app_ctx);
  77. void xremote_app_context_notify_led(XRemoteAppContext* app_ctx);
  78. void xremote_app_notification_blink(NotificationApp* notifications);
  79. bool xremote_app_send_signal(XRemoteAppContext* app_ctx, InfraredSignal* signal);
  80. bool xremote_app_context_select_file(XRemoteAppContext* app_ctx, const char* extension);
  81. bool xremote_app_browser_select_file(FuriString** file_path, const char* extension);
  82. //////////////////////////////////////////////////////////////////////////////
  83. // XRemote buttons and custom button pairs
  84. //////////////////////////////////////////////////////////////////////////////
  85. typedef struct {
  86. XRemoteAppContext* app_ctx;
  87. InfraredRemote* remote;
  88. FuriString* custom_up;
  89. FuriString* custom_down;
  90. FuriString* custom_left;
  91. FuriString* custom_right;
  92. FuriString* custom_ok;
  93. FuriString* custom_up_hold;
  94. FuriString* custom_down_hold;
  95. FuriString* custom_left_hold;
  96. FuriString* custom_right_hold;
  97. FuriString* custom_ok_hold;
  98. } XRemoteAppButtons;
  99. void xremote_app_buttons_free(XRemoteAppButtons* buttons);
  100. XRemoteAppButtons* xremote_app_buttons_alloc();
  101. XRemoteAppButtons* xremote_app_buttons_load(XRemoteAppContext* app_ctx);
  102. bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path);
  103. bool xremote_app_extension_load(XRemoteAppButtons* buttons, FuriString* path);
  104. bool xremote_app_alt_names_check_and_init();
  105. //////////////////////////////////////////////////////////////////////////////
  106. // XRemote application factory
  107. //////////////////////////////////////////////////////////////////////////////
  108. typedef struct {
  109. XRemoteClearCallback on_clear;
  110. XRemoteAppContext* app_ctx;
  111. XRemoteViewID submenu_id;
  112. XRemoteViewID view_id;
  113. XRemoteView* view_ctx;
  114. Submenu* submenu;
  115. void* context;
  116. } XRemoteApp;
  117. void xremote_app_submenu_add(
  118. XRemoteApp* app,
  119. const char* name,
  120. uint32_t index,
  121. SubmenuItemCallback callback);
  122. void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCallback prev_cb);
  123. void xremote_app_submenu_free(XRemoteApp* app);
  124. void xremote_app_view_alloc2(
  125. XRemoteApp* app,
  126. uint32_t view_id,
  127. XRemoteViewAllocator2 allocator,
  128. void* model_ctx);
  129. void xremote_app_view_alloc(XRemoteApp* app, uint32_t view_id, XRemoteViewAllocator allocator);
  130. void xremote_app_view_free(XRemoteApp* app);
  131. void xremote_app_view_set_previous_callback(XRemoteApp* app, ViewNavigationCallback callback);
  132. void xremote_app_set_view_context(XRemoteApp* app, void* context, XRemoteClearCallback on_clear);
  133. void xremote_app_set_user_context(XRemoteApp* app, void* context, XRemoteClearCallback on_clear);
  134. void xremote_app_user_context_free(XRemoteApp* app);
  135. bool xremote_app_has_view(XRemoteApp* app, uint32_t view_id);
  136. void xremote_app_switch_to_view(XRemoteApp* app, uint32_t view_id);
  137. void xremote_app_switch_to_submenu(XRemoteApp* app);
  138. XRemoteApp* xremote_app_alloc(XRemoteAppContext* ctx);
  139. void xremote_app_free(XRemoteApp* app);