desktop_scene_locked.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include <furi.h>
  2. #include <furi_hal.h>
  3. #include <gui/scene_manager.h>
  4. #include <gui/view_stack.h>
  5. #include <stdint.h>
  6. #include <portmacro.h>
  7. #include "../desktop.h"
  8. #include "../desktop_i.h"
  9. #include "../helpers/pin_lock.h"
  10. #include "../animations/animation_manager.h"
  11. #include "../views/desktop_events.h"
  12. #include "../views/desktop_view_pin_input.h"
  13. #include "../views/desktop_view_locked.h"
  14. #include "desktop_scene.h"
  15. #include "desktop_scene_i.h"
  16. #define WRONG_PIN_HEADER_TIMEOUT 3000
  17. #define INPUT_PIN_VIEW_TIMEOUT 15000
  18. static void desktop_scene_locked_callback(DesktopEvent event, void* context) {
  19. Desktop* desktop = (Desktop*)context;
  20. view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
  21. }
  22. static void desktop_scene_locked_new_idle_animation_callback(void* context) {
  23. furi_assert(context);
  24. Desktop* desktop = context;
  25. view_dispatcher_send_custom_event(
  26. desktop->view_dispatcher, DesktopAnimationEventNewIdleAnimation);
  27. }
  28. void desktop_scene_locked_on_enter(void* context) {
  29. Desktop* desktop = (Desktop*)context;
  30. // callbacks for 1-st layer
  31. animation_manager_set_new_idle_callback(
  32. desktop->animation_manager, desktop_scene_locked_new_idle_animation_callback);
  33. animation_manager_set_check_callback(desktop->animation_manager, NULL);
  34. animation_manager_set_interact_callback(desktop->animation_manager, NULL);
  35. // callbacks for 2-nd layer
  36. desktop_view_locked_set_callback(desktop->locked_view, desktop_scene_locked_callback, desktop);
  37. bool switch_to_timeout_scene = false;
  38. uint32_t state = scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLocked);
  39. if(state == SCENE_LOCKED_FIRST_ENTER) {
  40. bool pin_locked = desktop_pin_lock_is_locked();
  41. view_port_enabled_set(desktop->lock_viewport, true);
  42. Gui* gui = furi_record_open("gui");
  43. gui_set_lockdown(gui, true);
  44. furi_record_close("gui");
  45. if(pin_locked) {
  46. LOAD_DESKTOP_SETTINGS(&desktop->settings);
  47. desktop_view_locked_lock(desktop->locked_view, true);
  48. uint32_t pin_timeout = desktop_pin_lock_get_fail_timeout();
  49. if(pin_timeout > 0) {
  50. scene_manager_set_scene_state(
  51. desktop->scene_manager, DesktopScenePinTimeout, pin_timeout);
  52. switch_to_timeout_scene = true;
  53. } else {
  54. desktop_view_locked_close_doors(desktop->locked_view);
  55. }
  56. } else {
  57. desktop_view_locked_lock(desktop->locked_view, false);
  58. desktop_view_locked_close_doors(desktop->locked_view);
  59. }
  60. scene_manager_set_scene_state(
  61. desktop->scene_manager, DesktopSceneLocked, SCENE_LOCKED_REPEAT_ENTER);
  62. }
  63. if(switch_to_timeout_scene) {
  64. scene_manager_next_scene(desktop->scene_manager, DesktopScenePinTimeout);
  65. } else {
  66. view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLocked);
  67. }
  68. }
  69. bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
  70. Desktop* desktop = (Desktop*)context;
  71. bool consumed = false;
  72. if(event.type == SceneManagerEventTypeCustom) {
  73. switch(event.event) {
  74. case DesktopLockedEventUnlocked:
  75. desktop_unlock(desktop);
  76. consumed = true;
  77. break;
  78. case DesktopLockedEventUpdate:
  79. if(desktop_view_locked_is_locked_hint_visible(desktop->locked_view)) {
  80. notification_message(desktop->notification, &sequence_display_backlight_off);
  81. }
  82. desktop_view_locked_update(desktop->locked_view);
  83. consumed = true;
  84. break;
  85. case DesktopLockedEventShowPinInput:
  86. scene_manager_next_scene(desktop->scene_manager, DesktopScenePinInput);
  87. consumed = true;
  88. break;
  89. case DesktopAnimationEventNewIdleAnimation:
  90. animation_manager_new_idle_process(desktop->animation_manager);
  91. consumed = true;
  92. break;
  93. }
  94. }
  95. return consumed;
  96. }
  97. void desktop_scene_locked_on_exit(void* context) {
  98. UNUSED(context);
  99. }