static void zllSampleLight_HandleKeys( byte shift, byte keys )
{
(void)shift; // Intentionally unreferenced parameter
#ifdef HAL_BOARD_ZLIGHT
// Zlight has only a single button
static uint32 keyPressTime = 0;
if ( keys )
{
keyPressTime = osal_getClock();
}
else //key released
{
if ( keyPressTime )
{
keyPressTime = ( osal_getClock() - keyPressTime );
if ( keyPressTime <= KEY_HOLD_SHORT_INTERVAL )
{
zllTarget_PermitJoin( PERMIT_JOIN_DURATION );
}
else if ( keyPressTime > KEY_HOLD_LONG_INTERVAL )
{
zllTarget_ClassicalCommissioningStart();
}
else
{
zllTarget_ResetToFactoryNew();
}
keyPressTime = 0;
}
}
你可以看看TI的这个代码,我觉得算法最好了。 |