Add portable NFC module
This commit is contained in:
96
nfc/examples/banban_adapter.c
Normal file
96
nfc/examples/banban_adapter.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "nfc_service.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern int fota_start;
|
||||
extern int audio_packet_type;
|
||||
extern volatile int tts_playing;
|
||||
extern int g_testmode;
|
||||
extern int g_nfc_bind_status;
|
||||
|
||||
uint8_t get_sleep_mode(void);
|
||||
int get_mqtt_connect_status(void);
|
||||
unsigned char get_xiaoice_connected_status(void);
|
||||
bool vad_audio_is_recording(void);
|
||||
int xiaoice_get_play_counter(void);
|
||||
void handle_nfc_trigger(const char *uuid);
|
||||
void handle_nfc_bind(const char *uuid);
|
||||
|
||||
static int banban_nfc_can_poll(void *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
|
||||
if (fota_start != 0) {
|
||||
return 0;
|
||||
}
|
||||
if (get_sleep_mode() == 1) {
|
||||
return 0;
|
||||
}
|
||||
if (get_mqtt_connect_status() != 1) {
|
||||
return 0;
|
||||
}
|
||||
if (g_testmode == 1) {
|
||||
return 1;
|
||||
}
|
||||
if (get_xiaoice_connected_status() != 2) {
|
||||
return 0;
|
||||
}
|
||||
if (vad_audio_is_recording() == 1) {
|
||||
return 0;
|
||||
}
|
||||
if (audio_packet_type != 0) {
|
||||
return 0;
|
||||
}
|
||||
if (tts_playing != 0) {
|
||||
return 0;
|
||||
}
|
||||
if (xiaoice_get_play_counter() != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void banban_nfc_on_uid(const nfc_uid_t *uid, void *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
|
||||
if (uid == NULL || g_testmode != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_nfc_bind_status == 1) {
|
||||
handle_nfc_bind(uid->value);
|
||||
g_nfc_bind_status = 0;
|
||||
} else {
|
||||
handle_nfc_trigger(uid->value);
|
||||
}
|
||||
}
|
||||
|
||||
static void banban_nfc_on_error(int status, void *ctx)
|
||||
{
|
||||
(void)status;
|
||||
(void)ctx;
|
||||
}
|
||||
|
||||
int banban_nfc_start(void)
|
||||
{
|
||||
nfc_service_config_t config;
|
||||
nfc_service_callbacks_t callbacks = {
|
||||
.can_poll = banban_nfc_can_poll,
|
||||
.on_uid = banban_nfc_on_uid,
|
||||
.on_error = banban_nfc_on_error,
|
||||
.ctx = 0,
|
||||
};
|
||||
int ret;
|
||||
|
||||
nfc_service_default_config(&config);
|
||||
ret = nfc_service_init(&config, &callbacks);
|
||||
if (ret != NFC_STATUS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return nfc_service_start();
|
||||
}
|
||||
Reference in New Issue
Block a user