2021-07-22 06:05:07 +00:00
|
|
|
#include "../nfc_i.h"
|
2021-11-08 21:55:06 +00:00
|
|
|
#include "../helpers/nfc_emv_parser.h"
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2021-09-15 15:24:19 +00:00
|
|
|
void nfc_scene_device_info_widget_callback(GuiButtonType result, InputType type, void* context) {
|
2021-08-20 19:56:43 +00:00
|
|
|
Nfc* nfc = context;
|
2021-09-15 15:24:19 +00:00
|
|
|
if(type == InputTypeShort) {
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
|
|
|
}
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_device_info_on_enter(void* context) {
|
2021-08-20 19:56:43 +00:00
|
|
|
Nfc* nfc = context;
|
2022-08-17 15:08:13 +00:00
|
|
|
NfcDeviceData* dev_data = &nfc->dev->dev_data;
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
string_t temp_str;
|
|
|
|
string_init(temp_str);
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
if(dev_data->protocol == NfcDeviceProtocolEMV) {
|
|
|
|
EmvData* emv_data = &dev_data->emv_data;
|
|
|
|
string_printf(temp_str, "\e#%s\n", emv_data->name);
|
|
|
|
for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
|
|
|
|
string_cat_printf(temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
|
|
|
|
}
|
|
|
|
string_strim(temp_str);
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2022-08-17 15:08:13 +00:00
|
|
|
// Add expiration date
|
|
|
|
if(emv_data->exp_mon) {
|
|
|
|
string_cat_printf(temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
// Parse currency code
|
|
|
|
if((emv_data->currency_code)) {
|
|
|
|
string_t currency_name;
|
|
|
|
string_init(currency_name);
|
|
|
|
if(nfc_emv_parser_get_currency_name(
|
|
|
|
nfc->dev->storage, emv_data->currency_code, currency_name)) {
|
|
|
|
string_cat_printf(temp_str, "\nCur: %s ", string_get_cstr(currency_name));
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
string_clear(currency_name);
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
// Parse country code
|
|
|
|
if((emv_data->country_code)) {
|
2021-11-08 21:55:06 +00:00
|
|
|
string_t country_name;
|
|
|
|
string_init(country_name);
|
|
|
|
if(nfc_emv_parser_get_country_name(
|
|
|
|
nfc->dev->storage, emv_data->country_code, country_name)) {
|
2022-08-17 15:08:13 +00:00
|
|
|
string_cat_printf(temp_str, "Reg: %s", string_get_cstr(country_name));
|
2021-11-08 21:55:06 +00:00
|
|
|
}
|
|
|
|
string_clear(country_name);
|
2021-08-20 19:56:43 +00:00
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
} else if(dev_data->protocol == NfcDeviceProtocolMifareClassic) {
|
|
|
|
string_set(temp_str, nfc->dev->dev_data.parsed_data);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
2022-08-17 15:08:13 +00:00
|
|
|
|
|
|
|
widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, string_get_cstr(temp_str));
|
|
|
|
string_clear(temp_str);
|
|
|
|
|
|
|
|
widget_add_button_element(
|
|
|
|
nfc->widget, GuiButtonTypeRight, "More", nfc_scene_device_info_widget_callback, nfc);
|
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
bool nfc_scene_device_info_on_event(void* context, SceneManagerEvent event) {
|
2021-08-20 19:56:43 +00:00
|
|
|
Nfc* nfc = context;
|
2021-07-22 06:05:07 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-08-17 15:08:13 +00:00
|
|
|
if(event.event == GuiButtonTypeRight) {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo);
|
2021-07-22 06:05:07 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_device_info_on_exit(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
// Clear views
|
2022-02-02 19:59:28 +00:00
|
|
|
widget_reset(nfc->widget);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|