desktop_helpers.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <notification/notification.h>
  2. #include <notification/notification_messages.h>
  3. #include <stddef.h>
  4. #include <furi.h>
  5. #include <furi_hal.h>
  6. #include <gui/gui.h>
  7. #include "desktop_helpers.h"
  8. #include "desktop_i.h"
  9. static const NotificationSequence sequence_pin_fail = {
  10. &message_display_on,
  11. &message_red_255,
  12. &message_vibro_on,
  13. &message_delay_100,
  14. &message_vibro_off,
  15. &message_red_0,
  16. &message_delay_250,
  17. &message_red_255,
  18. &message_vibro_on,
  19. &message_delay_100,
  20. &message_vibro_off,
  21. &message_red_0,
  22. NULL,
  23. };
  24. static const uint8_t desktop_helpers_fails_timeout[] = {
  25. 0,
  26. 0,
  27. 0,
  28. 0,
  29. 30,
  30. 60,
  31. 90,
  32. 120,
  33. 150,
  34. 180,
  35. /* +60 for every next fail */
  36. };
  37. void desktop_helpers_emit_error_notification() {
  38. NotificationApp* notification = furi_record_open("notification");
  39. notification_message(notification, &sequence_pin_fail);
  40. furi_record_close("notification");
  41. }
  42. void desktop_helpers_lock_system(Desktop* desktop, bool hard_lock) {
  43. view_port_enabled_set(desktop->lock_viewport, true);
  44. if(hard_lock) {
  45. furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
  46. furi_hal_usb_disable();
  47. }
  48. Gui* gui = furi_record_open("gui");
  49. gui_set_lockdown(gui, true);
  50. furi_record_close("gui");
  51. }
  52. void desktop_helpers_unlock_system(Desktop* desktop) {
  53. furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
  54. furi_hal_usb_enable();
  55. view_port_enabled_set(desktop->lock_viewport, false);
  56. Gui* gui = furi_record_open("gui");
  57. gui_set_lockdown(gui, false);
  58. furi_record_close("gui");
  59. }
  60. uint32_t desktop_helpers_get_pin_fail_timeout(uint32_t pin_fails) {
  61. uint32_t pin_timeout = 0;
  62. uint32_t max_index = COUNT_OF(desktop_helpers_fails_timeout) - 1;
  63. if(pin_fails <= max_index) {
  64. pin_timeout = desktop_helpers_fails_timeout[pin_fails];
  65. } else {
  66. pin_timeout = desktop_helpers_fails_timeout[max_index] + (pin_fails - max_index) * 60;
  67. }
  68. return pin_timeout;
  69. }