首先把相关的程序流程理一理。
首先在business\main.c
的主函数中有对输入系统的初始化:
/* 初始化输入系统 */
InputInit();
IntpuDeviceInit();
运行InputInit()
后,触摸屏输入设备和网络输入设备都进行了结构体链表的注册。
运行IntpuDeviceInit();
后,各输入设备就进行了线程的创建,环形Buffer也得到了创建。
在各输入设备的线程中,通过while循环不断地调用各个设备自己的函数GetInputEvent()到设备底层读取数据。
接着页面系统开始运行→运行页面中的主页面…
在函数MainPageRun()中不断读取输入数据…
while (1)
{
/* 读取输入事件 */
error = GetInputEvent(&tInputEvent);
if (error)
continue;
/* 根据输入事件找到按钮 */
ptButton = GetButtonByInputEvent(&tInputEvent);
if (!ptButton)
continue;
/* 调用按钮的OnPressed函数 */
ptButton->OnPressed(ptButton, ptDispBuff, &tInputEvent);
}
我们不妨在这里把打获得的输入数据打印出来,并看它调用了几次的OnPressed函数。
while (1)
{
/* 读取输入事件 */
error = GetInputEvent(&tInputEvent);
if (error)
continue;
/* 根据输入事件找到按钮 */
ptButton = GetButtonByInputEvent(&tInputEvent);
if (!ptButton)
continue;
/* 调用按钮的OnPressed函数 */
if(tInputEvent.iType == INPUT_TYPE_TOUCH)
{
printf("Type : %d\n", tInputEvent.iType);
printf("iX : %d\n", tInputEvent.iX);
printf("iY : %d\n", tInputEvent.iY);
printf("iPressure : %d\n", tInputEvent.iPressure);
}
printf("Now enter OnPressed()\n");
ptButton->OnPressed(ptButton, ptDispBuff, &tInputEvent);\
printf("Now leaving OnPressed()\n");
}
编译通过后,首先把之前的业务程序终结掉:
kill 26780
然后屏幕刷黑
/mnt/business_test/draw_lcd_black
再重新启动新编译出的业务程序
cd /mnt/debug01/28_business_test/
这里就不后台运行了,因为我随时要终结程序,并且还要打印输出
./test ./simsun.ttc
运行结果如下:
可见,有两次输入事件,这个当然了,你按一次有两次输入事件,第一个是有压力值的输入,另一有次压力值为0,相当于一按一放是两次,这两次分别都去调用了一次ptButton->OnPressed()
函数,你调用一次,颜色就会变化一次,连续变化两次相当于没变呀。
所以我们这里要过滤压力值为0的事件…这样分析来就简单了呀…
我们把代码改为:
while (1)
{
/* 读取输入事件 */
error = GetInputEvent(&tInputEvent);
if (error)
continue;
/* 根据输入事件找到按钮 */
ptButton = GetButtonByInputEvent(&tInputEvent);
if (!ptButton)
continue;
/* 调用按钮的OnPressed函数 */
if(tInputEvent.iType == INPUT_TYPE_TOUCH && tInputEvent.iPressure != 0)
{
printf("Type : %d\n", tInputEvent.iType);
printf("iX : %d\n", tInputEvent.iX);
printf("iY : %d\n", tInputEvent.iY);
printf("iPressure : %d\n", tInputEvent.iPressure);
printf("Now enter OnPressed()\n");
ptButton->OnPressed(ptButton, ptDispBuff, &tInputEvent);\
printf("Now leaving OnPressed()\n");
}
}
}
再运行就完美了:
./test ./simsun.ttc
但是显然像上面这样改,网络设备的输入便不起作用了…
但是显然像上面这样改,网络设备的输入便不起作用了…
但是显然像上面这样改,网络设备的输入便不起作用了…
再进一步分析,实际上应该是去函数MainPageOnPressed()中去修改,即把函数MainPageOnPressed()中的:
if (ptInputEvent->iType == INPUT_TYPE_TOUCH)
改为:
if (ptInputEvent->iType == INPUT_TYPE_TOUCH && ptInputEvent->iPressure != 0)
就可以了…函数MainPageRun()中不需要作任何修改…