2 // this is pulled from cpasjuste and/or pickle
4 #if defined (_PANDORA) || !defined (EMULATOR)
6 /* cribbed from pnd_keytypes.h so as to make it unnecessary */
7 #define BITS_PER_LONG (sizeof(long) * 8)
8 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
15 #include <stdlib.h> /* abs() */
16 #include <linux/input.h> /* struct input_event */
18 #include "pnd_io_gpio.h"
19 //#include "pnd_keytype.h"
20 #include "pnd_device.h"
22 unsigned char GLES2D_Pad [ pke_pad_max ];
25 int fd_usbk, fd_usbm, fd_gpio, fd_pndk, fd_nub1, fd_nub2, fd_ts, rd, i, j, k;
26 struct input_event ev[64];
29 unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
30 char dev_name[256] = "Unknown";
33 char pnd_nub1[9] = PND_EVDEV_NUB1; //"vsense66";
34 char pnd_nub2[9] = PND_EVDEV_NUB2; //"vsense67";
35 char pnd_key[19] = PND_EVDEV_KEYPAD; //"omap_twl4030keypad";
36 char pnd_gpio[10] = "gpio-keys";
43 #define NUB1_CUTOFF 100
44 #define NUB2_CUTOFF 100
47 void PND_Setup_Controls ( void ) {
48 //printf( "Setting up Pandora Controls\n" );
52 fd_pndk = PND_OpenEventDeviceByName(pnd_key);
54 fd_gpio = PND_OpenEventDeviceByName(pnd_gpio);
55 // Pandora analog nub's
56 fd_nub1 = PND_OpenEventDeviceByName(pnd_nub1);
57 fd_nub2 = PND_OpenEventDeviceByName(pnd_nub2);
61 void PND_Close_Controls ( void ) {
62 //printf( "Closing Pandora Controls\n" );
75 void PND_SendKeyEvents ( void ) {
76 PND_ReadEvents( fd_pndk, DEV_PNDK );
77 PND_ReadEvents( fd_gpio, DEV_GPIO );
78 PND_ReadEvents( fd_nub1, DEV_NUB1 );
79 PND_ReadEvents( fd_nub2, DEV_NUB2 );
82 void PND_ReadEvents ( int fd, int device ) {
86 rd = read ( fd, ev, sizeof(struct input_event) * 64 );
88 if ( rd > (int) sizeof(struct input_event) ) {
89 for (i = 0; i < rd / sizeof(struct input_event); i++) {
90 PND_CheckEvent ( &ev[i], device );
99 void PND_CheckEvent ( struct input_event *event, int device ) {
102 // printf( "Device %d Type %d Code %d Value %d\n", device, event->type, event->code, event->value );
104 value = event->value;
106 switch( event->type ) {
110 switch( event->code ) {
113 if ( event->value ) {
114 GLES2D_Pad[pke_pad_up] = 1;
116 GLES2D_Pad[pke_pad_up] = 0;
121 if ( event->value ) {
122 GLES2D_Pad[pke_pad_down] = 1;
124 GLES2D_Pad[pke_pad_down] = 0;
129 if ( event->value ) {
130 GLES2D_Pad[pke_pad_left] = 1;
132 GLES2D_Pad[pke_pad_left] = 0;
137 if ( event->value ) {
138 GLES2D_Pad[pke_pad_right] = 1;
140 GLES2D_Pad[pke_pad_right] = 0;
145 if ( event->value ) {
146 GLES2D_Pad[pke_pad_menu] = 1;
148 GLES2D_Pad[pke_pad_menu] = 0;
153 if ( event->value ) printf("START\n");
157 if ( event->value ) printf("SELECT\n");
161 if ( event->value ) {
162 GLES2D_Pad[pke_pad_x] = 1;
164 GLES2D_Pad[pke_pad_x] = 0;
169 if ( event->value ) {
170 GLES2D_Pad[pke_pad_y] = 1;
172 GLES2D_Pad[pke_pad_y] = 0;
177 if ( event->value ) {
178 GLES2D_Pad[pke_pad_a] = 1;
180 GLES2D_Pad[pke_pad_a] = 0;
185 if ( event->value ) {
186 GLES2D_Pad[pke_pad_b] = 1;
188 GLES2D_Pad[pke_pad_b] = 0;
193 if ( event->value ) {
194 GLES2D_Pad[pke_pad_l] = 1;
196 GLES2D_Pad[pke_pad_l] = 0;
201 if ( event->value ) {
202 GLES2D_Pad[pke_pad_r] = 1;
204 GLES2D_Pad[pke_pad_r] = 0;
218 if ( event->code == ABS_X ) {
219 //printf( "nub1 x %3d\n", value );
220 if( abs(value) > NUB1_CUTOFF ) {
223 } else if( value < 0 ) {
230 if( event->code == ABS_Y ) {
231 //printf( "nub1 y %3d\n", value );
232 if( abs(value) > NUB1_CUTOFF ) {
235 } else if( value < 0 ) {
244 if(event->code == ABS_X) {
245 //printf( "nub2 x %3d\n", value );
246 if( abs(value) > NUB2_CUTOFF ) {
249 } else if( value < 0 ) {
256 if(event->code == ABS_Y) {
257 //printf( "nub2 y %3d\n", value );
258 if( abs(value) > NUB2_CUTOFF ) {
261 } else if( value < 0 ) {
276 int PND_OpenEventDeviceByID ( int event_id ) {
279 snprintf( event_name, sizeof(event_name), "/dev/input/event%d", event_id );
280 printf( "Device: %s\n", event_name );
281 if ((fd = open(event_name, O_RDONLY | O_NDELAY)) < 0) {
282 perror("ERROR: Could not open device");
286 if (ioctl(fd, EVIOCGVERSION, &version)) {
287 perror("evtest: can't get version");
291 printf("Input driver version is %d.%d.%d\n",
292 version >> 16, (version >> 8) & 0xff, version & 0xff);
294 ioctl(fd, EVIOCGID, id);
295 printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
296 id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);
298 ioctl(fd, EVIOCGNAME(sizeof(dev_name)), dev_name);
299 printf("Input device name: \"%s\"\n", dev_name);
304 int PND_OpenEventDeviceByName ( char device_name[] ) {
307 for (i = 0; 1; i++) {
309 snprintf( event_name, sizeof(event_name), "/dev/input/event%d", i );
310 printf( "Device: %s\n", event_name );
311 if ((fd = open(event_name, O_RDONLY | O_NDELAY)) < 0) {
312 perror("ERROR: Could not open device");
316 if (fd < 0) break; /* no more devices */
318 ioctl(fd, EVIOCGNAME(sizeof(dev_name)), dev_name);
319 if (strcmp(dev_name, device_name) == 0) {
321 if (ioctl(fd, EVIOCGVERSION, &version)) {
322 perror("evtest: can't get version");
326 printf("Input driver version is %d.%d.%d\n",
327 version >> 16, (version >> 8) & 0xff, version & 0xff);
329 ioctl(fd, EVIOCGID, id);
330 printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
331 id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);
333 ioctl(fd, EVIOCGNAME(sizeof(dev_name)), dev_name);
334 printf("Input device name: \"%s\"\n", dev_name);
339 close(fd); /* we don't need this device */
345 int PND_Pad_RecentlyPressed ( pnd_keytype_e num ) {
346 static int GLES2D_Pad_old [ pke_pad_max ];
348 if ( !GLES2D_Pad_old[num] && GLES2D_Pad[num] ) {
349 GLES2D_Pad_old[num] = GLES2D_Pad[num];
353 GLES2D_Pad_old[num] = GLES2D_Pad[num];