From d5485f33a4dbf396ef03b72211699800f0f25cf4 Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Tue, 22 Aug 2023 15:16:56 +0200 Subject: [PATCH 1/7] Draft code --- firmware/application/src/app_main.c | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index 10aec50..fd15c51 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -499,6 +499,37 @@ static void btn_fn_copy_ic_uid(void) { break; } + case TAG_TYPE_EM410X: { + uint8_t status; + + uint8_t id_buffer[5] = { 0x00 }; + status = PcdScanEM410X(id_buffer); + + if(status != LF_TAG_OK) { + return; + } + + bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER; + // first, we need switch to reader mode. + if (!is_reader_mode_now) { + // enter reader mode + reader_mode_enter(); + bsp_delay_ms(8); + NRF_LOG_INFO("Start reader mode to offline copy.") + } + + tag_data_buffer_t* buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X); + memcpy(buffer->buffer, id_buffer, LF_EM410X_TAG_ID_SIZE); + tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false); + + // keep reader mode or exit reader mode. + if (!is_reader_mode_now) { + tag_mode_enter(); + } + + return; + } + default: NRF_LOG_ERROR("Unsupported tag type") return; From 6d77fc87a7d39230137bc25215d8f2e02f972298 Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Tue, 22 Aug 2023 17:11:31 +0200 Subject: [PATCH 2/7] First become reader --- firmware/application/src/app_main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index fd15c51..fc64403 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -502,13 +502,6 @@ static void btn_fn_copy_ic_uid(void) { case TAG_TYPE_EM410X: { uint8_t status; - uint8_t id_buffer[5] = { 0x00 }; - status = PcdScanEM410X(id_buffer); - - if(status != LF_TAG_OK) { - return; - } - bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER; // first, we need switch to reader mode. if (!is_reader_mode_now) { @@ -518,6 +511,13 @@ static void btn_fn_copy_ic_uid(void) { NRF_LOG_INFO("Start reader mode to offline copy.") } + uint8_t id_buffer[5] = { 0x00 }; + status = PcdScanEM410X(id_buffer); + + if(status != LF_TAG_OK) { + return; + } + tag_data_buffer_t* buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X); memcpy(buffer->buffer, id_buffer, LF_EM410X_TAG_ID_SIZE); tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false); From 32934802fde31e08075c49aaf909b22729ced462 Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Tue, 22 Aug 2023 17:14:59 +0200 Subject: [PATCH 3/7] Leave reader mode before exiting --- firmware/application/src/app_main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index fc64403..be1e48c 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -515,6 +515,9 @@ static void btn_fn_copy_ic_uid(void) { status = PcdScanEM410X(id_buffer); if(status != LF_TAG_OK) { + if (!is_reader_mode_now) { + tag_mode_enter(); + } return; } From 30f3ddde880338d5d5e3a17aae6e93819fe69e6d Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Tue, 22 Aug 2023 17:32:50 +0200 Subject: [PATCH 4/7] Offline HF and LF --- firmware/application/src/app_main.c | 65 ++++++++++++++--------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index be1e48c..708f5d3 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -481,6 +481,37 @@ static void btn_fn_copy_ic_uid(void) { nfc_tag_14a_coll_res_entity_t* antres; + if(tag_type[1] == TAG_TYPE_EM410X) { + uint8_t status; + + bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER; + // first, we need switch to reader mode. + if (!is_reader_mode_now) { + // enter reader mode + reader_mode_enter(); + bsp_delay_ms(8); + NRF_LOG_INFO("Start reader mode to offline copy.") + } + + uint8_t id_buffer[5] = { 0x00 }; + status = PcdScanEM410X(id_buffer); + + if(status == LF_TAG_OK) { + tag_data_buffer_t* buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X); + memcpy(buffer->buffer, id_buffer, LF_EM410X_TAG_ID_SIZE); + tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false); + + // keep reader mode or exit reader mode. + if (!is_reader_mode_now) { + tag_mode_enter(); + } + } else { + if (!is_reader_mode_now) { + tag_mode_enter(); + } + } + } + switch(tag_type[0]) { case TAG_TYPE_MIFARE_Mini: case TAG_TYPE_MIFARE_1024: @@ -499,40 +530,6 @@ static void btn_fn_copy_ic_uid(void) { break; } - case TAG_TYPE_EM410X: { - uint8_t status; - - bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER; - // first, we need switch to reader mode. - if (!is_reader_mode_now) { - // enter reader mode - reader_mode_enter(); - bsp_delay_ms(8); - NRF_LOG_INFO("Start reader mode to offline copy.") - } - - uint8_t id_buffer[5] = { 0x00 }; - status = PcdScanEM410X(id_buffer); - - if(status != LF_TAG_OK) { - if (!is_reader_mode_now) { - tag_mode_enter(); - } - return; - } - - tag_data_buffer_t* buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X); - memcpy(buffer->buffer, id_buffer, LF_EM410X_TAG_ID_SIZE); - tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false); - - // keep reader mode or exit reader mode. - if (!is_reader_mode_now) { - tag_mode_enter(); - } - - return; - } - default: NRF_LOG_ERROR("Unsupported tag type") return; From 2ce2e25827b0d57b73228f8d60f5d9f806521beb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 22 Aug 2023 19:44:20 +0200 Subject: [PATCH 5/7] fix USB LED animation color on slot change --- firmware/application/src/rfid/nfctag/tag_emulation.c | 2 ++ firmware/application/src/rgb_marquee.c | 6 ++++++ firmware/application/src/rgb_marquee.h | 1 + 3 files changed, 9 insertions(+) diff --git a/firmware/application/src/rfid/nfctag/tag_emulation.c b/firmware/application/src/rfid/nfctag/tag_emulation.c index b65da99..800b328 100644 --- a/firmware/application/src/rfid/nfctag/tag_emulation.c +++ b/firmware/application/src/rfid/nfctag/tag_emulation.c @@ -7,6 +7,7 @@ #include "fds_util.h" #include "tag_emulation.h" #include "tag_persistence.h" +#include "rgb_marquee.h" #define NRF_LOG_MODULE_NAME tag_emu @@ -458,6 +459,7 @@ uint8_t tag_emulation_get_slot(void) { */ void tag_emulation_set_slot(uint8_t index) { slotConfig.config.activated = index; // 重设到新切换的卡槽上 + rgb_marquee_reset(); // force animation color refresh according to new slot } /** diff --git a/firmware/application/src/rgb_marquee.c b/firmware/application/src/rgb_marquee.c index 9003982..335983b 100644 --- a/firmware/application/src/rgb_marquee.c +++ b/firmware/application/src/rgb_marquee.c @@ -50,6 +50,12 @@ void rgb_marquee_stop(void){ ledblink1_step = 0; } +// reset RGB state machines to force a refresh of the LED color +void rgb_marquee_reset(void){ + ledblink6_step = 0; + ledblink1_step = 0; +} + // 亮度转PWM值 uint16_t get_pwmduty(uint8_t light_level){ return PWM_MAX-(PWM_MAX*pow(((double)light_level/LIGHT_LEVEL_MAX),2.2)); diff --git a/firmware/application/src/rgb_marquee.h b/firmware/application/src/rgb_marquee.h index a6702ff..0af8a41 100644 --- a/firmware/application/src/rgb_marquee.h +++ b/firmware/application/src/rgb_marquee.h @@ -7,6 +7,7 @@ void rgb_marquee_init(void); void rgb_marquee_stop(void); +void rgb_marquee_reset(void); bool is_rgb_marquee_enable(void); void ledblink1(uint8_t color,uint8_t dir); void ledblink2(uint8_t color,uint8_t dir, uint8_t end); From 41a368a99d64c4124e9e3d2243ea7f4ccad4b4f9 Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Tue, 22 Aug 2023 20:31:41 +0200 Subject: [PATCH 6/7] Fix structure --- firmware/application/src/app_main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/firmware/application/src/app_main.c b/firmware/application/src/app_main.c index 708f5d3..c1a41fb 100644 --- a/firmware/application/src/app_main.c +++ b/firmware/application/src/app_main.c @@ -502,13 +502,10 @@ static void btn_fn_copy_ic_uid(void) { tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false); // keep reader mode or exit reader mode. - if (!is_reader_mode_now) { - tag_mode_enter(); - } - } else { - if (!is_reader_mode_now) { - tag_mode_enter(); - } + } + + if (!is_reader_mode_now) { + tag_mode_enter(); } } From 95aded82676ca6eb7dc958f51eb4e0c7d41bdb08 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 22 Aug 2023 20:38:05 +0200 Subject: [PATCH 7/7] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e3b92..85d90d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added offline copy EM card uid for btnpress.(@nemanjan00) - Added offline copy ic card uid for btnpress.(@xianglin1998) - Added `hw settings btnpress` to get and set button press function.(@xianglin1998) - Added `hw battery` to get battery informartion (@xianglin1998)