xremote_app.h 6.0 KB

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