summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-09-16 23:54:16 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-09-16 23:54:16 +0200
commit40f95d58324609d74b1e3a7ff81d4ef3b2388550 (patch)
tree4f3e3ec2b38fa56ef0de3929a0395ad8817c6bc6 /ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp
parentad37ec007baf1170657ba51baea44688c52290e0 (diff)
proto-libevdev: first version. NEEDS UDEV RULE
Diffstat (limited to 'ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp')
-rw-r--r--ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp57
1 files changed, 39 insertions, 18 deletions
diff --git a/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp
index 6f34d20b..74986299 100644
--- a/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp
+++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp
@@ -1,37 +1,52 @@
#include "ftnoir_protocol_libevdev.h"
#include "facetracknoir/global-settings.h"
//#include "ftnoir_tracker_base/ftnoir_tracker_types.h"
+#include <cstdio>
+#include <algorithm>
-#define CHECK_LIBEVDEV(expr) if ((expr) != 0) goto error;
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#define CHECK_LIBEVDEV(expr) if (error = (expr) != 0) goto error;
+
+static const int max_input = 8192;
+static const int mid_input = 4096;
+static const int min_input = 0;
+
+#define HT_PI 3.1415926535
FTNoIR_Protocol::FTNoIR_Protocol() : dev(NULL), uidev(NULL)
{
- int error;
+ int error = 0;
dev = libevdev_new();
if (!dev)
goto error;
+ CHECK_LIBEVDEV(libevdev_enable_property(dev, INPUT_PROP_BUTTONPAD));
+
libevdev_set_name(dev, "opentrack headpose");
struct input_absinfo absinfo;
- absinfo.minimum = -ABS_MAX;
- absinfo.maximum = ABS_MAX;
- absinfo.resolution= 1; /* units per radian? let's go shopping */
- absinfo.value = 0;
- absinfo.fuzz = 1; /* no filtering in evdev subsystem, we do our own */
+ absinfo.minimum = min_input;
+ absinfo.maximum = max_input;
+ absinfo.resolution = 1;
+ absinfo.value = mid_input;
+ absinfo.flat = 8192 / 180;
+ absinfo.fuzz = 1;
+
+ CHECK_LIBEVDEV(libevdev_enable_event_type(dev, EV_ABS));
+ CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_X, &absinfo));
+ CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_Y, &absinfo));
+ CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_Z, &absinfo));
+ CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_RX, &absinfo));
+ CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_RY, &absinfo));
- CHECK_LIBEVDEV(libevdev_enable_event_type(dev, EV_ABS))
- CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_X, &absinfo))
- CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_Y, &absinfo))
- CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_Z, &absinfo))
- CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_RX, &absinfo))
- CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_RY, &absinfo))
- CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_RZ, &absinfo))
+ CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_ABS, ABS_RZ, &absinfo));
- CHECK_LIBEVDEV(error = libevdev_uinput_create_from_device(dev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uidev))
+ CHECK_LIBEVDEV(libevdev_uinput_create_from_device(dev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uidev));
return;
error:
@@ -39,6 +54,8 @@ error:
libevdev_uinput_destroy(uidev);
if (dev)
libevdev_free(dev);
+ if (error)
+ fprintf(stderr, "libevdev error: %d\n", error);
uidev = NULL;
dev = NULL;
}
@@ -60,15 +77,19 @@ void FTNoIR_Protocol::sendHeadposeToGame( double *headpose, double *rawheadpose
2,
2,
2,
- 2, /* | pitch | only goes to 90 */
- 1,
+ 2,
+ 1, /* |pitch| only goes to 90 */
2
};
const int max_euler = 90;
for (int i = 0; i < 6; i++)
- (void) libevdev_uinput_write_event(uidev, EV_ABS, axes[i], ranges[i] * headpose[i] * max_euler / ABS_MAX);
+ {
+ int value = headpose[i] * mid_input / (max_euler * ranges[i]) + mid_input;
+ int normalized = std::max(std::min(max_input, value), min_input);
+ (void) libevdev_uinput_write_event(uidev, EV_ABS, axes[i], normalized);
+ }
}
extern "C" FTNOIR_PROTOCOL_BASE_EXPORT IProtocol* CALLING_CONVENTION GetConstructor()