flipbip.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "flipbip.h"
  2. bool flipbip_custom_event_callback(void* context, uint32_t event) {
  3. furi_assert(context);
  4. FlipBip* app = context;
  5. return scene_manager_handle_custom_event(app->scene_manager, event);
  6. }
  7. void flipbip_tick_event_callback(void* context) {
  8. furi_assert(context);
  9. FlipBip* app = context;
  10. scene_manager_handle_tick_event(app->scene_manager);
  11. }
  12. //leave app if back button pressed
  13. bool flipbip_navigation_event_callback(void* context) {
  14. furi_assert(context);
  15. FlipBip* app = context;
  16. return scene_manager_handle_back_event(app->scene_manager);
  17. }
  18. FlipBip* flipbip_app_alloc() {
  19. FlipBip* app = malloc(sizeof(FlipBip));
  20. app->gui = furi_record_open(RECORD_GUI);
  21. app->notification = furi_record_open(RECORD_NOTIFICATION);
  22. //Turn backlight on, believe me this makes testing your app easier
  23. notification_message(app->notification, &sequence_display_backlight_on);
  24. //Scene additions
  25. app->view_dispatcher = view_dispatcher_alloc();
  26. view_dispatcher_enable_queue(app->view_dispatcher);
  27. app->scene_manager = scene_manager_alloc(&flipbip_scene_handlers, app);
  28. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  29. view_dispatcher_set_navigation_event_callback(
  30. app->view_dispatcher, flipbip_navigation_event_callback);
  31. view_dispatcher_set_tick_event_callback(
  32. app->view_dispatcher, flipbip_tick_event_callback, 100);
  33. view_dispatcher_set_custom_event_callback(app->view_dispatcher, flipbip_custom_event_callback);
  34. app->submenu = submenu_alloc();
  35. // Settings
  36. app->haptic = 1;
  37. app->led = 1;
  38. app->bip39_strength = 2; // 256 bits (24 words)
  39. app->bip44_coin = FlipBipCoinBTC0; // 0 (BTC)
  40. app->overwrite_saved_seed = 0;
  41. view_dispatcher_add_view(
  42. app->view_dispatcher, FlipBipViewIdMenu, submenu_get_view(app->submenu));
  43. app->flipbip_startscreen = flipbip_startscreen_alloc();
  44. view_dispatcher_add_view(
  45. app->view_dispatcher,
  46. FlipBipViewIdStartscreen,
  47. flipbip_startscreen_get_view(app->flipbip_startscreen));
  48. app->flipbip_scene_1 = flipbip_scene_1_alloc();
  49. view_dispatcher_add_view(
  50. app->view_dispatcher, FlipBipViewIdScene1, flipbip_scene_1_get_view(app->flipbip_scene_1));
  51. app->variable_item_list = variable_item_list_alloc();
  52. view_dispatcher_add_view(
  53. app->view_dispatcher,
  54. FlipBipViewIdSettings,
  55. variable_item_list_get_view(app->variable_item_list));
  56. //End Scene Additions
  57. return app;
  58. }
  59. void flipbip_app_free(FlipBip* app) {
  60. furi_assert(app);
  61. // Scene manager
  62. scene_manager_free(app->scene_manager);
  63. // View Dispatcher
  64. view_dispatcher_remove_view(app->view_dispatcher, FlipBipViewIdMenu);
  65. view_dispatcher_remove_view(app->view_dispatcher, FlipBipViewIdScene1);
  66. // view_dispatcher_remove_view(app->view_dispatcher, FlipBipViewIdScene2);
  67. view_dispatcher_remove_view(app->view_dispatcher, FlipBipViewIdSettings);
  68. submenu_free(app->submenu);
  69. view_dispatcher_free(app->view_dispatcher);
  70. furi_record_close(RECORD_GUI);
  71. app->gui = NULL;
  72. app->notification = NULL;
  73. //Remove whatever is left
  74. free(app);
  75. }
  76. int32_t flipbip_app(void* p) {
  77. UNUSED(p);
  78. FlipBip* app = flipbip_app_alloc();
  79. // Disabled because causes exit on customer firmwares such as RM
  80. /*if(!furi_hal_region_is_provisioned()) {
  81. flipbip_app_free(app);
  82. return 1;
  83. }*/
  84. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  85. scene_manager_next_scene(
  86. app->scene_manager, FlipBipSceneStartscreen); //Start with start screen
  87. //scene_manager_next_scene(app->scene_manager, FlipBipSceneMenu); //if you want to directly start with Menu
  88. furi_hal_power_suppress_charge_enter();
  89. view_dispatcher_run(app->view_dispatcher);
  90. furi_hal_power_suppress_charge_exit();
  91. flipbip_app_free(app);
  92. return 0;
  93. }