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