easy_flipper.h 9.1 KB

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