物理按键的程序
#include "main.h" #include"s5pv210-gpio.h" char *voice_table[6]={"./picture/voice0.bmp","./picture/voice1.bmp", "./picture/voice2.bmp","./picture/voice3.bmp", "./picture/voice4.bmp","./picture/voice5.bmp",}; void * key(void *arg){ int fp3=-1,fp2=-1,fp0=-1; int key ,key_num,flag=0xaa; fp3=open("/dev/gpH3",O_RDWR); if(fp3<0){ perror("dev/gpH3"); //_/exit(-1); } fp2=open("/dev/gpH2",O_RDWR); if(fp2<0){ perror("dev/gpH2"); //_exit(-1); } printf("\n 111111111111 %d %d\n\n",fp2,fp3); ioctl(fp3,GPIO_SET_PIN_OUT,0); ioctl(fp3,GPIO_SET_PULL_DIS,0); ioctl(fp3,GPIO_CLR_PIN,0); ioctl(fp3,GPIO_SET_PIN_OUT,1); ioctl(fp3,GPIO_SET_PULL_DIS,1); ioctl(fp3,GPIO_CLR_PIN,1); ioctl(fp2,GPIO_SET_PIN_IN,3); ioctl(fp2,GPIO_SET_PIN_IN,4); ioctl(fp2,GPIO_SET_PIN_IN,5); ioctl(fp2,GPIO_SET_PIN_IN,6); ioctl(fp2,GPIO_SET_PIN_IN,7); ioctl(fp2,GPIO_SET_PULL_UP,3); ioctl(fp2,GPIO_SET_PULL_UP,4); ioctl(fp2,GPIO_SET_PULL_UP,5); ioctl(fp2,GPIO_SET_PULL_UP,6); ioctl(fp2,GPIO_SET_PULL_UP,7); ioctl(fp2,GPIO_SET_PIN,3); ioctl(fp2,GPIO_SET_PIN,4); ioctl(fp2,GPIO_SET_PIN,5); ioctl(fp2,GPIO_SET_PIN,6); ioctl(fp2,GPIO_SET_PIN,7); int fp=open("./fifo_cmd",O_WRONLY); SONGNAME *namehead=readsongname(); while(1){ printf("\n\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n"); //sleep(1); ioctl(fp3,GPIO_CLR_PIN,0); ioctl(fp3,GPIO_SET_PIN,1); read(fp2,&key_num,sizeof(key_num)); key=key_num; usleep(100*1000); read(fp2,&key_num,sizeof(key_num)); if(key==key_num){ key=key&0xf8; int flag1=0; if(key==0xf0){ printf("key1 pressed\n"); N--; if(N<0)N=10; SONGNAME *namecmd; if(N>10)N=0; char p[255]="loadfile "; namecmd=namehead; while(namecmd!=NULL){ if(namecmd->num==N){ strcat(p,namecmd->songname); disp_song_name(namecmd);//歌曲名字显示 break; } namecmd=namecmd->next; } strcat(p,"\n"); write(fp,p,strlen(p)); TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1); TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1); TFT_File_Picture(windowHZ, 167, 189, "./picture/4.bmp", 1); flag1=1; } if(key==0xe8){ printf("--------------key2 pressed-----------\n"); TFT_ClearWindow(windowHZ); execlp("poweroff","poweroff",NULL); //perror("execlp"); flag1=1; } if(key==0xd8){ printf("key3 pressed\n"); N++; SONGNAME *namecmd; if(N>10)N=0; char p[255]="loadfile "; namecmd=namehead; while(namecmd!=NULL){ if(namecmd->num==N){ strcat(p,namecmd->songname); disp_song_name(namecmd);//歌曲名字显示 break; } namecmd=namecmd->next; } strcat(p,"\n"); write(fp,p,strlen(p)); TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1); TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1); TFT_File_Picture(windowHZ, 216, 189, "./picture/5.bmp", 1); flag1=1; } if(key==0xb8){ printf("key4 pressed\n"); write(fp,"seek 5\n",strlen("seek 5\n")); TFT_File_Picture(windowHZ, 118, 189, "./picture/3.bmp", 1); flag1=1; } if(key==0x78){ printf("key5 pressed\n"); write(fp,"seek -5\n",strlen("seek -5\n")); TFT_File_Picture(windowHZ, 69, 189, "./picture/2.bmp", 1); flag1=1; } if(flag1){ while(key==(key_num&0xf8)){ read(fp2,&key,sizeof(key)); } } } /********************************************************/ ioctl(fp3,GPIO_CLR_PIN,1); ioctl(fp3,GPIO_SET_PIN,0); read(fp2,&key_num,sizeof(key_num)); key=key_num; usleep(100*1000); int flag2=0; read(fp2,&key_num,sizeof(key_num)); if(key==key_num){ key=key&0xf0; if(key==0xe0){ printf("key6 pressed\n"); write(fp,"pause\n",strlen("pause\n")); if(!pic_flag){ pic_flag=~pic_flag; TFT_File_Picture(windowHZ, 20, 189, "./picture/11.bmp", 1); } else { pic_flag=~pic_flag; TFT_File_Picture(windowHZ, 20, 189, "./picture/1.bmp", 1); } flag2=1; } if(key==0xd0){ printf("key7 pressed\n"); voice=voice+20; if(!voice_flag){ TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1); } if(voice>100){ voice=1000; write(fp,"volume 0\n",strlen("volume 0\n")); } printf("voice= %d\n",voice); TFT_File_Picture(windowHZ, 314, 189, voice_table[voice/20], 1); if(voice==0) write(fp,"volume 0 1\n",strlen("volume 0 1\n")); if(voice==20) write(fp,"volume 20 1\n",strlen("volume 20 1\n")); if(voice==40) write(fp,"volume 40 1\n",strlen("volume 40 1\n")); if(voice==60) write(fp,"volume 60 1\n",strlen("volume 60 1\n")); if(voice==80) write(fp,"volume 80 1\n",strlen("volume 80 1\n")); if(voice==100) write(fp,"volume 100 1\n",strlen("volume 100 1\n")); flag2=1; } if(key==0xb0){//静音 printf("key8 pressed\n"); if(voice_flag){ voice_flag=~voice_flag; TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1); write(fp,"mute 0\n",strlen("mute 0\n")); } else { voice_flag=~voice_flag; TFT_File_Picture(windowHZ, 265, 189, "./picture/no_voice.bmp", 1); write(fp,"mute 1\n",strlen("mute 1\n")); } flag2=1; } if(key==0x70){ printf("key9 pressed\n"); voice=voice-20; if(voice_flag){ TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1); } if(voice<0){ voice=0; write(fp,"volume 0\n",strlen("volume 0\n")); } printf("voice= %d\n",voice); TFT_File_Picture(windowHZ, 314, 189, voice_table[voice/20], 1); if(voice==0) write(fp,"volume 0 1\n",strlen("volume 0 1\n")); if(voice==20) write(fp,"volume 20 1\n",strlen("volume 20 1\n")); if(voice==40) write(fp,"volume 40 1\n",strlen("volume 40 1\n")); if(voice==60) write(fp,"volume 60 1\n",strlen("volume 60 1\n")); if(voice==80) write(fp,"volume 80 1\n",strlen("volume 80 1\n")); if(voice==100) write(fp,"volume 100 1\n",strlen("volume 100 1\n")); flag2=1; } if(flag2){ while(key==(key_num&0xf0)){ read(fp2,&key,sizeof(key)); } } } } }