-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.c
executable file
·133 lines (118 loc) · 3.01 KB
/
key.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* comm.c
* Authors: zorro, modify
* Rickard E. (Rik) Faith <faith@redhat.com>
* handle the key signal and uart cmd
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <linux/input.h>
#include "key.h"
static struct input_event event;
/*===============key_thread================
*Function: read the key button,and set the enable record flag
*Author: zorro
*Date :6/1/2015
*======================================*/
int
key_thread(void *arg)
{
int rc;
int fd = 0;
int enable_record=0;
int *argtmp;
argtmp=arg;
//int e,d;
/*open the /dev/input/event of key*/
if ((fd = open(DEV_PATH, O_RDONLY, 0)) < 0) {
printf("\nzorro %s: open failed, fd = %d\n", DEV_PATH, fd);
return 0;
}
/*read the key event*/
while ((rc = read(fd, &event, sizeof(event))) > 0) {
printf("key enent : %-24.24s.%06lu type 0x%04x; code 0x%04x;"
" value 0x%08x ;\n\n",
ctime(&event.time.tv_sec),
event.time.tv_usec,
event.type, event.code, event.value);
if (event.type == EV_KEY) {
if (event.code > BTN_MISC) {
printf("Button %d %s",
event.code & 0xff,
event.value ? "press" : "release");
} else {
printf("Key %d (0x%x) %s",
event.code & 0xff,
event.code & 0xff,
event.value ? "press" : "release");
/*
e=*argtmp/10;
d=*argtmp%10;
if ((event.code & 0xff) == 0x0073)//115 key value(vol up)
{
if(event.value==0)//release
{
if (e)//10 bit
{
*argtmp=*argtmp-10;
}
else
{
*argtmp=*argtmp+10;
}
printf("enc mode change to %d\n",*argtmp);
}
}
if ((event.code & 0xff) == 0x0072)//114 key value(vol dn)
{
if(event.value==0)//release
{
if (d)// 1 bit
{
*argtmp=*argtmp-1;
}
else
{
*argtmp=*argtmp+1;
}
printf("dec mode change to %d\n",*argtmp);
}
}
*/
if ((event.code & 0xff) == 0x0072)//114 key value(vol dn)
{
if(event.value==0)//release
{
if (*argtmp==1)// 1 bit
{
printf("dec mode change to enc:%d\n",*argtmp);
*argtmp=10;
}
else
{
printf("enc mode change to dec :%d\n",*argtmp);
*argtmp=1;
}
}
}
// enable_record += (int)event.value; /*Even number represents Enable, odd number Disable*/
}
}
}
printf("rc = %d, (%s)\n", rc, strerror(errno));
close(fd);
return 0;
}
//
#if _INDEPENDENT_
int main(int argc, char *argv[])
{
key_thread(argv[1]);
}
#endif