这几天用SC95F低功耗触摸按键唤醒库发现一个问题,现象是进入低功耗后,通过其他方式(非触摸按键)唤醒后调用退出低功耗模式(调用该函数void TouchKey_QuitLowPowerMode(void))时,在退出低功耗到正常模式扫描按键时,会有最后触摸扫描通道按键触发。
通过打印跟踪在unsigned long int TouchKeyScan(void)函数中,WakeUpKeyValue变量在非触摸退出低功耗时正好是最后扫描通道,导致一退出低功耗就有按键触发。
/**************************************************
*函数名称:unsigned int TouchKeyScan(void)
*函数功能:检测按键接口
*入口参数:void
*出口参数:按键通道, 返回的是一个int , 通道数
*备注 :1, 调用触控库检测函数SensorKeyFlag()
2, 分析得出16个通道,哪个通道有按下,按下bit 位设置为1,否则为0
3, 检测是否需要立即更新baseline: 大于MAX_KEY_RESET_BASELINE 个按键按下时立即更新baseline
4, 双键或者单键按下时, 时间大于SetOneKeyPushResetTime()结果时更新baseline
**************************************************/
unsigned long int TouchKeyScan(void)
{
unsigned char t;
unsigned char MultipleCnt = 0;//按键计数
unsigned long int Keyvalue = 0;
unsigned long int KeyData = 0;
if(WakeUp_Flag == 0)
{
if(GetIsNeedUpdateBaseline() == 0) //检测是否需要更新baseline
{
Keyvalue = SensorKeyFlag(); //Sensor判断, 这里如果bMultiple = 1 表示中间有干扰 //分析按键,得出标准的16通道bit 位
for(t=0;t<CurrentChannelMax;t++)
{
Keyvalue = Keyvalue>>1;
if(TK_CY)
{
KeyData |= ((unsigned long int)0x01 << (CurrentChannel[t]));
MultipleCnt++;
}
}
if(MultipleCnt >= 2) //进入多按键处理
{
bMultiple = 1;
if(MultipleCnt >= SOCAPI_MAX_KEY_NUM_INVALID)
{
SetNeedUpdateBaseline(); // 立即更新baseline ,例如亚克力板盖上去
}
else
{
if(IsDoubleKeyOrSlideKey())
{
bMultiple = 0;
}
}
}
if(bMultiple == 0) //进入按键判断
{
if(KeyData != 0x0) //单个按键达到多长时间就update baseline ,松手检测
{
UpdateBaseLNum++;
}
else
{
UpdateBaseLNum = 0;
}
}
else
{
//考虑基线更新
MultipleLNum++;
KeyData = 0x00;
}
if(UpdateBaseLNum > SetOneKeyPushResetTime()) //按键超出最长输出时间更新基线
{
SetNeedUpdateBaseline();
UpdateBaseLNum = 0;
}
if(MultipleLNum >SOCAPI_MAX_KEY_MUTIPLE) //干扰计数大于最大计数更新基线
{
SetNeedUpdateBaseline();
MultipleDealTpye = 1;
MultipleLNum = 0;
}
}
else
{
MultipleDeal(TKCFG[AUTO_UPDATE_TIME]); //基线复位处理
}
}
else
{
#ifdef TK_LowPowerMode
if(++WakeUpThenScanCount>5)
{
WakeUpThenScanCount = 0;
WakeUp_Flag = 0;
}
for(t=0;t<CurrentChannelMax;t++)
{
FilterDataDeal(t);
if(!WakeUp_Flag)
{
if(WakeUpKeyValue==t)
continue;
BaseLine[t] = RawData[t];
}
}
//修改后
if(WakeUpKeyValue != 0xff)
{
KeyData |= ((unsigned long int)0x01 << (CurrentChannel[WakeUpKeyValue]));
}
//原来
//KeyData |= ((unsigned long int)0x01 << (CurrentChannel[WakeUpKeyValue]));
#endif
}
return KeyData;
}
就是在这个void TouchKey_LowPower_Dispose(void)函数中,在无触摸按键下,WakeUpKeyValue变量值是最后扫描通道。现在需要修改在无触摸时WakeUpKeyValue值不能为正常触摸通道索引,修改如下:
/**************************************************
*函数名称:void TouchKey_LowPower_Dispose(void)
*函数功能低功耗扫描数据处理
*入口参数:void
*出口参数:void
**************************************************/
void TouchKey_LowPower_Dispose(void)
{
int differData;
int SetFingerThresholdtmp;
unsigned char WakeUpKey_Index;
unsigned char NextWakeUpKey_Index;
unsigned int ScanTimeTemp;
SingleKeyFastScan_Flag = 0;
TKCFG0 &= 0XF0;
BTM_WakeUpFlag = 0;
TKCFG0 |= TKChannelCfg[0][SET_TOUCH_FREQ];
for(WakeUpKey_Index=0; WakeUpKey_Index<WakeUpKeyNum; WakeUpKey_Index++)
{
WakeUpKeyValue = WakeUpKey_List[WakeUpKey_Index];
NextWakeUpKey_Index = WakeUpKey_Index+1;
if(NextWakeUpKey_Index>=WakeUpKeyNum)
{
NextWakeUpKey_Index = 0;
}
ScanTimeTemp = ScanTimeTemp0*TKChannelCfg[WakeUpKey_List[NextWakeUpKey_Index]][SCANTIME];
while(TRIF == 0);
TRIF = 0;
RawData[WakeUpKeyValue] = TKCNT<<4;
TKCFG1 = (TKCFG1 & 0X80) | BaseLineAdjusttmp[WakeUpKey_List[NextWakeUpKey_Index]];
TKCR = 0x80|CurrentChannel[WakeUpKey_List[NextWakeUpKey_Index]];
TKTM = ScanTimeTemp;
TRIG = 1;
differData = RawData[WakeUpKeyValue]-BaseLine[WakeUpKeyValue] ;
SetFingerThresholdtmp = GetCurrFingerValue(WakeUpKeyValue);
if(differData >= SetFingerThresholdtmp)
{
SingleKeyFastScan_Flag = 1;
break;
}
else if(differData > (-(SetFingerThresholdtmp>>1)))
{
if(WakeUpNum==WakeUpKey_Index%BaselineUpdateCnt)
Lowpower_BaselineUpdate(5);
}
else
{
Lowpower_BaselineUpdate(2);
}
}
if(++WakeUpNum>=BaselineUpdateCnt)
{
WakeUpNum = 0;
}
//新修改添加
if(!SingleKeyFastScan_Flag)
{
WakeUpKeyValue = 0xff;
}
}
通过以上修改之后,在其他需要唤醒调用函数void TouchKey_QuitLowPowerMode(void)时,就不会有触摸误动作按键。
|