mag_scene_emulate.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // TODO: Display other relevant config settings (namely RFID vs GPIO)?
  11. widget_add_icon_element(widget, 1, 1, &I_mag_10px);
  12. widget_add_string_element(
  13. widget, 13, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp_str));
  14. furi_string_reset(tmp_str);
  15. for(uint8_t i = 0; i < MAG_DEV_TRACKS; i++) {
  16. FuriString* trackstr = mag->mag_dev->dev_data.track[i].str;
  17. // there's definitely a better way to do this...
  18. bool is_active_one = (mag->setting->track == MagTrackStateOne) & (i == 0);
  19. bool is_active_two = (mag->setting->track == MagTrackStateTwo) & (i == 1);
  20. bool is_active_both = (mag->setting->track == MagTrackStateAll);
  21. if(is_active_one | is_active_two | is_active_both) {
  22. furi_string_cat_printf(
  23. tmp_str,
  24. "Track %d:%s%s\n\n",
  25. (i + 1),
  26. furi_string_empty(trackstr) ? " " : "\n",
  27. furi_string_empty(trackstr) ? "< empty >" : furi_string_get_cstr(trackstr));
  28. }
  29. }
  30. widget_add_text_scroll_element(widget, 0, 15, 128, 49, furi_string_get_cstr(tmp_str));
  31. widget_add_button_element(widget, GuiButtonTypeLeft, "Config", mag_widget_callback, mag);
  32. widget_add_button_element(widget, GuiButtonTypeRight, "Send", mag_widget_callback, mag);
  33. widget_add_button_element(widget, GuiButtonTypeCenter, "Bitwise", mag_widget_callback, mag);
  34. view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewWidget);
  35. furi_string_free(tmp_str);
  36. }
  37. bool mag_scene_emulate_on_event(void* context, SceneManagerEvent event) {
  38. Mag* mag = context;
  39. SceneManager* scene_manager = mag->scene_manager;
  40. bool consumed = false;
  41. if(event.type == SceneManagerEventTypeCustom) {
  42. switch(event.event) {
  43. case GuiButtonTypeLeft:
  44. consumed = true;
  45. scene_manager_next_scene(scene_manager, MagSceneEmulateConfig);
  46. break;
  47. case GuiButtonTypeRight:
  48. consumed = true;
  49. notification_message(mag->notifications, &sequence_blink_start_cyan);
  50. mag_spoof(mag);
  51. notification_message(mag->notifications, &sequence_blink_stop);
  52. break;
  53. case GuiButtonTypeCenter:
  54. consumed = true;
  55. notification_message(mag->notifications, &sequence_blink_start_cyan);
  56. mag_spoof_bitwise(mag);
  57. notification_message(mag->notifications, &sequence_blink_stop);
  58. break;
  59. }
  60. }
  61. return consumed;
  62. }
  63. void mag_scene_emulate_on_exit(void* context) {
  64. Mag* mag = context;
  65. notification_message(mag->notifications, &sequence_blink_stop);
  66. widget_reset(mag->widget);
  67. }