xremote_app.h 6.0 KB

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