flip_library_callback.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef FLIP_LIBRARY_CALLBACK_H
  2. #define FLIP_LIBRARY_CALLBACK_H
  3. #include <flip_library.h>
  4. #include <flip_storage/flip_library_storage.h>
  5. #define MAX_TOKENS 512 // Adjust based on expected JSON size
  6. typedef enum FactState FactState;
  7. enum FactState {
  8. FactStateInitial,
  9. FactStateRequested,
  10. FactStateReceived,
  11. FactStateParsed,
  12. FactStateParseError,
  13. FactStateError,
  14. };
  15. typedef enum FlipLibraryCustomEvent FlipLibraryCustomEvent;
  16. enum FlipLibraryCustomEvent {
  17. FlipLibraryCustomEventProcess,
  18. };
  19. typedef struct FactLoaderModel FactLoaderModel;
  20. typedef bool (*FactLoaderFetch)(FactLoaderModel* model);
  21. typedef char* (*FactLoaderParser)(FactLoaderModel* model);
  22. struct FactLoaderModel {
  23. char* title;
  24. char* fact_text;
  25. FactState fact_state;
  26. FactLoaderFetch fetcher;
  27. FactLoaderParser parser;
  28. void* parser_context;
  29. size_t request_index;
  30. size_t request_count;
  31. ViewNavigationCallback back_callback;
  32. FuriTimer* timer;
  33. };
  34. extern uint32_t random_facts_index;
  35. extern bool sent_random_fact_request;
  36. extern bool random_fact_request_success;
  37. extern bool random_fact_request_success_all;
  38. extern char* random_fact;
  39. void flip_library_generic_switch_to_view(
  40. FlipLibraryApp* app,
  41. char* title,
  42. FactLoaderFetch fetcher,
  43. FactLoaderParser parser,
  44. size_t request_count,
  45. ViewNavigationCallback back,
  46. uint32_t view_id);
  47. void flip_library_loader_draw_callback(Canvas* canvas, void* model);
  48. void flip_library_loader_init(View* view);
  49. void flip_library_loader_free_model(View* view);
  50. bool flip_library_custom_event_callback(void* context, uint32_t index);
  51. void callback_submenu_choices(void* context, uint32_t index);
  52. void text_updated_ssid(void* context);
  53. void text_updated_password(void* context);
  54. void text_updated_query(void* context);
  55. uint32_t callback_to_submenu(void* context);
  56. uint32_t callback_to_wifi_settings(void* context);
  57. uint32_t callback_to_random_facts(void* context);
  58. void settings_item_selected(void* context, uint32_t index);
  59. /**
  60. * @brief Navigation callback for exiting the application
  61. * @param context The context - unused
  62. * @return next view id (VIEW_NONE to exit the app)
  63. */
  64. uint32_t callback_exit_app(void* context);
  65. #endif // FLIP_LIBRARY_CALLBACK_H