lfrfid_app_scene_raw_info.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "lfrfid_app_scene_raw_info.h"
  2. #include "../view/elements/button_element.h"
  3. #include "../view/elements/icon_element.h"
  4. #include "../view/elements/string_element.h"
  5. static void ok_callback(void* context) {
  6. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  7. LfRfidApp::Event event;
  8. event.type = LfRfidApp::EventType::Next;
  9. app->view_controller.send_event(&event);
  10. }
  11. static void back_callback(void* context) {
  12. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  13. LfRfidApp::Event event;
  14. event.type = LfRfidApp::EventType::Back;
  15. app->view_controller.send_event(&event);
  16. }
  17. void LfRfidAppSceneRawInfo::on_enter(LfRfidApp* app, bool /* need_restore */) {
  18. string_init(string_info);
  19. auto container = app->view_controller.get<ContainerVM>();
  20. bool sd_exist = storage_sd_status(app->storage) == FSE_OK;
  21. if(!sd_exist) {
  22. auto icon = container->add<IconElement>();
  23. icon->set_icon(0, 0, &I_SDQuestion_35x43);
  24. auto line = container->add<StringElement>();
  25. line->set_text(
  26. "No SD card found.\nThis function will not\nwork without\nSD card.",
  27. 81,
  28. 4,
  29. 0,
  30. AlignCenter,
  31. AlignTop,
  32. FontSecondary);
  33. auto button = container->add<ButtonElement>();
  34. button->set_type(ButtonElement::Type::Left, "Back");
  35. button->set_callback(app, back_callback);
  36. } else {
  37. string_printf(
  38. string_info,
  39. "RAW RFID data reader\r\n"
  40. "1) Put the Flipper on your card\r\n"
  41. "2) Press OK\r\n"
  42. "3) Wait until data is read");
  43. auto line = container->add<StringElement>();
  44. line->set_text(string_get_cstr(string_info), 0, 1, 0, AlignLeft, AlignTop, FontSecondary);
  45. auto button = container->add<ButtonElement>();
  46. button->set_type(ButtonElement::Type::Center, "OK");
  47. button->set_callback(app, ok_callback);
  48. }
  49. app->view_controller.switch_to<ContainerVM>();
  50. }
  51. bool LfRfidAppSceneRawInfo::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  52. bool consumed = false;
  53. if(event->type == LfRfidApp::EventType::Next) {
  54. app->scene_controller.switch_to_scene({LfRfidApp::SceneType::RawRead});
  55. consumed = true;
  56. } else if(event->type == LfRfidApp::EventType::Back) {
  57. app->scene_controller.search_and_switch_to_previous_scene(
  58. {LfRfidApp::SceneType::ExtraActions});
  59. consumed = true;
  60. }
  61. return consumed;
  62. }
  63. void LfRfidAppSceneRawInfo::on_exit(LfRfidApp* app) {
  64. app->view_controller.get<ContainerVM>()->clean();
  65. string_clear(string_info);
  66. }