You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
2.8 KiB
113 lines
2.8 KiB
////////////////////////////////////////////////////////////////////////////
|
|
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
|
|
///-------------------------------------------------------------------------
|
|
/// @file bsp_drv.c
|
|
/// @brief bsp @ driver config
|
|
///-------------------------------------------------------------------------
|
|
/// @version 1.0
|
|
/// @author CC
|
|
/// @date 20180331
|
|
/// @note cc_AS_stc02
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "task_btn_nonblock.h"
|
|
#include "../app/app_config.h"
|
|
#include "../bsp/bsp_config.h"
|
|
#include "../msp/uart0.h"
|
|
#include "../bsp/bsp_key_nonblock.h"
|
|
#include "../bsp/bsp_led.h"
|
|
|
|
S_TASK_BTN _s_task_btn;
|
|
static int i;
|
|
static U8 key;
|
|
|
|
void L3_task_btn_init(void)
|
|
{
|
|
L1_task_init(&_s_task_btn.task);
|
|
L3_task_s_go(_s_task_btn,D_task_init);
|
|
}
|
|
|
|
#define D_TASK_BTN_SCAN 0x50
|
|
#define D_TASK_BTN_SHAKE 0x51
|
|
#define D_TASK_BTN_COMPLETE 0x52
|
|
|
|
void L3_task_btn_handler(S_TASK_BTN *s)
|
|
{
|
|
TTSS_Task_init()
|
|
L2_task_go(D_TASK_BTN_SCAN);
|
|
|
|
TTSS_Task_step(D_TASK_BTN_SCAN)
|
|
//检测是否有按键按下,并记录行、列
|
|
key = bsp_key_nonblock_scan(&s->row, &s->col);
|
|
if(key != BSP_KEY_NUM_MAX)
|
|
{
|
|
//检测到的按键按下次数
|
|
s->times = 0;
|
|
//最大次数阈值,超过阈值停止检测,判定为按键放开
|
|
s->times_threshold = 100;
|
|
//再次检测(防抖动、检测按键弹起)
|
|
L2_task_go_Tdelay(D_TASK_BTN_SHAKE, D_Tdelay_5ms);
|
|
}
|
|
|
|
TTSS_Task_step(D_TASK_BTN_SHAKE)
|
|
//检测当前列是否仍处于按下状态,或者按下超时
|
|
//此时row仍处于检测状态,不需要再次调用scan_row()
|
|
if(bsp_key_nonblock_scan_col(s->col) == 0 || s->times > s->times_threshold)
|
|
{
|
|
L2_task_go_Tdelay(D_TASK_BTN_COMPLETE, 0);
|
|
}
|
|
else
|
|
{
|
|
s->times ++;
|
|
//每5s检测一次
|
|
L2_task_go_Tdelay(D_TASK_BTN_SHAKE, D_Tdelay_5ms);
|
|
}
|
|
|
|
TTSS_Task_step(D_TASK_BTN_COMPLETE)
|
|
//至少一次,防抖动
|
|
if(s->times > 1)
|
|
{
|
|
L0_uart0_uc('#');
|
|
L0_uart0_uchex(key);
|
|
|
|
//功能按键
|
|
if(key == 0)
|
|
{
|
|
//设置功能按键按下
|
|
R.func_btn = 1;
|
|
//此处代码注释掉:因为低功耗由上位机处理
|
|
//功能键按下退出低功耗模式
|
|
//L3_set_power_mode(POWER_NORMAL);
|
|
}
|
|
//心电模式
|
|
else if(key == 13)
|
|
{
|
|
//设置心电模式按下
|
|
R.xd_mode ^= 1;
|
|
//亮灯
|
|
R.led_status[key] = R.xd_mode;
|
|
}
|
|
else if(key>=1 && key <=12)
|
|
{
|
|
//如果不需要授权 or 需要但已经授权
|
|
if(!(R.auth_flag & 0xF0) || (R.auth_flag & 0x0F))
|
|
{
|
|
//L0_uart0_uc('$');
|
|
//L0_uart0_uchex(key);
|
|
|
|
//设置对应的rfid
|
|
L3_new_rfid(R.rfid_table[key], 0, 0xFF);
|
|
|
|
//亮灯
|
|
R.led_status[key] = 1;
|
|
}
|
|
}
|
|
}
|
|
L2_task_go_Tdelay(D_TASK_BTN_SCAN,0);
|
|
|
|
TTSS_Task_end();
|
|
}
|
|
|
|
|
|
|
|
|
|
|