summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_libevdev
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-10-19 13:39:50 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-10-19 13:39:50 +0200
commita8ffbb76f3e3bbca547fccf5135323e06cae9d2a (patch)
treecd77a5302cb4ead5995a2a86d5b5b6324ebf43ff /ftnoir_tracker_libevdev
parent0f0d663c6263a59e2cb14f555a00b39b19c134e7 (diff)
update modules to refactored API
Diffstat (limited to 'ftnoir_tracker_libevdev')
-rw-r--r--ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp70
-rw-r--r--ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.h36
-rw-r--r--ftnoir_tracker_libevdev/ftnoir_tracker_libevdev_dll.cpp20
3 files changed, 74 insertions, 52 deletions
diff --git a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
index 8bb35314..13669cf9 100644
--- a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
+++ b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
@@ -15,38 +15,43 @@
static const int ot_libevdev_joystick_axes[6] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
-FTNoIR_Tracker::FTNoIR_Tracker() : node(nullptr), success(false)
+FTNoIR_Tracker::FTNoIR_Tracker() : node(nullptr), success(false), should_quit(false)
{
}
FTNoIR_Tracker::~FTNoIR_Tracker()
{
+ if (success)
+ {
+ should_quit = true;
+ wait();
+ }
if (node)
libevdev_free(node);
if (fd != -1)
close(fd);
}
-void FTNoIR_Tracker::StartTracker(QFrame*)
+void FTNoIR_Tracker::start_tracker(QFrame*)
{
QString node_name = s.device_name;
std::string str = (QString("/dev/input/by-id/") + node_name).toStdString();
const char* filename = str.c_str();
-
- fd = open(filename, O_NONBLOCK, O_RDWR);
+
+ fd = open(filename, 0, O_RDWR);
if (fd == -1)
{
qDebug() << "error opening" << filename;
return;
}
-
+
int ret = libevdev_new_from_fd(fd, &node);
if (ret)
{
qDebug() << "libevdev open error" << ret;
return;
}
-
+
for (int i = 0; i < 6; i++)
{
// no error checking here, errors result in SIGFPE
@@ -54,32 +59,65 @@ void FTNoIR_Tracker::StartTracker(QFrame*)
a_max[i] = libevdev_get_abs_maximum(node, ot_libevdev_joystick_axes[i]);
qDebug() << "axis limits" << i << a_min[i] << "->" << a_max[i];
}
-
+
success = true;
+
+ QThread::start();
}
-void FTNoIR_Tracker::GetHeadPoseData(double *data)
+void FTNoIR_Tracker::run()
{
- if (node)
+ bool absp = libevdev_has_event_code(node, EV_ABS, ABS_X) &&
+ !libevdev_has_event_code(node, EV_REL, ABS_X);
+ while (!should_quit)
{
- while (libevdev_has_event_pending(node) == 1)
+ struct input_event ev;
+ int status = libevdev_next_event(node, LIBEVDEV_READ_FLAG_NORMAL, &ev);
+ if (status != LIBEVDEV_READ_STATUS_SUCCESS)
+ continue;
+ if (absp)
{
- struct input_event ev;
- int status = libevdev_next_event(node, LIBEVDEV_READ_FLAG_NORMAL, &ev);
- if (status != LIBEVDEV_READ_STATUS_SUCCESS)
- continue;
if (ev.type == EV_ABS)
{
- const int val = ev.value, code = ev.code;
+ const int code = ev.code;
for (int i = 0; i < 6; i++)
{
if (ot_libevdev_joystick_axes[i] == code)
{
- data[i] = (val - a_min[i])*(i >= Yaw ? 180. : 100.) / a_max[i] - a_min[i];
+ QMutexLocker l(&mtx);
+ values[i] = ev.value;
break;
}
}
}
+ } else {
+ if (ev.type == EV_REL)
+ {
+ const int code = ev.code;
+ for (int i = 0; i < 6; i++)
+ {
+ if (ot_libevdev_joystick_axes[i] == code)
+ {
+ QMutexLocker l(&mtx);
+ values[i] += ev.value;
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+void FTNoIR_Tracker::data(double *data)
+{
+ if (node)
+ {
+ QMutexLocker l(&mtx);
+ for (int i = 0; i < 6; i++)
+ {
+ int val = values[i];
+ double v = (val - a_min[i])*(i >= Yaw ? 180. : 100.) / a_max[i] - a_min[i];
+ data[i] = v;
}
}
}
diff --git a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.h b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.h
index 2474fb35..4251435c 100644
--- a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.h
+++ b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.h
@@ -4,6 +4,9 @@
#include "facetracknoir/plugin-api.hpp"
#include "facetracknoir/options.h"
#include "./ui_ftnoir_libevdev.h"
+#include <QThread>
+#include <QMutex>
+#include <QMutexLocker>
using namespace options;
struct settings {
@@ -15,41 +18,42 @@ struct settings {
{}
};
-class FTNoIR_Tracker : public ITracker
+class FTNoIR_Tracker : public ITracker, private QThread
{
public:
- FTNoIR_Tracker();
+ FTNoIR_Tracker();
~FTNoIR_Tracker() override;
- void StartTracker(QFrame *);
- void GetHeadPoseData(double *data);
+ void start_tracker(QFrame *);
+ void data(double *data);
private:
+ void run() override;
struct libevdev* node;
int fd;
settings s;
bool success;
- int a_min[6], a_max[6];
+ int a_min[6], a_max[6], values[6];
+ QMutex mtx;
+ volatile bool should_quit;
};
-class TrackerControls: public QWidget, public ITrackerDialog
+class TrackerControls: public ITrackerDialog
{
Q_OBJECT
public:
- TrackerControls();
- void registerTracker(ITracker *) {}
- void unRegisterTracker() {}
+ TrackerControls();
+ void register_tracker(ITracker *) {}
+ void unregister_tracker() {}
private:
- Ui::ui_libevdev_tracker_dialog ui;
+ Ui::ui_libevdev_tracker_dialog ui;
settings s;
private slots:
- void doOK();
- void doCancel();
+ void doOK();
+ void doCancel();
};
class FTNoIR_TrackerDll : public Metadata
{
public:
- void getFullName(QString *strToBeFilled);
- void getShortName(QString *strToBeFilled);
- void getDescription(QString *strToBeFilled);
- void getIcon(QIcon *icon);
+ QString name() { return QString("libevdev joystick input"); }
+ QIcon icon() { return QIcon(":/images/facetracknoir.png"); }
};
diff --git a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev_dll.cpp b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev_dll.cpp
index 6ad13c8c..e6216d7f 100644
--- a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev_dll.cpp
+++ b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev_dll.cpp
@@ -1,26 +1,6 @@
#include "ftnoir_tracker_libevdev.h"
#include "facetracknoir/plugin-support.h"
-void FTNoIR_TrackerDll::getFullName(QString *strToBeFilled)
-{
- *strToBeFilled = "Joystick";
-}
-
-void FTNoIR_TrackerDll::getShortName(QString *strToBeFilled)
-{
- *strToBeFilled = "Joystick";
-}
-
-void FTNoIR_TrackerDll::getDescription(QString *strToBeFilled)
-{
- *strToBeFilled = "Joystick";
-}
-
-void FTNoIR_TrackerDll::getIcon(QIcon *icon)
-{
- *icon = QIcon(":/images/facetracknoir.png");
-}
-
extern "C" OPENTRACK_EXPORT Metadata* GetMetadata()
{
return new FTNoIR_TrackerDll;