easy_flipper.h 9.0 KB

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