Skip to content

Commit

Permalink
Added my own evdev handler for dpad/dpadbuttons/nubs, works fantastic
Browse files Browse the repository at this point in the history
  • Loading branch information
skeezix committed Mar 15, 2010
1 parent 8a4b1c8 commit e29a953
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ LIB = libpnd.a
SOLIB = libpnd.so.1 # canonicle name
SOLIB1 = libpnd.so.1.0.1 # versioned name
XMLOBJ = lib/tinyxml/tinystr.o lib/tinyxml/tinyxml.o lib/tinyxml/tinyxmlerror.o lib/tinyxml/tinyxmlparser.o
ALLOBJ = pnd_conf.o pnd_container.o pnd_discovery.o pnd_pxml.o pnd_notify.o pnd_locate.o pnd_tinyxml.o pnd_pndfiles.o pnd_apps.o pnd_utility.o pnd_desktop.o pnd_io_gpio.o pnd_logger.o pnd_dbusnotify.o pnd_device.o
ALLOBJ = pnd_conf.o pnd_container.o pnd_discovery.o pnd_pxml.o pnd_notify.o pnd_locate.o pnd_tinyxml.o pnd_pndfiles.o pnd_apps.o pnd_utility.o pnd_desktop.o pnd_io_gpio.o pnd_io_ioctl.o pnd_io_evdev.o pnd_logger.o pnd_dbusnotify.o pnd_device.o

all: ${SOLIB} ${LIB} conftest discotest notifytest pndnotifyd rawpxmltest pndvalidator loggertest dbusnotifytest pnd_run pndevmapperd pnd_info evtest mmenu mmwrapper
all: ${SOLIB} ${LIB} conftest discotest evdevtest notifytest pndnotifyd rawpxmltest pndvalidator loggertest dbusnotifytest pnd_run pndevmapperd pnd_info evtest mmenu mmwrapper

clean:
${RM} -f ${ALLOBJ} ${XMLOBJ} ${LIB} ${SOLIB1} locatetest.o bin/locatetest conftest.o bin/conftest discotest.o bin/discotest dbusnotifytest.o bin/dbusnotifytest loggertest.o bin/loggertest bin/notifytest notifytest.o bin/rawpxmltest rawpxmltest.o bin/pnd_run pnd_run.o pnd_info.o bin/pnd_info bin/pndevmapperd pndevmapperd.o bin/pndnotifyd pndnotifyd.o ${SOLIB} testdata/dotdesktop/*.desktop testdata/menu/*.desktop testdata/apps/*.pnd testdata/dotdesktop/*.png deployment/usr/lib/libpnd* deployment/usr/bin/pndnotifyd deployment/usr/bin/pnd_run deployment/usr/bin/pnd_info deployment/usr/pandora/scripts/* deployment/etc/sudoers deployment/etc/init.d/pndnotifyd bin/pndvalidator pndvalidator.o deployment/usr/bin/pndevmapperd testdata/menuicons/* evtest.o bin/evtest bin/mmenu bin/mmwrapper mmenu.o mmwrapper.o deployment/usr/bin/mmenu deployment/usr/bin/mmwrapper mmcache.o mmui.o mmcat.o
${RM} -f ${ALLOBJ} ${XMLOBJ} ${LIB} ${SOLIB1} locatetest.o bin/locatetest conftest.o bin/conftest discotest.o evdevtest.o bin/evdevtest bin/discotest dbusnotifytest.o bin/dbusnotifytest loggertest.o bin/loggertest bin/notifytest notifytest.o bin/rawpxmltest rawpxmltest.o bin/pnd_run pnd_run.o pnd_info.o bin/pnd_info bin/pndevmapperd pndevmapperd.o bin/pndnotifyd pndnotifyd.o ${SOLIB} testdata/dotdesktop/*.desktop testdata/menu/*.desktop testdata/apps/*.pnd testdata/dotdesktop/*.png deployment/usr/lib/libpnd* deployment/usr/bin/pndnotifyd deployment/usr/bin/pnd_run deployment/usr/bin/pnd_info deployment/usr/pandora/scripts/* deployment/etc/sudoers deployment/etc/init.d/pndnotifyd bin/pndvalidator pndvalidator.o deployment/usr/bin/pndevmapperd testdata/menuicons/* evtest.o bin/evtest bin/mmenu bin/mmwrapper mmenu.o mmwrapper.o deployment/usr/bin/mmenu deployment/usr/bin/mmwrapper mmcache.o mmui.o mmcat.o
${RM} -rf deployment/media deployment/etc/pandora/mmenu
find . -name "*~*" -exec rm {} \; -print

Expand Down Expand Up @@ -114,6 +114,9 @@ conftest: conftest.o ${LIB}
discotest: discotest.o ${LIB}
${CC} -lstdc++ -o bin/discotest discotest.o libpnd.a

evdevtest: evdevtest.o ${LIB}
${CC} -lstdc++ -o bin/evdevtest evdevtest.o -static libpnd.a

notifytest: notifytest.o ${LIB}
${CC} -lstdc++ -o bin/notifytest notifytest.o libpnd.a

Expand Down
8 changes: 8 additions & 0 deletions include/pnd_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ extern "C" {
#define PND_DEVICE_LED_BT "/sys/class/leds/pandora::bluetooth"
#define PND_DEVICE_LED_SUFFIX_BRIGHTNESS "/brightness"

// device names
#define PND_EVDEV_NUB1 "vsense66"
#define PND_EVDEV_NUB2 "vsense67"
#define PND_EVDEV_KEYPAD "omap_twl4030keypad"
#define PND_EVDEV_GPIO "gpio-keys"
#define PND_EVDEV_TS "ADS784x Touchscreen"
#define PND_EVDEV_POWER "triton2-pwrbutton"

/* utility
*/
unsigned char pnd_device_open_write_close ( char *name, char *v );
Expand Down
69 changes: 69 additions & 0 deletions include/pnd_io_evdev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

