|
各位看官,在下有一問題不甚明了,忘知情者指點迷津。這是一個軟件濾波的算法,本人看不大懂,懂的人可以講一下算法的精髓,謝謝!
void Key_Debounce(TkeyIndex enKey,u8 input)
{
u8 keycount;
T_KeyCtl* p_stKey;
p_stKey=&keyIndex[enKey];
keycount= p_stKey->count;
if (input != FALSE) {
if (keycount < KEY_HOLD_THRESHOLD) {
keycount++;
}
else{
}
if (keycount >= KEY_HOLD_THRESHOLD) {
if (p_stKey->ctl.Bits.press_s == FALSE) {
p_stKey->ctl.Bits.press_s = TRUE;
p_stKey->ctl.Bits.press = TRUE;
}
p_stKey->ctl.Bits.status = TRUE;
}
}
else {
if (keycount > KEY_PRESS_THRESHOLD) {
keycount = KEY_PRESS_THRESHOLD;
}
if (keycount > KEY_RELEASE_MIN) {
keycount--;
}
if (keycount <= KEY_RELEASE_MIN) {
if (p_stKey->ctl.Bits.press_s) {
p_stKey->ctl.Bits.release = TRUE;
p_stKey->ctl.Bits.press_s = FALSE;
}
p_stKey->ctl.Bits.status = FALSE;
}
}
p_stKey->count = keycount;
} |
|