easy_flipper.h 9.0 KB

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