• CPU占用率低,非常灵活
    • 条件变量

    • 单线程

    image.png
    select休眠时,由内核将其唤醒

    • 多线程

    image.png
    内核唤醒子线程,子线程再唤醒主线程显示

    1. int GetInputEvent()

    image.png
    image.png
    image.png
    image.png
    以阻塞方式打开stdin、touchscreen,在没有数据输入时休眠;有数据输入后被内核唤醒,然后获取数据并唤醒主线程
    image.png

    • 实现滑动翻页

    触摸点在X方向的位移差值超过x(如80),就翻页
    80是一个经验值,是通过测试得出的
    或者可以设为超过xres/5就翻页这样

    • 修改touchscreen即可

    按下点和松开点的距离xres/5
    怎么判断按下还是松开:压力值

    1. static int TouchScreenGetInputEvent(PT_InputEvent ptInputEvent)
    2. {
    3. struct ts_sample tSamp;
    4. struct ts_sample tSampPressed;
    5. struct ts_sample tSampReleased;
    6. int iRet;
    7. int bStart = 0;
    8. int iDelta;
    9. while(1){
    10. iRet = rs_read(g_tTSDev, &tSamp, 1);
    11. if(iRet == 1){
    12. /* 成功 */
    13. if((tSamp.pressure > 0) && (0 == bStart))
    14. {
    15. //按下
    16. tSampPressed = tSamp;
    17. bStart = 1;
    18. }
    19. if((tSamp.pressure <= 0) && (0 != bStart)){
    20. //松开
    21. tSampReleased = tSamp;
    22. if(!bStart){
    23. return -1;
    24. }else{
    25. iDelta = tSampReleased.x - tSampPressed.x;
    26. if(iDelta > giXres/5){
    27. //翻到上一页
    28. }else if(iDelta < 0 - giXres/5){
    29. //翻到下一页
    30. }else
    31. //无法处理,UNKNOW
    32. return 0;
    33. }
    34. }
    35. }else
    36. return -1;
    37. }
    38. }

    文档:
    Unix_Linux_Windows_OpenMP多线程编程.pdf