mag_scene_emulate.c 2.3 KB

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