消抖算法思想

下面是一种消抖算法,(常用于ucgui,xvworks图形控制等领域)只是思想,下面分析一下

if(msg.type == MSG_POINTER )
{
/*when the buttonState is not 0,it state the mouse has pressed*/
if(msg.data.pointer.buttonState !=0)
{
buttonState_tmp =(int)msg.data.pointer.buttonState;
/* handle the mouse shake*/
while(msg.data.pointer.buttonState)
uglInputMsgGet (pDisplayControl->inputServiceId, &msg, 140 /* mSec */);
mouseEcho(pDisplayControl,buttonState_tmp);
}
}

if(msg.data.pointer.buttonState !=0)
这一句说明有鼠标按下,因为只要按下一定不为0
buttonState_tmp =(int)msg.data.pointer.buttonState;
把当前值保存下来。
while(msg.data.pointer.buttonState)
如果鼠标不抬起的话,这个msg.data.pointer.buttonState一直不为0,就起到了消抖的作用
uglInputMsgGet (pDisplayControl->inputServiceId, &msg, 140 /* mSec */);
在while里面重新或得坐标值
mouseEcho(pDisplayControl,buttonState_tmp);
退出while后,就是消抖完成了。执行用户程序了
 

原文地址:https://www.cnblogs.com/fishoneseaatblog/p/2281061.html