mag_scene_emulate.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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));
  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(furi_string_get_cstr(mag->mag_dev->dev_data));
  33. // Assumes track 2 for temporary testing.
  34. // Will overhaul alongside file format and config system
  35. notification_message(mag->notifications, &sequence_blink_start_cyan);
  36. mag_spoof_single_track_rfid(tmp_str, 1);
  37. notification_message(mag->notifications, &sequence_blink_stop);
  38. furi_string_free(tmp_str);
  39. }
  40. }
  41. return consumed;
  42. }
  43. void mag_scene_emulate_on_exit(void* context) {
  44. Mag* mag = context;
  45. notification_message(mag->notifications, &sequence_blink_stop);
  46. widget_reset(mag->widget);
  47. }