nfc_scene_device_info.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. string_t temp_str;
  13. string_init(temp_str);
  14. if(dev_data->protocol == NfcDeviceProtocolEMV) {
  15. EmvData* emv_data = &dev_data->emv_data;
  16. string_printf(temp_str, "\e#%s\n", emv_data->name);
  17. for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
  18. string_cat_printf(temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
  19. }
  20. string_strim(temp_str);
  21. // Add expiration date
  22. if(emv_data->exp_mon) {
  23. string_cat_printf(temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
  24. }
  25. // Parse currency code
  26. if((emv_data->currency_code)) {
  27. string_t currency_name;
  28. string_init(currency_name);
  29. if(nfc_emv_parser_get_currency_name(
  30. nfc->dev->storage, emv_data->currency_code, currency_name)) {
  31. string_cat_printf(temp_str, "\nCur: %s ", string_get_cstr(currency_name));
  32. }
  33. string_clear(currency_name);
  34. }
  35. // Parse country code
  36. if((emv_data->country_code)) {
  37. string_t country_name;
  38. string_init(country_name);
  39. if(nfc_emv_parser_get_country_name(
  40. nfc->dev->storage, emv_data->country_code, country_name)) {
  41. string_cat_printf(temp_str, "Reg: %s", string_get_cstr(country_name));
  42. }
  43. string_clear(country_name);
  44. }
  45. } else if(dev_data->protocol == NfcDeviceProtocolMifareClassic) {
  46. string_set(temp_str, nfc->dev->dev_data.parsed_data);
  47. }
  48. widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, string_get_cstr(temp_str));
  49. string_clear(temp_str);
  50. widget_add_button_element(
  51. nfc->widget, GuiButtonTypeRight, "More", nfc_scene_device_info_widget_callback, nfc);
  52. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  53. }
  54. bool nfc_scene_device_info_on_event(void* context, SceneManagerEvent event) {
  55. Nfc* nfc = context;
  56. bool consumed = false;
  57. if(event.type == SceneManagerEventTypeCustom) {
  58. if(event.event == GuiButtonTypeRight) {
  59. scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo);
  60. consumed = true;
  61. }
  62. }
  63. return consumed;
  64. }
  65. void nfc_scene_device_info_on_exit(void* context) {
  66. Nfc* nfc = context;
  67. // Clear views
  68. widget_reset(nfc->widget);
  69. }