3503a9d44203273c2a37b59d12cf726da41b9754
[pandora-libraries.git] / include / pnd_io_evdev.h
1
2 #ifndef h_pnd_io_evdev_h
3 #define h_pnd_io_evdev_h
4
5 // some handy routines for open/close/monitor of the evdev controller devices ..
6 // ie: so you can watch the analogs and d-pads pretty easily, for when you don't
7 // want to rely on SDL or whatever
8 //
9 // this technique works fine for nubs, d-pads, even keyboard and various buttons
10 // this API may only handle some parts for now, but you coudl easily duplicate some of the
11 // code to extend for adding keyboard.
12 //
13 // dpad, nubs, start/select/pandora, triggers all work fine as of Mar 2010.
14 //
15
16 // can get analog nubs, d-pads, or even keyboard A-Z type keys here
17 // some special ones like Power are on other devices than you'd expect, but all good
18
19 typedef enum {
20   pnd_evdev_dpads = 0,   // for d-pad and d-pad-buttons
21   pnd_evdev_nub1,
22   pnd_evdev_nub2,
23   pnd_evdev_power,
24   pnd_evdev_max
25 } pnd_evdev_e;
26
27 unsigned char pnd_evdev_open ( pnd_evdev_e device ); // returns 0 on error, >0 success
28 void pnd_evdev_close ( pnd_evdev_e device );
29 void pnd_evdev_closeall ( void );
30 int pnd_evdev_get_fd ( unsigned char handle ); // obtain actual fd from handle
31 int pnd_evdev_open_by_name ( char *devname ); // internal but handy; see device names in pnd_device.h
32
33 typedef enum {
34   pnd_evdev_left = (1<<0),     // these are bitmask; ex: (pnd_evdev_left | pnd_evdev_up)
35   pnd_evdev_right = 1<<1,
36   pnd_evdev_up = 1<<2,
37   pnd_evdev_down = 1<<3,
38   pnd_evdev_x = 1<<4,
39   pnd_evdev_y = 1<<5,
40   pnd_evdev_a = 1<<6,
41   pnd_evdev_b = 1<<7,
42   pnd_evdev_ltrigger = 1<<8,
43   pnd_evdev_rtrigger = 1<<9,
44   pnd_evdev_start = 1<<10,
45   pnd_evdev_select = 1<<11,
46   pnd_evdev_pandora = 1<<12
47 } pnd_evdev_dpad_e;
48
49 typedef struct {
50   int x;
51   int y;
52 } pnd_nubstate_t;
53
54 // catchup() - catch up any pending events
55 // return 0 if something weird happened, like device error; in that case, closeall and reopen?
56 // return 1 if looks like state is all up to date now (ie: no more events)
57 unsigned char pnd_evdev_catchup ( unsigned char blockp ); // will do all open devices
58
59 // fetch dpad state -- a mask of what buttons are pressed currently
60 // return -1 if device not open
61 int pnd_evdev_dpad_state ( pnd_evdev_e device ); // returns bitmask of pnd_evdev_dpad_e
62
63 // try to obtain X/Y axis for the requested nub
64 // r_nubstate best not be null or the behaviour is undefined. (Well, it is defined .. *catch fire*)
65 // return 1 when state is copied over
66 // return -1 when device not opened
67 int pnd_evdev_nub_state ( pnd_evdev_e nubdevice, pnd_nubstate_t *r_nubstate );
68
69 #endif