lfrfid_app_scene_delete_confirm.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "lfrfid_app_scene_delete_confirm.h"
  2. #include "../view/elements/button_element.h"
  3. #include "../view/elements/icon_element.h"
  4. #include "../view/elements/string_element.h"
  5. void LfRfidAppSceneDeleteConfirm::on_enter(LfRfidApp* app, bool need_restore) {
  6. string_init(string_data);
  7. string_init(string_decrypted);
  8. string_init(string_header);
  9. auto container = app->view_controller.get<ContainerVM>();
  10. auto button = container->add<ButtonElement>();
  11. button->set_type(ButtonElement::Type::Left, "Back");
  12. button->set_callback(app, LfRfidAppSceneDeleteConfirm::back_callback);
  13. button = container->add<ButtonElement>();
  14. button->set_type(ButtonElement::Type::Right, "Delete");
  15. button->set_callback(app, LfRfidAppSceneDeleteConfirm::delete_callback);
  16. auto line_1 = container->add<StringElement>();
  17. auto line_2 = container->add<StringElement>();
  18. auto line_3 = container->add<StringElement>();
  19. auto line_4 = container->add<StringElement>();
  20. RfidKey& key = app->worker.key;
  21. const uint8_t* data = key.get_data();
  22. for(uint8_t i = 0; i < key.get_type_data_count(); i++) {
  23. if(i != 0) {
  24. string_cat_printf(string_data, " ");
  25. }
  26. string_cat_printf(string_data, "%02X", data[i]);
  27. }
  28. string_printf(string_header, "Delete %s?", key.get_name());
  29. line_1->set_text(
  30. string_get_cstr(string_header), 64, 19, 128 - 2, AlignCenter, AlignBottom, FontPrimary);
  31. line_2->set_text(
  32. string_get_cstr(string_data), 64, 29, 0, AlignCenter, AlignBottom, FontSecondary);
  33. switch(key.get_type()) {
  34. case LfrfidKeyType::KeyEM4100:
  35. string_printf(
  36. string_decrypted, "%03u,%05u", data[2], (uint16_t)((data[3] << 8) | (data[4])));
  37. break;
  38. case LfrfidKeyType::KeyH10301:
  39. case LfrfidKeyType::KeyI40134:
  40. string_printf(
  41. string_decrypted, "FC: %u ID: %u", data[0], (uint16_t)((data[1] << 8) | (data[2])));
  42. break;
  43. }
  44. line_3->set_text(
  45. string_get_cstr(string_decrypted), 64, 39, 0, AlignCenter, AlignBottom, FontSecondary);
  46. line_4->set_text(
  47. lfrfid_key_get_type_string(key.get_type()),
  48. 64,
  49. 49,
  50. 0,
  51. AlignCenter,
  52. AlignBottom,
  53. FontSecondary);
  54. app->view_controller.switch_to<ContainerVM>();
  55. }
  56. bool LfRfidAppSceneDeleteConfirm::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  57. bool consumed = false;
  58. if(event->type == LfRfidApp::EventType::Next) {
  59. app->delete_key(&app->worker.key);
  60. app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::DeleteSuccess);
  61. consumed = true;
  62. } else if(event->type == LfRfidApp::EventType::Stay) {
  63. app->scene_controller.switch_to_previous_scene();
  64. consumed = true;
  65. } else if(event->type == LfRfidApp::EventType::Back) {
  66. consumed = true;
  67. }
  68. return consumed;
  69. }
  70. void LfRfidAppSceneDeleteConfirm::on_exit(LfRfidApp* app) {
  71. app->view_controller.get<ContainerVM>()->clean();
  72. string_clear(string_data);
  73. string_clear(string_decrypted);
  74. string_clear(string_header);
  75. }
  76. void LfRfidAppSceneDeleteConfirm::back_callback(void* context) {
  77. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  78. LfRfidApp::Event event;
  79. event.type = LfRfidApp::EventType::Stay;
  80. app->view_controller.send_event(&event);
  81. }
  82. void LfRfidAppSceneDeleteConfirm::delete_callback(void* context) {
  83. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  84. LfRfidApp::Event event;
  85. event.type = LfRfidApp::EventType::Next;
  86. app->view_controller.send_event(&event);
  87. }