easy_flipper.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #ifndef EASY_FLIPPER_H
  2. #define EASY_FLIPPER_H
  3. #include <malloc.h>
  4. #include <furi.h>
  5. #include <furi_hal.h>
  6. #include <gui/gui.h>
  7. #include <gui/view.h>
  8. #include <gui/modules/submenu.h>
  9. #include <gui/view_dispatcher.h>
  10. #include <gui/modules/menu.h>
  11. #include <gui/modules/submenu.h>
  12. #include <gui/modules/widget.h>
  13. #include <gui/modules/text_input.h>
  14. #include <gui/modules/text_box.h>
  15. #include <gui/modules/variable_item_list.h>
  16. #include <gui/modules/dialog_ex.h>
  17. #include <notification/notification.h>
  18. #include <dialogs/dialogs.h>
  19. #include <gui/modules/popup.h>
  20. #include <gui/modules/loading.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <jsmn/jsmn.h>
  24. #define EASY_TAG "EasyFlipper"
  25. /**
  26. * @brief Navigation callback for exiting the application
  27. * @param context The context - unused
  28. * @return next view id (VIEW_NONE to exit the app)
  29. */
  30. uint32_t easy_flipper_callback_exit_app(void* context);
  31. /**
  32. * @brief Initialize a buffer
  33. * @param buffer The buffer to initialize
  34. * @param buffer_size The size of the buffer
  35. * @return true if successful, false otherwise
  36. */
  37. bool easy_flipper_set_buffer(char** buffer, uint32_t buffer_size);
  38. /**
  39. * @brief Initialize a View object
  40. * @param view The View object to initialize
  41. * @param view_id The ID/Index of the view
  42. * @param draw_callback The draw callback function (set to NULL if not needed)
  43. * @param input_callback The input callback function (set to NULL if not needed)
  44. * @param previous_callback The previous callback function (can be set to NULL)
  45. * @param view_dispatcher The ViewDispatcher object
  46. * @return true if successful, false otherwise
  47. */
  48. bool easy_flipper_set_view(
  49. View** view,
  50. int32_t view_id,
  51. void draw_callback(Canvas*, void*),
  52. bool input_callback(InputEvent*, void*),
  53. uint32_t (*previous_callback)(void*),
  54. ViewDispatcher** view_dispatcher,
  55. void* context);
  56. /**
  57. * @brief Initialize a ViewDispatcher object
  58. * @param view_dispatcher The ViewDispatcher object to initialize
  59. * @param gui The GUI object
  60. * @param context The context to pass to the event callback
  61. * @return true if successful, false otherwise
  62. */
  63. bool easy_flipper_set_view_dispatcher(ViewDispatcher** view_dispatcher, Gui* gui, void* context);
  64. /**
  65. * @brief Initialize a Submenu object
  66. * @note This does not set the items in the submenu
  67. * @param submenu The Submenu object to initialize
  68. * @param view_id The ID/Index of the view
  69. * @param title The title/header of the submenu
  70. * @param previous_callback The previous callback function (can be set to NULL)
  71. * @param view_dispatcher The ViewDispatcher object
  72. * @return true if successful, false otherwise
  73. */
  74. bool easy_flipper_set_submenu(
  75. Submenu** submenu,
  76. int32_t view_id,
  77. char* title,
  78. uint32_t(previous_callback)(void*),
  79. ViewDispatcher** view_dispatcher);
  80. /**
  81. * @brief Initialize a Menu object
  82. * @note This does not set the items in the menu
  83. * @param menu The Menu object to initialize
  84. * @param view_id The ID/Index of the view
  85. * @param item_callback The item callback function
  86. * @param previous_callback The previous callback function (can be set to NULL)
  87. * @param view_dispatcher The ViewDispatcher object
  88. * @return true if successful, false otherwise
  89. */
  90. bool easy_flipper_set_menu(
  91. Menu** menu,
  92. int32_t view_id,
  93. uint32_t(previous_callback)(void*),
  94. ViewDispatcher** view_dispatcher);
  95. /**
  96. * @brief Initialize a Widget object
  97. * @param widget The Widget object to initialize
  98. * @param view_id The ID/Index of the view
  99. * @param text The text to display in the widget
  100. * @param previous_callback The previous callback function (can be set to NULL)
  101. * @param view_dispatcher The ViewDispatcher object
  102. * @return true if successful, false otherwise
  103. */
  104. bool easy_flipper_set_widget(
  105. Widget** widget,
  106. int32_t view_id,
  107. char* text,
  108. uint32_t(previous_callback)(void*),
  109. ViewDispatcher** view_dispatcher);
  110. /**
  111. * @brief Initialize a VariableItemList object
  112. * @note This does not set the items in the VariableItemList
  113. * @param variable_item_list The VariableItemList object to initialize
  114. * @param view_id The ID/Index of the view
  115. * @param enter_callback The enter callback function (can be set to NULL)
  116. * @param previous_callback The previous callback function (can be set to NULL)
  117. * @param view_dispatcher The ViewDispatcher object
  118. * @param context The context to pass to the enter callback (usually the app)
  119. * @return true if successful, false otherwise
  120. */
  121. bool easy_flipper_set_variable_item_list(
  122. VariableItemList** variable_item_list,
  123. int32_t view_id,
  124. void (*enter_callback)(void*, uint32_t),
  125. uint32_t(previous_callback)(void*),
  126. ViewDispatcher** view_dispatcher,
  127. void* context);
  128. /**
  129. * @brief Initialize a TextInput object
  130. * @param text_input The TextInput object to initialize
  131. * @param view_id The ID/Index of the view
  132. * @param previous_callback The previous callback function (can be set to NULL)
  133. * @param view_dispatcher The ViewDispatcher object
  134. * @return true if successful, false otherwise
  135. */
  136. bool easy_flipper_set_text_input(
  137. TextInput** text_input,
  138. int32_t view_id,
  139. char* header_text,
  140. char* text_input_temp_buffer,
  141. uint32_t text_input_buffer_size,
  142. void (*result_callback)(void*),
  143. uint32_t(previous_callback)(void*),
  144. ViewDispatcher** view_dispatcher,
  145. void* context);
  146. /**
  147. * @brief Initialize a TextInput object with extra symbols
  148. * @param uart_text_input The TextInput object to initialize
  149. * @param view_id The ID/Index of the view
  150. * @param previous_callback The previous callback function (can be set to NULL)
  151. * @param view_dispatcher The ViewDispatcher object
  152. * @return true if successful, false otherwise
  153. */
  154. bool easy_flipper_set_uart_text_input(
  155. TextInput** uart_text_input,
  156. int32_t view_id,
  157. char* header_text,
  158. char* uart_text_input_temp_buffer,
  159. uint32_t uart_text_input_buffer_size,
  160. void (*result_callback)(void*),
  161. uint32_t(previous_callback)(void*),
  162. ViewDispatcher** view_dispatcher,
  163. void* context);
  164. /**
  165. * @brief Initialize a DialogEx object
  166. * @param dialog_ex The DialogEx object to initialize
  167. * @param view_id The ID/Index of the view
  168. * @param header The header of the dialog
  169. * @param header_x The x coordinate of the header
  170. * @param header_y The y coordinate of the header
  171. * @param text The text of the dialog
  172. * @param text_x The x coordinate of the dialog
  173. * @param text_y The y coordinate of the dialog
  174. * @param left_button_text The text of the left button
  175. * @param right_button_text The text of the right button
  176. * @param center_button_text The text of the center button
  177. * @param result_callback The result callback function
  178. * @param previous_callback The previous callback function (can be set to NULL)
  179. * @param view_dispatcher The ViewDispatcher object
  180. * @param context The context to pass to the result callback
  181. * @return true if successful, false otherwise
  182. */
  183. bool easy_flipper_set_dialog_ex(
  184. DialogEx** dialog_ex,
  185. int32_t view_id,
  186. char* header,
  187. uint16_t header_x,
  188. uint16_t header_y,
  189. char* text,
  190. uint16_t text_x,
  191. uint16_t text_y,
  192. char* left_button_text,
  193. char* right_button_text,
  194. char* center_button_text,
  195. void (*result_callback)(DialogExResult, void*),
  196. uint32_t(previous_callback)(void*),
  197. ViewDispatcher** view_dispatcher,
  198. void* context);
  199. /**
  200. * @brief Initialize a Popup object
  201. * @param popup The Popup object to initialize
  202. * @param view_id The ID/Index of the view
  203. * @param header The header of the dialog
  204. * @param header_x The x coordinate of the header
  205. * @param header_y The y coordinate of the header
  206. * @param text The text of the dialog
  207. * @param text_x The x coordinate of the dialog
  208. * @param text_y The y coordinate of the dialog
  209. * @param result_callback The result callback function
  210. * @param previous_callback The previous callback function (can be set to NULL)
  211. * @param view_dispatcher The ViewDispatcher object
  212. * @param context The context to pass to the result callback
  213. * @return true if successful, false otherwise
  214. */
  215. bool easy_flipper_set_popup(
  216. Popup** popup,
  217. int32_t view_id,
  218. char* header,
  219. uint16_t header_x,
  220. uint16_t header_y,
  221. char* text,
  222. uint16_t text_x,
  223. uint16_t text_y,
  224. void (*result_callback)(void*),
  225. uint32_t(previous_callback)(void*),
  226. ViewDispatcher** view_dispatcher,
  227. void* context);
  228. /**
  229. * @brief Initialize a Loading object
  230. * @param loading The Loading object to initialize
  231. * @param view_id The ID/Index of the view
  232. * @param previous_callback The previous callback function (can be set to NULL)
  233. * @param view_dispatcher The ViewDispatcher object
  234. * @return true if successful, false otherwise
  235. */
  236. bool easy_flipper_set_loading(
  237. Loading** loading,
  238. int32_t view_id,
  239. uint32_t(previous_callback)(void*),
  240. ViewDispatcher** view_dispatcher);
  241. /**
  242. * @brief Set a char butter to a FuriString
  243. * @param furi_string The FuriString object
  244. * @param buffer The buffer to copy the string to
  245. * @return true if successful, false otherwise
  246. */
  247. bool easy_flipper_set_char_to_furi_string(FuriString** furi_string, char* buffer);
  248. #endif