easy_flipper.h 8.9 KB

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