lfrfid_app_scene_write.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "lfrfid_app_scene_write.h"
  2. void LfRfidAppSceneWrite::on_enter(LfRfidApp* app, bool need_restore) {
  3. card_not_supported = false;
  4. string_init(data_string);
  5. const uint8_t* data = app->worker.key.get_data();
  6. for(uint8_t i = 0; i < app->worker.key.get_type_data_count(); i++) {
  7. string_cat_printf(data_string, "%02X", data[i]);
  8. }
  9. auto popup = app->view_controller.get<PopupVM>();
  10. popup->set_header("Writing", 89, 30, AlignCenter, AlignTop);
  11. if(strlen(app->worker.key.get_name())) {
  12. popup->set_text(app->worker.key.get_name(), 89, 43, AlignCenter, AlignTop);
  13. } else {
  14. popup->set_text(string_get_cstr(data_string), 89, 43, AlignCenter, AlignTop);
  15. }
  16. popup->set_icon(0, 3, &I_RFIDDolphinSend_97x61);
  17. app->view_controller.switch_to<PopupVM>();
  18. app->worker.start_write();
  19. }
  20. bool LfRfidAppSceneWrite::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  21. bool consumed = false;
  22. if(event->type == LfRfidApp::EventType::Tick) {
  23. RfidWorker::WriteResult result = app->worker.write();
  24. switch(result) {
  25. case RfidWorker::WriteResult::Nothing:
  26. notification_message(app->notification, &sequence_blink_yellow_10);
  27. break;
  28. case RfidWorker::WriteResult::Ok:
  29. notification_message(app->notification, &sequence_success);
  30. app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::WriteSuccess);
  31. break;
  32. case RfidWorker::WriteResult::NotWritable:
  33. if(!card_not_supported) {
  34. auto popup = app->view_controller.get<PopupVM>();
  35. popup->set_icon(0, 0, NULL);
  36. popup->set_header("Still trying to write", 64, 7, AlignCenter, AlignTop);
  37. popup->set_text(
  38. "This card may be protected\nor does not support this\ntype of writing",
  39. 64,
  40. 23,
  41. AlignCenter,
  42. AlignTop);
  43. card_not_supported = true;
  44. }
  45. notification_message(app->notification, &sequence_blink_red_10);
  46. break;
  47. }
  48. }
  49. return consumed;
  50. }
  51. void LfRfidAppSceneWrite::on_exit(LfRfidApp* app) {
  52. app->view_controller.get<PopupVM>()->clean();
  53. app->worker.stop_write();
  54. string_clear(data_string);
  55. }