#ifndef h_pnd_io_evdev_h
#define h_pnd_io_evdev_h

// some handy routines for open/close/monitor of the evdev controller devices ..
// ie: so you can watch the analogs and d-pads pretty easily, for when you don't
// want to rely on SDL or whatever
//
// this technique works fine for nubs, d-pads, even keyboard and various buttons
// this API may only handle some parts for now, but you coudl easily duplicate some of the
// code to extend for adding keyboard.
//
// dpad, nubs, start/select/pandora, triggers all work fine as of Mar 2010.
//

// can get analog nubs, d-pads, or even keyboard A-Z type keys here
// some special ones like Power are on other devices than you'd expect, but all good

typedef enum {
pnd_evdev_dpads = 0, // for d-pad and d-pad-buttons
pnd_evdev_nub1,
pnd_evdev_nub2,
pnd_evdev_power,
pnd_evdev_max
} pnd_evdev_e;

unsigned char pnd_evdev_open ( pnd_evdev_e device ); // returns 0 on error, >0 success
void pnd_evdev_close ( pnd_evdev_e device );
void pnd_evdev_closeall ( void );
int pnd_evdev_get_fd ( unsigned char handle ); // obtain actual fd from handle
int pnd_evdev_open_by_name ( char *devname ); // internal but handy; see device names in pnd_device.h

typedef enum {
pnd_evdev_left = (1<<0), // these are bitmask; ex: (pnd_evdev_left | pnd_evdev_up)
pnd_evdev_right = 1<<1,
pnd_evdev_up = 1<<2,
pnd_evdev_down = 1<<3,
pnd_evdev_x = 1<<4,
pnd_evdev_y = 1<<5,
pnd_evdev_a = 1<<6,
pnd_evdev_b = 1<<7,
pnd_evdev_ltrigger = 1<<8,
pnd_evdev_rtrigger = 1<<9,
pnd_evdev_start = 1<<10,
pnd_evdev_select = 1<<11,
pnd_evdev_pandora = 1<<12
} pnd_evdev_dpad_e;

typedef struct {
int x;
int y;
} pnd_nubstate_t;

// catchup() - catch up any pending events
// return 0 if something weird happened, like device error; in that case, closeall and reopen?
// return 1 if looks like state is all up to date now (ie: no more events)
unsigned char pnd_evdev_catchup ( unsigned char blockp ); // will do all open devices

// fetch dpad state -- a mask of what buttons are pressed currently
// return -1 if device not open
int pnd_evdev_dpad_state ( pnd_evdev_e device ); // returns bitmask of pnd_evdev_dpad_e

// try to obtain X/Y axis for the requested nub
// r_nubstate best not be null or the behaviour is undefined. (Well, it is defined .. *catch fire*)
// return 1 when state is copied over
// return -1 when device not opened
int pnd_evdev_nub_state ( pnd_evdev_e nubdevice, pnd_nubstate_t *r_nubstate );

#endif
9 changes: 9 additions & 0 deletions include/pnd_io_ioctl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef h_pnd_io_ioctl_h
#define h_pnd_io_ioctl_h

// this is a simple 'is key pressed?' type routine, using standard ioctl; if you don't want to
// monitor the events and just ewant to see whats up, this can be handy.
// returns -1 on error, 0 for 'not down', and >0 for 'is down'
int pnd_is_key_down ( int fd, int key );

#endif
Loading

0 comments on commit e29a953

Please sign in to comment.