easy_flipper.h 9.7 KB

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