picopass_scene_read_factory_success.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "../picopass_i.h"
  2. #include <dolphin/dolphin.h>
  3. #include "../picopass_keys.h"
  4. void picopass_scene_read_factory_success_widget_callback(
  5. GuiButtonType result,
  6. InputType type,
  7. void* context) {
  8. furi_assert(context);
  9. Picopass* picopass = context;
  10. if(type == InputTypeShort) {
  11. view_dispatcher_send_custom_event(picopass->view_dispatcher, result);
  12. }
  13. }
  14. void picopass_scene_read_factory_success_on_enter(void* context) {
  15. Picopass* picopass = context;
  16. FuriString* title = furi_string_alloc_set("Factory Default");
  17. FuriString* subtitle = furi_string_alloc_set("");
  18. dolphin_deed(DolphinDeedNfcReadSuccess);
  19. // Send notification
  20. notification_message(picopass->notifications, &sequence_success);
  21. // Setup view
  22. Widget* widget = picopass->widget;
  23. //PicopassPacs* pacs = &picopass->dev->dev_data.pacs;
  24. PicopassBlock* card_data = picopass->dev->dev_data.card_data;
  25. uint8_t* configBlock = card_data[PICOPASS_CONFIG_BLOCK_INDEX].data;
  26. uint8_t fuses = configBlock[7];
  27. if((fuses & 0x80) == 0x80) {
  28. furi_string_cat_printf(subtitle, "Personalization mode");
  29. } else {
  30. furi_string_cat_printf(subtitle, "Application mode");
  31. }
  32. widget_add_button_element(
  33. widget,
  34. GuiButtonTypeCenter,
  35. "Write Standard iClass Key",
  36. picopass_scene_read_factory_success_widget_callback,
  37. picopass);
  38. widget_add_string_element(
  39. widget, 64, 5, AlignCenter, AlignCenter, FontSecondary, furi_string_get_cstr(title));
  40. widget_add_string_element(
  41. widget, 64, 20, AlignCenter, AlignCenter, FontPrimary, furi_string_get_cstr(subtitle));
  42. furi_string_free(title);
  43. furi_string_free(subtitle);
  44. view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewWidget);
  45. }
  46. bool picopass_scene_read_factory_success_on_event(void* context, SceneManagerEvent event) {
  47. Picopass* picopass = context;
  48. bool consumed = false;
  49. if(event.type == SceneManagerEventTypeCustom) {
  50. if(event.event == GuiButtonTypeLeft) {
  51. consumed = scene_manager_previous_scene(picopass->scene_manager);
  52. } else if(event.event == GuiButtonTypeCenter) {
  53. memcpy(
  54. picopass->write_key_context.key_to_write, picopass_iclass_key, PICOPASS_BLOCK_LEN);
  55. picopass->write_key_context.is_elite = false;
  56. scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
  57. consumed = true;
  58. }
  59. } else if(event.type == SceneManagerEventTypeBack) {
  60. scene_manager_search_and_switch_to_previous_scene(
  61. picopass->scene_manager, PicopassSceneStart);
  62. consumed = true;
  63. }
  64. return consumed;
  65. }
  66. void picopass_scene_read_factory_success_on_exit(void* context) {
  67. Picopass* picopass = context;
  68. // Clear view
  69. widget_reset(picopass->widget);
  70. }