ibutton-scene-read.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "ibutton-scene-read.h"
  2. #include "../ibutton-app.h"
  3. #include "../ibutton-view-manager.h"
  4. #include "../ibutton-event.h"
  5. void iButtonSceneRead::on_enter(iButtonApp* app) {
  6. iButtonAppViewManager* view_manager = app->get_view_manager();
  7. Popup* popup = view_manager->get_popup();
  8. popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
  9. popup_set_text(popup, "waiting\nfor key ...", 95, 30, AlignCenter, AlignTop);
  10. popup_set_icon(popup, 0, 5, I_DolphinWait_61x59);
  11. view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
  12. app->get_key()->set_name("");
  13. app->get_key_worker()->start_read();
  14. }
  15. bool iButtonSceneRead::on_event(iButtonApp* app, iButtonEvent* event) {
  16. bool consumed = false;
  17. if(event->type == iButtonEvent::Type::EventTypeTick) {
  18. consumed = true;
  19. app->notify_red_blink();
  20. switch(app->get_key_worker()->read(app->get_key())) {
  21. case KeyReader::Error::EMPTY:
  22. break;
  23. case KeyReader::Error::OK:
  24. app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
  25. break;
  26. case KeyReader::Error::CRC_ERROR:
  27. app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
  28. break;
  29. case KeyReader::Error::NOT_ARE_KEY:
  30. app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
  31. break;
  32. }
  33. }
  34. return consumed;
  35. }
  36. void iButtonSceneRead::on_exit(iButtonApp* app) {
  37. app->get_key_worker()->stop_read();
  38. Popup* popup = app->get_view_manager()->get_popup();
  39. popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
  40. popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
  41. popup_set_icon(popup, 0, 0, I_Empty_1x1);
  42. }