- CPU占用率低,非常灵活
条件变量
单线程
select休眠时,由内核将其唤醒
- 多线程
内核唤醒子线程,子线程再唤醒主线程显示
int GetInputEvent()
以阻塞方式打开stdin、touchscreen,在没有数据输入时休眠;有数据输入后被内核唤醒,然后获取数据并唤醒主线程
- 实现滑动翻页
触摸点在X方向的位移差值超过x(如80),就翻页
80是一个经验值,是通过测试得出的
或者可以设为超过xres/5就翻页这样
- 修改touchscreen即可
按下点和松开点的距离xres/5
怎么判断按下还是松开:压力值
static int TouchScreenGetInputEvent(PT_InputEvent ptInputEvent)
{
struct ts_sample tSamp;
struct ts_sample tSampPressed;
struct ts_sample tSampReleased;
int iRet;
int bStart = 0;
int iDelta;
while(1){
iRet = rs_read(g_tTSDev, &tSamp, 1);
if(iRet == 1){
/* 成功 */
if((tSamp.pressure > 0) && (0 == bStart))
{
//按下
tSampPressed = tSamp;
bStart = 1;
}
if((tSamp.pressure <= 0) && (0 != bStart)){
//松开
tSampReleased = tSamp;
if(!bStart){
return -1;
}else{
iDelta = tSampReleased.x - tSampPressed.x;
if(iDelta > giXres/5){
//翻到上一页
}else if(iDelta < 0 - giXres/5){
//翻到下一页
}else
//无法处理,UNKNOW
return 0;
}
}
}else
return -1;
}
}