desktop_scene_locked.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "../desktop_i.h"
  2. #include "../views/desktop_locked.h"
  3. #include "desktop/helpers/desktop_animation.h"
  4. #include "desktop/views/desktop_main.h"
  5. void desktop_scene_locked_callback(DesktopLockedEvent event, void* context) {
  6. Desktop* desktop = (Desktop*)context;
  7. view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
  8. }
  9. static void desktop_scene_locked_animation_changed_callback(void* context) {
  10. furi_assert(context);
  11. Desktop* desktop = context;
  12. view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopMainEventUpdateAnimation);
  13. }
  14. void desktop_scene_locked_on_enter(void* context) {
  15. Desktop* desktop = (Desktop*)context;
  16. DesktopLockedView* locked_view = desktop->locked_view;
  17. desktop_locked_set_callback(locked_view, desktop_scene_locked_callback, desktop);
  18. desktop_locked_reset_door_pos(locked_view);
  19. desktop_locked_update_hint_timeout(locked_view);
  20. desktop_animation_set_animation_changed_callback(
  21. desktop->animation, desktop_scene_locked_animation_changed_callback, desktop);
  22. bool status_bar_background_black = false;
  23. const Icon* icon =
  24. desktop_animation_get_animation(desktop->animation, &status_bar_background_black);
  25. desktop_locked_set_dolphin_animation(locked_view, icon, status_bar_background_black);
  26. uint32_t state = scene_manager_get_scene_state(desktop->scene_manager, DesktopViewLocked);
  27. desktop_locked_with_pin(desktop->locked_view, state == DesktopLockedWithPin);
  28. view_port_enabled_set(desktop->lock_viewport, true);
  29. osTimerStart(locked_view->timer, osKernelGetTickFreq() / 16);
  30. view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewLocked);
  31. }
  32. static bool desktop_scene_locked_check_pin(Desktop* desktop, DesktopMainEvent event) {
  33. bool match = false;
  34. size_t length = desktop->pincode_buffer.length;
  35. length = code_input_push(desktop->pincode_buffer.data, length, event);
  36. desktop->pincode_buffer.length = length;
  37. match = code_input_compare(
  38. desktop->pincode_buffer.data,
  39. length,
  40. desktop->settings.pincode.data,
  41. desktop->settings.pincode.length);
  42. if(match) {
  43. desktop->pincode_buffer.length = 0;
  44. furi_hal_usb_enable();
  45. furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
  46. desktop_main_unlocked(desktop->main_view);
  47. }
  48. return match;
  49. }
  50. bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
  51. Desktop* desktop = (Desktop*)context;
  52. bool consumed = false;
  53. if(event.type == SceneManagerEventTypeCustom) {
  54. switch(event.event) {
  55. case DesktopLockedEventUnlock:
  56. scene_manager_set_scene_state(
  57. desktop->scene_manager, DesktopSceneMain, DesktopMainEventUnlocked);
  58. scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
  59. consumed = true;
  60. break;
  61. case DesktopLockedEventUpdate:
  62. desktop_locked_manage_redraw(desktop->locked_view);
  63. consumed = true;
  64. break;
  65. case DesktopLockedEventInputReset:
  66. desktop->pincode_buffer.length = 0;
  67. break;
  68. case DesktopMainEventUpdateAnimation: {
  69. bool status_bar_background_black = false;
  70. const Icon* icon =
  71. desktop_animation_get_animation(desktop->animation, &status_bar_background_black);
  72. desktop_locked_set_dolphin_animation(
  73. desktop->locked_view, icon, status_bar_background_black);
  74. consumed = true;
  75. break;
  76. }
  77. default:
  78. if(desktop_scene_locked_check_pin(desktop, event.event)) {
  79. scene_manager_set_scene_state(
  80. desktop->scene_manager, DesktopSceneMain, DesktopMainEventUnlocked);
  81. scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
  82. consumed = true;
  83. }
  84. break;
  85. }
  86. }
  87. return consumed;
  88. }
  89. void desktop_scene_locked_on_exit(void* context) {
  90. Desktop* desktop = (Desktop*)context;
  91. desktop_animation_set_animation_changed_callback(desktop->animation, NULL, NULL);
  92. desktop_locked_reset_counter(desktop->locked_view);
  93. osTimerStop(desktop->locked_view->timer);
  94. }