ibutton_scene_read.cpp 1.8 KB

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