easy_flipper.h 8.9 KB

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