lfrfid_app_scene_read_success.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "lfrfid_app_scene_read_success.h"
  2. #include "../view/elements/button_element.h"
  3. #include "../view/elements/icon_element.h"
  4. #include "../view/elements/string_element.h"
  5. void LfRfidAppSceneReadSuccess::on_enter(LfRfidApp* app, bool /* need_restore */) {
  6. string_init(string_info);
  7. string_init(string_header);
  8. string_init_printf(
  9. string_header,
  10. "%s[%s]",
  11. protocol_dict_get_name(app->dict, app->protocol_id),
  12. protocol_dict_get_manufacturer(app->dict, app->protocol_id));
  13. size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id);
  14. uint8_t* data = (uint8_t*)malloc(size);
  15. protocol_dict_get_data(app->dict, app->protocol_id, data, size);
  16. for(uint8_t i = 0; i < size; i++) {
  17. if(i != 0) {
  18. string_cat_printf(string_info, " ");
  19. }
  20. if(i >= 9) {
  21. string_cat_printf(string_info, "...");
  22. break;
  23. } else {
  24. string_cat_printf(string_info, "%02X", data[i]);
  25. }
  26. }
  27. free(data);
  28. string_t render_data;
  29. string_init(render_data);
  30. protocol_dict_render_brief_data(app->dict, render_data, app->protocol_id);
  31. string_cat_printf(string_info, "\r\n%s", string_get_cstr(render_data));
  32. string_clear(render_data);
  33. auto container = app->view_controller.get<ContainerVM>();
  34. auto button = container->add<ButtonElement>();
  35. button->set_type(ButtonElement::Type::Left, "Retry");
  36. button->set_callback(app, LfRfidAppSceneReadSuccess::back_callback);
  37. button = container->add<ButtonElement>();
  38. button->set_type(ButtonElement::Type::Right, "More");
  39. button->set_callback(app, LfRfidAppSceneReadSuccess::more_callback);
  40. auto header = container->add<StringElement>();
  41. header->set_text(string_get_cstr(string_header), 0, 2, 0, AlignLeft, AlignTop, FontPrimary);
  42. auto text = container->add<StringElement>();
  43. text->set_text(string_get_cstr(string_info), 0, 16, 0, AlignLeft, AlignTop, FontSecondary);
  44. app->view_controller.switch_to<ContainerVM>();
  45. notification_message_block(app->notification, &sequence_set_green_255);
  46. }
  47. bool LfRfidAppSceneReadSuccess::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  48. bool consumed = false;
  49. if(event->type == LfRfidApp::EventType::Next) {
  50. app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::ReadKeyMenu);
  51. consumed = true;
  52. } else if(event->type == LfRfidApp::EventType::Retry) {
  53. app->scene_controller.switch_to_next_scene({LfRfidApp::SceneType::RetryConfirm});
  54. consumed = true;
  55. } else if(event->type == LfRfidApp::EventType::Back) {
  56. app->scene_controller.switch_to_next_scene({LfRfidApp::SceneType::ExitConfirm});
  57. consumed = true;
  58. }
  59. return consumed;
  60. }
  61. void LfRfidAppSceneReadSuccess::on_exit(LfRfidApp* app) {
  62. notification_message_block(app->notification, &sequence_reset_green);
  63. app->view_controller.get<ContainerVM>()->clean();
  64. string_clear(string_info);
  65. string_clear(string_header);
  66. }
  67. void LfRfidAppSceneReadSuccess::back_callback(void* context) {
  68. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  69. LfRfidApp::Event event;
  70. event.type = LfRfidApp::EventType::Retry;
  71. app->view_controller.send_event(&event);
  72. }
  73. void LfRfidAppSceneReadSuccess::more_callback(void* context) {
  74. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  75. LfRfidApp::Event event;
  76. event.type = LfRfidApp::EventType::Next;
  77. app->view_controller.send_event(&event);
  78. }