mifare_nested_scene_no_nonces_collected.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "../mifare_nested_i.h"
  2. void mifare_nested_scene_no_nonces_collected_widget_callback(
  3. GuiButtonType result,
  4. InputType type,
  5. void* context) {
  6. MifareNested* mifare_nested = context;
  7. if(type == InputTypeShort) {
  8. view_dispatcher_send_custom_event(mifare_nested->view_dispatcher, result);
  9. }
  10. }
  11. void mifare_nested_scene_no_nonces_collected_on_enter(void* context) {
  12. MifareNested* mifare_nested = context;
  13. Widget* widget = mifare_nested->widget;
  14. SaveNoncesResult_t* save_state = mifare_nested->save_state;
  15. notification_message(mifare_nested->notifications, &sequence_error);
  16. widget_add_icon_element(widget, 73, 12, &I_DolphinCry);
  17. widget_add_string_element(
  18. widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "No nonces collected");
  19. uint32_t index = 12;
  20. if(save_state->skipped) {
  21. char append_skipped[8] = {'s', 'e', 'c', 't', 'o', 'r', ' ', '\0'};
  22. if(save_state->skipped != 1) {
  23. append_skipped[6] = 's';
  24. }
  25. char draw_str[32] = {};
  26. snprintf(
  27. draw_str, sizeof(draw_str), "Skipped: %lu %s", save_state->skipped, append_skipped);
  28. widget_add_string_element(widget, 0, index, AlignLeft, AlignTop, FontSecondary, draw_str);
  29. widget_add_string_element(
  30. widget, 0, index + 10, AlignLeft, AlignTop, FontSecondary, "(already has keys)");
  31. index += 20;
  32. }
  33. if(save_state->invalid) {
  34. char append_invalid[8] = {'s', 'e', 'c', 't', 'o', 'r', ' ', '\0'};
  35. if(save_state->invalid != 1) {
  36. append_invalid[6] = 's';
  37. }
  38. char draw_str[32] = {};
  39. snprintf(
  40. draw_str, sizeof(draw_str), "Invalid: %lu %s", save_state->invalid, append_invalid);
  41. widget_add_string_element(widget, 0, index, AlignLeft, AlignTop, FontSecondary, draw_str);
  42. widget_add_string_element(
  43. widget, 0, index + 10, AlignLeft, AlignTop, FontSecondary, "(can't auth)");
  44. }
  45. free(save_state);
  46. widget_add_button_element(
  47. widget,
  48. GuiButtonTypeLeft,
  49. "Back",
  50. mifare_nested_scene_no_nonces_collected_widget_callback,
  51. mifare_nested);
  52. // Setup and start worker
  53. view_dispatcher_switch_to_view(mifare_nested->view_dispatcher, MifareNestedViewWidget);
  54. }
  55. bool mifare_nested_scene_no_nonces_collected_on_event(void* context, SceneManagerEvent event) {
  56. MifareNested* mifare_nested = context;
  57. bool consumed = false;
  58. if(event.type == SceneManagerEventTypeCustom) {
  59. if(event.event == GuiButtonTypeCenter || event.event == GuiButtonTypeLeft) {
  60. scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
  61. consumed = true;
  62. }
  63. } else if(event.type == SceneManagerEventTypeBack) {
  64. scene_manager_search_and_switch_to_previous_scene(mifare_nested->scene_manager, 0);
  65. consumed = true;
  66. }
  67. return consumed;
  68. }
  69. void mifare_nested_scene_no_nonces_collected_on_exit(void* context) {
  70. MifareNested* mifare_nested = context;
  71. widget_reset(mifare_nested->widget);
  72. }