easy_flipper.h 9.8 KB

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