#include "zsn603.h"  
#include "demo_zsn603_entries.h"
static int a = 0;

//有卡检测到回调函数
void __card_input(void *p_arg){
    a = 1;
}

void demo_zsn603_auto_detect_test_entry(zsn603_handle_t handle)
{
    unsigned char ret;
    unsigned char data[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
    zsn603_auto_detect_ctrl_t  auto_ctrl;
    zsn603_auto_detect_data_t  auto_data;

    //自动检测模式配置
    auto_ctrl.ad_mode        = ZSN603_AUTO_DETECT_CONTINUE | ZSN603_AUTO_DETECT_INTERRUPT |
                               ZSN603_AUTO_DETECT_SEND;
    auto_ctrl.tx_mode        = ZSN603_ANT_MODE_TX12;
    auto_ctrl.req_code       = ZSN603_MIFARE_REQUEST_IDLE;
    auto_ctrl.auth_mode      = ZSN603_AUTO_DETECT_KEY_AUTH;
    auto_ctrl.key_type       = ZSN603_ICC_KEY_TYPE_A;
    auto_ctrl.p_key          = data;
    auto_ctrl.key_len        = 6;
    auto_ctrl.block          = 4;
    auto_ctrl.pfn_card_input = __card_input;
    auto_ctrl.p_arg          = NULL;

    ret = zsn603_auto_detect(handle, &auto_ctrl);
    if(ret == 0){
        printf("Entry auto detect card mode success!\r\n");
    }else{
        printf("Entry auto detect card mode fail beacuse error 0x%02x!\r\n", ret);
        return ;
    }

    while(a == 0);
    ret = zsn603_get_auto_detect(handle, 0, &auto_data);
    a = 0;

    if(ret == 0){
        printf("Auto detect card success!\r\n");
    }else{
        printf("Auto detect card fail beacuse error 0x%2x!\r\n", ret);
    }
}  
