我使用simplePeripheral工程作为我的工程基础,想区分长短按键,该怎么区分?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
当按键被按下的时候, 会产生一个中断, 收到这个中断以后, 代码会把按键的中断关闭, 然后对这个按键的状态做poll(轮询). 如果状态一直没变, 就一直轮询.
当轮询到按键被释放, 状态改变, 就会再次把这个按键的中断打开, 以等待下次按键按下.
请参考hal_key.c里面的HalKeyPoll(), 以及OnBoard.c里面的OnBoard_KeyCallback().
前者做状态轮询, 后者根据按键状态进行中断开关.
你可以根据需要在这两个地方加点东西, 比如计数之类, 来判断按键按下的时间长短.
你好,请问蓝牙协议栈中为什么要加入这段程序呢?(zigbee协议栈中却没有这一段)
/* If any key is currently pressed down and interrupt
is still enabled, disable interrupt and switch to polling */
if( keys != 0 )
{
if( OnboardKeyIntEnable == HAL_KEY_INTERRUPT_ENABLE )
{
OnboardKeyIntEnable = HAL_KEY_INTERRUPT_DISABLE;
HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback);
}
}
/* If no key is currently pressed down and interrupt
is disabled, enable interrupt and turn off polling */
else
{
if( OnboardKeyIntEnable == HAL_KEY_INTERRUPT_DISABLE )
{
OnboardKeyIntEnable = HAL_KEY_INTERRUPT_ENABLE;
HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback);
}
}