📄 test.c
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Copyright (C) 2002, 2003 Motorola Semiconductors HK Ltd * */#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>int main(){ int fd; char buf[2]; int size; int i; fd = open("/dev/i2c-keypad",O_RDONLY); for(i=0;i<2;i++) buf[i] = 0; // printf("open fd=%d\n",fd); while(i<102){ size = read(fd,buf,2); { //printf("app read okay---\n"); printf("buf[%d] = %x\n",0,buf[0]); printf("buf[%d] = %x\n",1,buf[1]); /*switch(buf[0]){ case 0xEF: switch(buf[1]){ case 0xEF: break; case 0xF7: break; case 0xFB: break; case 0xFD: break; case 0xFE: break; default: } break; case 0xF7: switch(buf[1]){ case 0xEF: break; case 0xF7: break; case 0xFB: break; case 0xFD: break; case 0xFE: break; default: } break; case 0xFB: switch(buf[1]){ case 0xEF: break; case 0xF7: break; case 0xFB: break; case 0xFD: break; case 0xFE: break; default: } break; case 0xFD: switch(buf[1]){ case 0xEF: break; case 0xF7: break; case 0xFB: break; case 0xFD: break; case 0xFE: break; default: } break; case 0xFE: switch(buf[1]){ case 0xEF: break; case 0xF7: break; case 0xFB: break; case 0xFD: break; case 0xFE: break; default: } break; default: switch(buf[1]){ case 0xEF: break; case 0xF7: break; case 0xFB: break; case 0xFD: break; case 0xFE: break; default: } } */ /*if ((~buf[0]&0x10) && (~buf[1]&0x10)) printf("L "); if ((~buf[0]&0x10) && (~buf[1]&0x08)) printf("R "); if ((~buf[0]&0x10) && (~buf[1]&0x04)) printf("D "); if ((~buf[0]&0x08) && (~buf[1]&0x02)) printf("U "); if ((~buf[0]&0x04) && (~buf[1]&0x01)) printf("A "); if ((~buf[0]&0x02) && (~buf[1]&0x10)) printf("B "); if ((buf[0]==0xFF) && (buf[1]==0xFF)) printf("No keys are pressed "); printf("\n"); */ //putchar('\r'); //putchar(((~buf[0]&0x10) && (~buf[1]&0x10))?'L':' '); //putchar(((~buf[0]&0x10) && (~buf[1]&0x08))?'R':' '); //putchar(((~buf[0]&0x10) && (~buf[1]&0x04))?'U':' '); //putchar(((~buf[0]&0x08) && (~buf[1]&0x02))?'P':' '); //putchar(((~buf[0]&0x04) && (~buf[1]&0x01))?'A':' '); //putchar(((~buf[0]&0x02) && (~buf[1]&0x10))?'B':' '); //fflush(stdout); } i = i + 1; } close(fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -