flipbip39.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "flipbip39.h"
  2. bool flipbip39_custom_event_callback(void* context, uint32_t event) {
  3. furi_assert(context);
  4. FlipBip39* app = context;
  5. return scene_manager_handle_custom_event(app->scene_manager, event);
  6. }
  7. void flipbip39_tick_event_callback(void* context) {
  8. furi_assert(context);
  9. FlipBip39* app = context;
  10. scene_manager_handle_tick_event(app->scene_manager);
  11. }
  12. //leave app if back button pressed
  13. bool flipbip39_navigation_event_callback(void* context) {
  14. furi_assert(context);
  15. FlipBip39* app = context;
  16. return scene_manager_handle_back_event(app->scene_manager);
  17. }
  18. FlipBip39* flipbip39_app_alloc() {
  19. FlipBip39* app = malloc(sizeof(FlipBip39));
  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(&flipbip39_scene_handlers, app);
  28. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  29. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, flipbip39_navigation_event_callback);
  30. view_dispatcher_set_tick_event_callback(app->view_dispatcher, flipbip39_tick_event_callback, 100);
  31. view_dispatcher_set_custom_event_callback(app->view_dispatcher, flipbip39_custom_event_callback);
  32. app->submenu = submenu_alloc();
  33. app->haptic = 1;
  34. app->speaker = 1;
  35. app->led = 1;
  36. app->bip39_strength = 1; // 256 bits (24 words)
  37. view_dispatcher_add_view(app->view_dispatcher, FlipBip39ViewIdMenu, submenu_get_view(app->submenu));
  38. app->flipbip39_startscreen = flipbip39_startscreen_alloc();
  39. view_dispatcher_add_view(app->view_dispatcher, FlipBip39ViewIdStartscreen, flipbip39_startscreen_get_view(app->flipbip39_startscreen));
  40. app->flipbip39_scene_1 = flipbip39_scene_1_alloc();
  41. view_dispatcher_add_view(app->view_dispatcher, FlipBip39ViewIdScene1, flipbip39_scene_1_get_view(app->flipbip39_scene_1));
  42. app->flipbip39_scene_2 = flipbip39_scene_2_alloc();
  43. view_dispatcher_add_view(app->view_dispatcher, FlipBip39ViewIdScene2, flipbip39_scene_2_get_view(app->flipbip39_scene_2));
  44. app->variable_item_list = variable_item_list_alloc();
  45. view_dispatcher_add_view(app->view_dispatcher, FlipBip39ViewIdSettings, variable_item_list_get_view(app->variable_item_list));
  46. //End Scene Additions
  47. return app;
  48. }
  49. void flipbip39_app_free(FlipBip39* app) {
  50. furi_assert(app);
  51. // Scene manager
  52. scene_manager_free(app->scene_manager);
  53. // View Dispatcher
  54. view_dispatcher_remove_view(app->view_dispatcher, FlipBip39ViewIdMenu);
  55. view_dispatcher_remove_view(app->view_dispatcher, FlipBip39ViewIdScene1);
  56. view_dispatcher_remove_view(app->view_dispatcher, FlipBip39ViewIdScene2);
  57. view_dispatcher_remove_view(app->view_dispatcher, FlipBip39ViewIdSettings);
  58. submenu_free(app->submenu);
  59. view_dispatcher_free(app->view_dispatcher);
  60. furi_record_close(RECORD_GUI);
  61. app->gui = NULL;
  62. app->notification = NULL;
  63. //Remove whatever is left
  64. free(app);
  65. }
  66. int32_t flipbip39_app(void* p) {
  67. UNUSED(p);
  68. FlipBip39* app = flipbip39_app_alloc();
  69. // Disabled because causes exit on customer firmwares such as RM
  70. /*if(!furi_hal_region_is_provisioned()) {
  71. flipbip39_app_free(app);
  72. return 1;
  73. }*/
  74. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  75. scene_manager_next_scene(app->scene_manager, FlipBip39SceneStartscreen); //Start with start screen
  76. //scene_manager_next_scene(app->scene_manager, FlipBip39SceneMenu); //if you want to directly start with Menu
  77. furi_hal_power_suppress_charge_enter();
  78. view_dispatcher_run(app->view_dispatcher);
  79. furi_hal_power_suppress_charge_exit();
  80. flipbip39_app_free(app);
  81. return 0;
  82. }