mag_scene_emulate.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "../mag_i.h"
  2. void mag_scene_emulate_on_enter(void* context) {
  3. Mag* mag = context;
  4. Widget* widget = mag->widget;
  5. FuriString* tmp_str;
  6. tmp_str = furi_string_alloc();
  7. // Use strlcpy instead perhaps, to truncate to screen width, then add ellipses if needed?
  8. furi_string_printf(tmp_str, "%s\r\n", mag->mag_dev->dev_name);
  9. widget_add_icon_element(widget, 1, 1, &I_mag_10px);
  10. widget_add_string_element(
  11. widget, 13, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp_str));
  12. furi_string_reset(tmp_str);
  13. furi_string_printf(tmp_str, furi_string_get_cstr(mag->mag_dev->dev_data.track[1].str));
  14. widget_add_string_multiline_element(
  15. widget, 0, 15, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(tmp_str));
  16. widget_add_button_element(widget, GuiButtonTypeLeft, "Config", mag_widget_callback, mag);
  17. widget_add_button_element(widget, GuiButtonTypeRight, "Send", mag_widget_callback, mag);
  18. view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
  19. furi_string_free(tmp_str);
  20. }
  21. bool mag_scene_emulate_on_event(void* context, SceneManagerEvent event) {
  22. Mag* mag = context;
  23. SceneManager* scene_manager = mag->scene_manager;
  24. bool consumed = false;
  25. if(event.type == SceneManagerEventTypeCustom) {
  26. if(event.event == GuiButtonTypeLeft) {
  27. consumed = true;
  28. scene_manager_next_scene(scene_manager, MagSceneEmulateConfig);
  29. } else if(event.event == GuiButtonTypeRight) {
  30. consumed = true;
  31. FuriString* tmp_str;
  32. tmp_str = furi_string_alloc_set_str(
  33. furi_string_get_cstr(mag->mag_dev->dev_data.track[1].str));
  34. // Assumes track 2 for temporary testing.
  35. // Will overhaul alongside file format and config system
  36. notification_message(mag->notifications, &sequence_blink_start_cyan);
  37. mag_spoof_single_track_rfid(tmp_str, 1);
  38. notification_message(mag->notifications, &sequence_blink_stop);
  39. furi_string_free(tmp_str);
  40. }
  41. }
  42. return consumed;
  43. }
  44. void mag_scene_emulate_on_exit(void* context) {
  45. Mag* mag = context;
  46. notification_message(mag->notifications, &sequence_blink_stop);
  47. widget_reset(mag->widget);
  48. }