嵌入式 Linux智能终端菜单界面设计(2)

        键盘处理线程主要检查是否有键按下,一旦有键按下则读取相应的键码值,并作相应的响应处理。当一个键按下时,EM9160内核中的键盘驱动程序将得到的有效键码存储在内部的缓冲区中,应用程序可直接通过read函数读取键码。

        应用程序打开矩阵键盘驱动程序的方法还是打开相应的设备文件,如下:

        key_fd = open('/dev/em9x60_keypad', O_RDONLY | O_NONBLOCK);

        以下为读取键码值并作相应的处理代码:

        FD_ZERO(&fs_read);
        FD_SET(key_fd,&fs_read);

        time.tv_sec = 0;
        time.tv_usec = 100000; //timeout = 100ms
        fs_sel = select(key_fd+1, &fs_read, NULL, NULL, &time);
        if(fs_sel)
        {
                //data available, so get it!
          
      len = read(key_fd, &KeyCode, sizeof(KeyCode));
                if(len > 0)
                {
                        //printf('len=%d KeyCode= 0x%x\r\n', len, KeyCode);
                  
      switch( KeyCode )
                        {
                        case 0x011b:
                                KeyCmd = ESC;
                                MenuManager.Key_ESC( );
                                break;
                        case 0x1c0d:
                                KeyCmd = ENTER;
                                MenuManager.Key_ENTER( );
                                break;
                        case 0x0635:
                                KeyCmd = UP;
                                MenuManager.Key_SHIFT( 1 );
                                break;
                        case 0x0938:
                                KeyCmd = DOWN;
                                MenuManager.Key_SHIFT( 0 );
                                break;
                        case 0x0837:
                                KeyCmd = LEFT;
                                break;
                        case 0x0939:
                                KeyCmd = RIGHT;
                                break;
                        }
                }
        }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwsgwg.html