pokemon_app.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <furi_hal_light.h>
  2. #include <pokemon_icons.h>
  3. #include "pokemon_app.h"
  4. #include "pokemon_data.h"
  5. #include "scenes/pokemon_menu.h"
  6. #include "views/trade.h"
  7. #include "views/select_pokemon.h"
  8. #include "pokemon_char_encode.h"
  9. PokemonFap* pokemon_alloc() {
  10. PokemonFap* pokemon_fap = (PokemonFap*)malloc(sizeof(PokemonFap));
  11. // View dispatcher
  12. pokemon_fap->view_dispatcher = view_dispatcher_alloc();
  13. view_dispatcher_enable_queue(pokemon_fap->view_dispatcher);
  14. view_dispatcher_set_event_callback_context(pokemon_fap->view_dispatcher, pokemon_fap);
  15. view_dispatcher_attach_to_gui(
  16. pokemon_fap->view_dispatcher,
  17. (Gui*)furi_record_open(RECORD_GUI),
  18. ViewDispatcherTypeFullscreen);
  19. // Set up defaults
  20. memcpy(&pokemon_fap->pins, &common_pinouts[PINOUT_ORIGINAL], sizeof(struct gblink_pins));
  21. /* Set up gui modules used. It would be nice if these could be allocated and
  22. * freed as needed, however, the scene manager still requires pointers that
  23. * get set up as a part of the scene. Therefore, individual scene's exit
  24. * callbacks cannot free the buffer.
  25. *
  26. * In order to do this properly, I think each scene, or maybe common to all
  27. * scenes, would end up needing to set a delayed callback of some kind. But
  28. * I'm not sure how to guarantee this gets called in a reasonable amount of
  29. * time.
  30. */
  31. pokemon_fap->text_input = text_input_alloc();
  32. pokemon_fap->submenu = submenu_alloc();
  33. pokemon_fap->variable_item_list = variable_item_list_alloc();
  34. pokemon_fap->dialog_ex = dialog_ex_alloc();
  35. // Set up menu scene
  36. pokemon_fap->scene_manager = scene_manager_alloc(&pokemon_scene_manager_handlers, pokemon_fap);
  37. view_dispatcher_add_view(
  38. pokemon_fap->view_dispatcher, AppViewMainMenu, submenu_get_view(pokemon_fap->submenu));
  39. scene_manager_next_scene(pokemon_fap->scene_manager, MainMenuScene);
  40. return pokemon_fap;
  41. }
  42. void free_app(PokemonFap* pokemon_fap) {
  43. furi_assert(pokemon_fap);
  44. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewMainMenu);
  45. view_dispatcher_free(pokemon_fap->view_dispatcher);
  46. // Free scenes
  47. scene_manager_free(pokemon_fap->scene_manager);
  48. // Free gui modules
  49. submenu_free(pokemon_fap->submenu);
  50. text_input_free(pokemon_fap->text_input);
  51. variable_item_list_free(pokemon_fap->variable_item_list);
  52. dialog_ex_free(pokemon_fap->dialog_ex);
  53. // Close records
  54. furi_record_close(RECORD_GUI);
  55. // Free rest
  56. free(pokemon_fap);
  57. pokemon_fap = NULL;
  58. }
  59. int32_t pokemon_app(void* p) {
  60. UNUSED(p);
  61. PokemonFap* pokemon_fap = pokemon_alloc();
  62. furi_hal_light_set(LightRed, 0x00);
  63. furi_hal_light_set(LightGreen, 0x00);
  64. furi_hal_light_set(LightBlue, 0x00);
  65. //switch view and run dispatcher
  66. view_dispatcher_run(pokemon_fap->view_dispatcher);
  67. // Free resources
  68. free_app(pokemon_fap);
  69. return 0;
  70. }