nfc_apdu_runner_scene_results.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * @Author: SpenserCai
  3. * @Date: 2025-03-07 16:31:44
  4. * @version:
  5. * @LastEditors: SpenserCai
  6. * @LastEditTime: 2025-03-11 09:59:00
  7. * @Description: file content
  8. */
  9. #include "../nfc_apdu_runner.h"
  10. #include "nfc_apdu_runner_scene.h"
  11. // 结果场景按钮回调
  12. static void nfc_apdu_runner_scene_results_button_callback(
  13. GuiButtonType result,
  14. InputType type,
  15. void* context) {
  16. NfcApduRunner* app = context;
  17. if(type == InputTypeShort) {
  18. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  19. }
  20. }
  21. // 结果场景进入回调
  22. void nfc_apdu_runner_scene_results_on_enter(void* context) {
  23. NfcApduRunner* app = context;
  24. Widget* widget = app->widget;
  25. widget_reset(widget);
  26. widget_add_string_element(widget, 64, 5, AlignCenter, AlignTop, FontPrimary, "执行结果");
  27. FuriString* text = furi_string_alloc();
  28. for(uint32_t i = 0; i < app->response_count; i++) {
  29. furi_string_cat_printf(text, "Command: %s\n", app->responses[i].command);
  30. furi_string_cat_str(text, "Response: ");
  31. for(uint16_t j = 0; j < app->responses[i].response_length; j++) {
  32. furi_string_cat_printf(text, "%02X", app->responses[i].response[j]);
  33. }
  34. furi_string_cat_str(text, "\n\n");
  35. }
  36. widget_add_text_scroll_element(widget, 0, 16, 128, 35, furi_string_get_cstr(text));
  37. furi_string_free(text);
  38. // 添加按钮
  39. widget_add_button_element(
  40. widget, GuiButtonTypeLeft, "Cancel", nfc_apdu_runner_scene_results_button_callback, app);
  41. widget_add_button_element(
  42. widget, GuiButtonTypeRight, "Save", nfc_apdu_runner_scene_results_button_callback, app);
  43. view_dispatcher_switch_to_view(app->view_dispatcher, NfcApduRunnerViewWidget);
  44. }
  45. // 结果场景事件回调
  46. bool nfc_apdu_runner_scene_results_on_event(void* context, SceneManagerEvent event) {
  47. NfcApduRunner* app = context;
  48. bool consumed = false;
  49. if(event.type == SceneManagerEventTypeCustom) {
  50. if(event.event == GuiButtonTypeLeft) {
  51. // 取消按钮 - 返回到开始场景
  52. scene_manager_search_and_switch_to_previous_scene(
  53. app->scene_manager, NfcApduRunnerSceneStart);
  54. consumed = true;
  55. } else if(event.event == GuiButtonTypeRight) {
  56. // 保存按钮 - 进入保存文件场景
  57. // 设置场景状态,标记为进入保存文件场景
  58. scene_manager_set_scene_state(
  59. app->scene_manager, NfcApduRunnerSceneResults, NfcApduRunnerSceneSaveFile);
  60. scene_manager_next_scene(app->scene_manager, NfcApduRunnerSceneSaveFile);
  61. consumed = true;
  62. }
  63. } else if(event.type == SceneManagerEventTypeBack) {
  64. // 返回键 - 返回到开始场景
  65. scene_manager_search_and_switch_to_previous_scene(
  66. app->scene_manager, NfcApduRunnerSceneStart);
  67. consumed = true;
  68. }
  69. return consumed;
  70. }
  71. // 结果场景退出回调
  72. void nfc_apdu_runner_scene_results_on_exit(void* context) {
  73. NfcApduRunner* app = context;
  74. widget_reset(app->widget);
  75. // 只有在不是进入保存文件场景时才释放响应资源
  76. if(app->responses != NULL &&
  77. scene_manager_get_scene_state(app->scene_manager, NfcApduRunnerSceneResults) !=
  78. NfcApduRunnerSceneSaveFile) {
  79. nfc_apdu_responses_free(app->responses, app->response_count);
  80. app->responses = NULL;
  81. app->response_count = 0;
  82. }
  83. }