fishonesea

android 驱动,移植,qq群:91386163 推荐《Android深度探索(卷1):HAL与驱动开发》
  博客园  :: 首页  :: 新随笔  :: 管理

消抖算法思想

Posted on 2011-12-08 17:42  fishonesea  阅读(1140)  评论(0编辑  收藏  举报

下面是一种消抖算法,(常用于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后,就是消抖完成了。执行用户程序了