easy_flipper.h 9.9 KB

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