summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/accelerometers.c35
-rw-r--r--src/types.h1
2 files changed, 36 insertions, 0 deletions
diff --git a/src/accelerometers.c b/src/accelerometers.c
index 61118fc..8f13114 100644
--- a/src/accelerometers.c
+++ b/src/accelerometers.c
@@ -45,6 +45,7 @@ struct input_event {
};
#define EV_SYN (0x00)
#define EV_REL (0x02)
+#define EV_ABS (0x03)
#define SYN_REPORT (0x00)
#define REL_X (0x00)
#define REL_Y (0x01)
@@ -66,6 +67,13 @@ AccelHandle *accelerometer_open() {
accel->type = ACCEL_UNKNOWN;
/* Determine accelerometer type */
+ accel->fd = open("/dev/input/by-path/platform-hdaps-event-joystick", O_RDONLY, O_NONBLOCK);
+ if ( accel->fd != -1 ) {
+ accel->type = ACCEL_HDAPS;
+ printf("ThinkPad HDAPS detected\n");
+ return accel;
+ }
+
accel->fd = open("/dev/input/event3", O_RDONLY, O_NONBLOCK);
if ( accel->fd != -1 ) {
accel->type = ACCEL_FREERUNNER;
@@ -80,6 +88,29 @@ AccelHandle *accelerometer_open() {
}
+void accelerometer_update_hdaps(AccelHandle *accel) {
+
+ struct input_event ev;
+ size_t rval;
+
+ rval = read(accel->fd, &ev, sizeof(ev));
+ if ( rval != sizeof(ev) ) {
+ fprintf(stderr, "Couldn't read accelerometer data");
+ return;
+ }
+ if (ev.type == EV_ABS && ev.code == REL_Y)
+ // This is the result of some experimentation
+ accel->y = -600 + abs(ev.value) * 12;
+
+ /*
+ fprintf(stderr, "Event: time %ld.%06ld, type %s, code %d, value %d\n",
+ ev.time.tv_sec, ev.time.tv_usec,
+ ev.type == EV_REL ? "REL" :
+ ev.type == EV_ABS ? "ABS" : "Other" ,
+ ev.code, ev.value);
+ */
+
+}
void accelerometer_update_freerunner(AccelHandle *accel) {
struct input_event ev;
@@ -123,6 +154,10 @@ void accelerometer_update(AccelHandle *accel) {
accelerometer_update_freerunner(accel);
break;
}
+ case ACCEL_HDAPS : {
+ accelerometer_update_hdaps(accel);
+ break;
+ }
/* Add other types here. You simply need to provide the "y"
* component of acceleration in milli-g in the relevant
* structure. */
diff --git a/src/types.h b/src/types.h
index b864742..eae97b6 100644
--- a/src/types.h
+++ b/src/types.h
@@ -33,6 +33,7 @@
typedef enum {
ACCEL_UNKNOWN,
ACCEL_FREERUNNER, /* Openmoko Neo Freerunner */
+ ACCEL_HDAPS, /* Thinkpad HDAPS */
} AccelType;
typedef struct {