feat(nfc): activate transmit mode with key clicks
This commit is contained in:
@@ -30,9 +30,40 @@ extern int fota_start;
|
||||
#define KEY_LONG_PRESS_1_5S 1500/5
|
||||
#define KEY_LONG_PRESS_3S 3000/5
|
||||
#define KEY_LONG_PRESS_5S 5000/5
|
||||
#define KEY_LONG_PRESS_10S 10000/5
|
||||
|
||||
static unsigned char key_down_event = 0;
|
||||
#define KEY_LONG_PRESS_10S 10000/5
|
||||
#define NFC_TX_CLICK_GAP 2000/5
|
||||
#define NFC_TX_CLICK_COUNT 5
|
||||
|
||||
static unsigned char key_down_event = 0;
|
||||
static unsigned char nfc_tx_click_count = 0;
|
||||
static u32 nfc_tx_last_click_time = 0;
|
||||
|
||||
extern void app_nfc_tx_mode_start(void);
|
||||
|
||||
static int key_mic_register_short_click(void)
|
||||
{
|
||||
u32 now = ql_rtos_get_systicks();
|
||||
|
||||
if (nfc_tx_click_count == 0 ||
|
||||
(u32)(now - nfc_tx_last_click_time) > NFC_TX_CLICK_GAP) {
|
||||
nfc_tx_click_count = 1;
|
||||
} else {
|
||||
nfc_tx_click_count++;
|
||||
}
|
||||
nfc_tx_last_click_time = now;
|
||||
|
||||
printf("NFC TX key clicks:%u/%u\r\n",
|
||||
nfc_tx_click_count, NFC_TX_CLICK_COUNT);
|
||||
if (nfc_tx_click_count >= NFC_TX_CLICK_COUNT) {
|
||||
nfc_tx_click_count = NFC_TX_CLICK_COUNT;
|
||||
app_nfc_tx_mode_start();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Keep the first click's existing voice action. Suppress clicks 2-4 so
|
||||
* a rapid NFC gesture does not repeatedly start/interrupt voice work. */
|
||||
return nfc_tx_click_count > 1;
|
||||
}
|
||||
|
||||
static void key_press_mic(void *args)
|
||||
{
|
||||
@@ -114,31 +145,36 @@ static void key_thread_entry(void *parameter)
|
||||
if(level!=0){ //up
|
||||
key_press_mic_status = 0;
|
||||
|
||||
if(ql_rtos_get_systicks() - key_press_mic_time > KEY_LONG_PRESS_3S){
|
||||
//app_play_tips_file(10);
|
||||
if(ql_rtos_get_systicks() - key_press_mic_time > KEY_LONG_PRESS_3S){
|
||||
nfc_tx_click_count = 0;
|
||||
//app_play_tips_file(10);
|
||||
// power_down_status = 1;
|
||||
ql_rtos_task_sleep_s(3);
|
||||
ql_power_down(1);
|
||||
}
|
||||
else if(ql_rtos_get_systicks() - key_press_mic_time > KEY_WAIT_TIME){
|
||||
//休眠唤醒其它线程
|
||||
if(app_get_app_sleep_flag()==0){
|
||||
app_set_app_operation(1);
|
||||
}
|
||||
|
||||
int mic_pdp = app_get_data_call_net_status();
|
||||
int mic_mqtt = get_mqtt_connect_status();
|
||||
printf("[NET-GATE] mic pdp=%d mqtt=%d action=%s\r\n",
|
||||
mic_pdp, mic_mqtt,
|
||||
!mic_pdp ? "blocked_no_pdp" : (mic_mqtt != 1 ? "blocked_mqtt_offline" : "start_voice"));
|
||||
if(mic_pdp && mic_mqtt == 1){
|
||||
if(tts_play_interrupt_func()==-2){
|
||||
app_play_tips_file(2);
|
||||
}
|
||||
}else{
|
||||
app_play_tips_file(2);
|
||||
}
|
||||
}
|
||||
else if(ql_rtos_get_systicks() - key_press_mic_time > KEY_WAIT_TIME){
|
||||
int nfc_click_handled = key_mic_register_short_click();
|
||||
|
||||
//休眠唤醒其它线程
|
||||
if(app_get_app_sleep_flag()==0){
|
||||
app_set_app_operation(1);
|
||||
}
|
||||
|
||||
if (!nfc_click_handled) {
|
||||
int mic_pdp = app_get_data_call_net_status();
|
||||
int mic_mqtt = get_mqtt_connect_status();
|
||||
printf("[NET-GATE] mic pdp=%d mqtt=%d action=%s\r\n",
|
||||
mic_pdp, mic_mqtt,
|
||||
!mic_pdp ? "blocked_no_pdp" : (mic_mqtt != 1 ? "blocked_mqtt_offline" : "start_voice"));
|
||||
if(mic_pdp && mic_mqtt == 1){
|
||||
if(tts_play_interrupt_func()==-2){
|
||||
app_play_tips_file(2);
|
||||
}
|
||||
}else{
|
||||
app_play_tips_file(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
key_press_mic_time = ql_rtos_get_systicks();
|
||||
key_press_mic_counter = 0;
|
||||
@@ -148,8 +184,9 @@ static void key_thread_entry(void *parameter)
|
||||
key_press_mic_status = 1;//表示已经按下了
|
||||
}
|
||||
|
||||
if(ql_rtos_get_systicks() - key_press_mic_time > KEY_LONG_PRESS_3S && power_down_status==0){
|
||||
power_down_status = 1;
|
||||
if(ql_rtos_get_systicks() - key_press_mic_time > KEY_LONG_PRESS_3S && power_down_status==0){
|
||||
nfc_tx_click_count = 0;
|
||||
power_down_status = 1;
|
||||
app_play_tips_file(10);
|
||||
power_down_status = 2;
|
||||
//ql_rtos_task_sleep_s(3);
|
||||
|
||||
Reference in New Issue
Block a user