lfrfid-app-scene-write.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. 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", 90, 34, AlignCenter, AlignTop);
  11. popup->set_text(string_get_cstr(data_string), 90, 48, AlignCenter, AlignTop);
  12. popup->set_icon(0, 4, I_RFIDDolphinSend_98x60);
  13. app->view_controller.switch_to<PopupVM>();
  14. app->worker.start_write();
  15. }
  16. bool LfRfidAppSceneWrite::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  17. bool consumed = false;
  18. if(event->type == LfRfidApp::EventType::Tick) {
  19. RfidWorker::WriteResult result = app->worker.write();
  20. switch(result) {
  21. case RfidWorker::WriteResult::Nothing:
  22. notification_message(app->notification, &sequence_blink_yellow_10);
  23. break;
  24. case RfidWorker::WriteResult::Ok:
  25. notification_message(app->notification, &sequence_success);
  26. app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::WriteSuccess);
  27. break;
  28. case RfidWorker::WriteResult::NotWritable:
  29. if(!card_not_supported) {
  30. auto popup = app->view_controller.get<PopupVM>();
  31. popup->set_icon(0, 0, I_Empty_1x1);
  32. popup->set_header("Still trying to write", 64, 7, AlignCenter, AlignTop);
  33. popup->set_text(
  34. "This card may be protected\nor does not support this\ntype of writing",
  35. 64,
  36. 23,
  37. AlignCenter,
  38. AlignTop);
  39. card_not_supported = true;
  40. }
  41. notification_message(app->notification, &sequence_blink_red_10);
  42. break;
  43. }
  44. }
  45. return consumed;
  46. }
  47. void LfRfidAppSceneWrite::on_exit(LfRfidApp* app) {
  48. app->view_controller.get<PopupVM>()->clean();
  49. app->worker.stop_write();
  50. string_clear(data_string);
  51. }