diff options
Diffstat (limited to 'firmware/target/hosted/agptek/button-agptek.c')
-rw-r--r-- | firmware/target/hosted/agptek/button-agptek.c | 84 |
1 files changed, 1 insertions, 83 deletions
diff --git a/firmware/target/hosted/agptek/button-agptek.c b/firmware/target/hosted/agptek/button-agptek.c index 2c84a50405..8fc676acec 100644 --- a/firmware/target/hosted/agptek/button-agptek.c +++ b/firmware/target/hosted/agptek/button-agptek.c | |||
@@ -17,25 +17,13 @@ | |||
17 | * KIND, either express or implied. | 17 | * KIND, either express or implied. |
18 | * | 18 | * |
19 | ****************************************************************************/ | 19 | ****************************************************************************/ |
20 | #include <poll.h> | ||
21 | //#include <dir.h> | ||
22 | #include <errno.h> | ||
23 | #include <unistd.h> | ||
24 | #include <sys/types.h> | ||
25 | #include <linux/input.h> | 20 | #include <linux/input.h> |
26 | #include <fcntl.h> | ||
27 | #include <string.h> | ||
28 | #include <stdlib.h> | ||
29 | 21 | ||
30 | #include "sysfs.h" | 22 | #include "sysfs.h" |
31 | #include "button.h" | 23 | #include "button.h" |
32 | #include "button-target.h" | 24 | #include "button-target.h" |
33 | #include "panic.h" | ||
34 | 25 | ||
35 | #define NR_POLL_DESC 2 | 26 | int button_map(int keycode) |
36 | static struct pollfd poll_fds[NR_POLL_DESC]; | ||
37 | |||
38 | static int button_map(int keycode) | ||
39 | { | 27 | { |
40 | switch(keycode) | 28 | switch(keycode) |
41 | { | 29 | { |
@@ -68,67 +56,6 @@ static int button_map(int keycode) | |||
68 | } | 56 | } |
69 | } | 57 | } |
70 | 58 | ||
71 | void button_init_device(void) | ||
72 | { | ||
73 | const char * const input_devs[NR_POLL_DESC] = { | ||
74 | "/dev/input/event0", | ||
75 | "/dev/input/event1" | ||
76 | }; | ||
77 | |||
78 | for(int i = 0; i < NR_POLL_DESC; i++) | ||
79 | { | ||
80 | int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC); | ||
81 | |||
82 | if(fd < 0) | ||
83 | { | ||
84 | panicf("Cannot open input device: %s\n", input_devs[i]); | ||
85 | } | ||
86 | |||
87 | poll_fds[i].fd = fd; | ||
88 | poll_fds[i].events = POLLIN; | ||
89 | poll_fds[i].revents = 0; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | int button_read_device(void) | ||
94 | { | ||
95 | static int button_bitmap = 0; | ||
96 | struct input_event event; | ||
97 | |||
98 | /* check if there are any events pending and process them */ | ||
99 | while(poll(poll_fds, NR_POLL_DESC, 0)) | ||
100 | { | ||
101 | for(int i = 0; i < NR_POLL_DESC; i++) | ||
102 | { | ||
103 | /* read only if non-blocking */ | ||
104 | if(poll_fds[i].revents & POLLIN) | ||
105 | { | ||
106 | int size = read(poll_fds[i].fd, &event, sizeof(event)); | ||
107 | if(size == (int)sizeof(event)) | ||
108 | { | ||
109 | int keycode = event.code; | ||
110 | /* event.value == 0x10000 means press | ||
111 | * event.value == 0 means release | ||
112 | */ | ||
113 | bool press = event.value ? true : false; | ||
114 | |||
115 | /* map linux event code to rockbox button bitmap */ | ||
116 | if(press) | ||
117 | { | ||
118 | button_bitmap |= button_map(keycode); | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | button_bitmap &= ~button_map(keycode); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | return button_bitmap; | ||
130 | } | ||
131 | |||
132 | bool headphones_inserted(void) | 59 | bool headphones_inserted(void) |
133 | { | 60 | { |
134 | int status = 0; | 61 | int status = 0; |
@@ -137,12 +64,3 @@ bool headphones_inserted(void) | |||
137 | 64 | ||
138 | return status ? true : false; | 65 | return status ? true : false; |
139 | } | 66 | } |
140 | |||
141 | void button_close_device(void) | ||
142 | { | ||
143 | /* close descriptors */ | ||
144 | for(int i = 0; i < NR_POLL_DESC; i++) | ||
145 | { | ||
146 | close(poll_fds[i].fd); | ||
147 | } | ||
148 | } | ||