📄 buttonsample.c
字号:
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++File Name: buttonsample.cAbstract: demo program for using button bond/restore buttons(connected to gpg0/gpg2) driverAuthor: Huiqing GuoRevision History: 2007.10 created---------------------------------------------------------------------------*/#include <stdio.h>#include <fcntl.h>#include <pthread.h>void bond_button_thread(void){ int fileno; char readvalue; struct sched_param threadparam; int staticpriority; //NOTE: //In order to decrease the delay time,we should set this thread to be real-time thread. //And the static priority should be configured according to the real environment in which //this thread running. staticpriority = sched_get_priority_min(SCHED_FIFO); threadparam.__sched_priority = staticpriority; sched_setscheduler(0,SCHED_FIFO,&threadparam); fileno = open("/dev/btn_update",O_RDONLY); if (fileno == -1){ printf("open device bondbutton error!\n"); return ; } while(1){ if(read(fileno, &readvalue,1)==-1){ printf("read failure\n"); close(fileno); return ; } if(readvalue=='1'){ printf("bondbutton checked a short time button press!\n"); } else{ printf("bondbutton checked a long time button press!\n"); } } close(fileno); return;}void restore_button_thread(void){ int fileno; int readvalue; struct sched_param threadparam; int staticpriority; //NOTE: //In order to decrease the delay time,we should set this thread to be real-time thread. //And the static priority should be configured according to the real environment in which //this thread running. staticpriority = sched_get_priority_min(SCHED_FIFO); threadparam.__sched_priority = staticpriority; sched_setscheduler(0,SCHED_FIFO,&threadparam); fileno = open("/dev/btn_upload",O_RDONLY); if (fileno == -1){ printf("open device bondbutton error!\n"); return ; } while(1) { if(read(fileno, &readvalue,1)==-1) { printf("read failure\n"); close(fileno); return ; } if(readvalue <= 100) { printf("restorebutton checked a short time button press!\n"); } else { printf("restorebutton checked a long time button press!\n"); } } close(fileno); return;}int main(void){ pthread_t threadid; pthread_create(&threadid,NULL,(void*)bond_button_thread,NULL);//create the dameon thread pthread_create(&threadid,NULL,(void*)restore_button_thread,NULL);//create the dameon thread pthread_join(threadid,NULL);//wait,until the dameon thread terminate return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -