nfc_scene_device_info.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "../nfc_i.h"
  2. #include "../helpers/nfc_emv_parser.h"
  3. void nfc_scene_device_info_widget_callback(GuiButtonType result, InputType type, void* context) {
  4. Nfc* nfc = context;
  5. if(type == InputTypeShort) {
  6. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  7. }
  8. }
  9. void nfc_scene_device_info_on_enter(void* context) {
  10. Nfc* nfc = context;
  11. NfcDeviceData* dev_data = &nfc->dev->dev_data;
  12. FuriString* temp_str;
  13. temp_str = furi_string_alloc();
  14. if(dev_data->protocol == NfcDeviceProtocolEMV) {
  15. EmvData* emv_data = &dev_data->emv_data;
  16. furi_string_printf(temp_str, "\e#%s\n", emv_data->name);
  17. for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
  18. furi_string_cat_printf(
  19. temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
  20. }
  21. furi_string_trim(temp_str);
  22. // Add expiration date
  23. if(emv_data->exp_mon) {
  24. furi_string_cat_printf(
  25. temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
  26. }
  27. // Parse currency code
  28. if((emv_data->currency_code)) {
  29. FuriString* currency_name;
  30. currency_name = furi_string_alloc();
  31. if(nfc_emv_parser_get_currency_name(
  32. nfc->dev->storage, emv_data->currency_code, currency_name)) {
  33. furi_string_cat_printf(
  34. temp_str, "\nCur: %s ", furi_string_get_cstr(currency_name));
  35. }
  36. furi_string_free(currency_name);
  37. }
  38. // Parse country code
  39. if((emv_data->country_code)) {
  40. FuriString* country_name;
  41. country_name = furi_string_alloc();
  42. if(nfc_emv_parser_get_country_name(
  43. nfc->dev->storage, emv_data->country_code, country_name)) {
  44. furi_string_cat_printf(temp_str, "Reg: %s", furi_string_get_cstr(country_name));
  45. }
  46. furi_string_free(country_name);
  47. }
  48. } else if(
  49. dev_data->protocol == NfcDeviceProtocolMifareClassic ||
  50. dev_data->protocol == NfcDeviceProtocolMifareUl) {
  51. furi_string_set(temp_str, nfc->dev->dev_data.parsed_data);
  52. }
  53. widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
  54. furi_string_free(temp_str);
  55. widget_add_button_element(
  56. nfc->widget, GuiButtonTypeRight, "More", nfc_scene_device_info_widget_callback, nfc);
  57. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  58. }
  59. bool nfc_scene_device_info_on_event(void* context, SceneManagerEvent event) {
  60. Nfc* nfc = context;
  61. bool consumed = false;
  62. if(event.type == SceneManagerEventTypeCustom) {
  63. if(event.event == GuiButtonTypeRight) {
  64. scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo);
  65. consumed = true;
  66. }
  67. }
  68. return consumed;
  69. }
  70. void nfc_scene_device_info_on_exit(void* context) {
  71. Nfc* nfc = context;
  72. // Clear views
  73. widget_reset(nfc->widget);
  74. }