From ad37ec007baf1170657ba51baea44688c52290e0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 16 Sep 2013 22:16:21 +0200 Subject: initial libevdev impl --- .../ftnoir_libevdev_controls.ui | 111 +++++++++++++++++++++ .../ftnoir_protocol_libevdev.cpp | 77 ++++++++++++++ .../ftnoir_protocol_libevdev.h | 72 +++++++++++++ .../ftnoir_protocol_libevdev_dialog.cpp | 41 ++++++++ .../ftnoir_protocol_libevdev_dll.cpp | 16 +++ ftnoir_protocol_libevdev/libevdev-protocol.qrc | 5 + 6 files changed, 322 insertions(+) create mode 100644 ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui create mode 100644 ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp create mode 100644 ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.h create mode 100644 ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dialog.cpp create mode 100644 ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dll.cpp create mode 100644 ftnoir_protocol_libevdev/libevdev-protocol.qrc diff --git a/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui b/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui new file mode 100644 index 00000000..f9a55547 --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui @@ -0,0 +1,111 @@ + + + UICVJoyControls + + + Qt::ApplicationModal + + + + 0 + 0 + 228 + 69 + + + + VJoy + + + + :/images/vjoy.png:/images/vjoy.png + + + Qt::LeftToRight + + + false + + + + + + Make sure rw for /dev/input/uinput! + + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + OK + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Cancel + + + + + + + + + + + btnOK + btnCancel + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp new file mode 100644 index 00000000..6f34d20b --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp @@ -0,0 +1,77 @@ +#include "ftnoir_protocol_libevdev.h" +#include "facetracknoir/global-settings.h" +//#include "ftnoir_tracker_base/ftnoir_tracker_types.h" + +#define CHECK_LIBEVDEV(expr) if ((expr) != 0) goto error; + +FTNoIR_Protocol::FTNoIR_Protocol() : dev(NULL), uidev(NULL) +{ + int error; + + dev = libevdev_new(); + + if (!dev) + goto error; + + 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 */ + + 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(error = libevdev_uinput_create_from_device(dev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uidev)) + + return; +error: + if (uidev) + libevdev_uinput_destroy(uidev); + if (dev) + libevdev_free(dev); + uidev = NULL; + dev = NULL; +} + +FTNoIR_Protocol::~FTNoIR_Protocol() +{ + if (uidev) + libevdev_uinput_destroy(uidev); + if (dev) + libevdev_free(dev); +} + +void FTNoIR_Protocol::sendHeadposeToGame( double *headpose, double *rawheadpose ) { + static const int axes[] = { + /* translation goes first */ + ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ + }; + static const int ranges[] = { + 2, + 2, + 2, + 2, /* | pitch | only goes to 90 */ + 1, + 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); +} + +extern "C" FTNOIR_PROTOCOL_BASE_EXPORT IProtocol* CALLING_CONVENTION GetConstructor() +{ + return new FTNoIR_Protocol; +} diff --git a/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.h b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.h new file mode 100644 index 00000000..b71738f1 --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.h @@ -0,0 +1,72 @@ +/* Copyright (c) 2013 Stanislaw Halik + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ +#pragma once +#include "ftnoir_protocol_base/ftnoir_protocol_base.h" +#include "ui_ftnoir_libevdev_controls.h" + +#include +#include +#include "facetracknoir/global-settings.h" + +#include +#include + +class FTNoIR_Protocol : public IProtocol +{ +public: + FTNoIR_Protocol(); + ~FTNoIR_Protocol(); + bool checkServerInstallationOK() { + return dev != NULL; + } + void sendHeadposeToGame( double *headpose, double *rawheadpose ); + QString getGameName() { + return "Virtual joystick for Linux"; + } +private: + struct libevdev* dev; + struct libevdev_uinput* uidev; +}; + +// Widget that has controls for FTNoIR protocol client-settings. +class LibevdevControls: public QWidget, public IProtocolDialog +{ + Q_OBJECT +public: + + explicit LibevdevControls(); + virtual ~LibevdevControls(); + void showEvent ( QShowEvent *) {} + + void Initialize(QWidget *); + void registerProtocol(IProtocol *l) {} + void unRegisterProtocol() {} + +private: + Ui::UICVJoyControls ui; + void save(); + +private slots: + void doOK(); + void doCancel(); +}; + +//******************************************************************************************************* +// FaceTrackNoIR Protocol DLL. Functions used to get general info on the Protocol +//******************************************************************************************************* +class FTNoIR_ProtocolDll : public Metadata +{ +public: + FTNoIR_ProtocolDll(); + ~FTNoIR_ProtocolDll(); + + void getFullName(QString *strToBeFilled) { *strToBeFilled = QString("libevdev"); } + void getShortName(QString *strToBeFilled) { *strToBeFilled = QString("libevdev"); } + void getDescription(QString *strToBeFilled) { *strToBeFilled = QString("libevdev"); } + + void getIcon(QIcon *icon) { *icon = QIcon(":/images/linux.png"); } +}; diff --git a/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dialog.cpp b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dialog.cpp new file mode 100644 index 00000000..6665a3d2 --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dialog.cpp @@ -0,0 +1,41 @@ +#include "ftnoir_protocol_libevdev.h" +#include "facetracknoir/global-settings.h" + +LibevdevControls::LibevdevControls() : QWidget() +{ + ui.setupUi( this ); + connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); + connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); +} + +LibevdevControls::~LibevdevControls() { +} + +// +// Initialize tracker-client-dialog +// +void LibevdevControls::Initialize(QWidget *parent) { + + QPoint offsetpos(100, 100); + if (parent) { + this->move(parent->pos() + offsetpos); + } + show(); +} + +void LibevdevControls::doOK() { + save(); + this->close(); +} + +void LibevdevControls::doCancel() { + this->close(); +} + +void LibevdevControls::save() { +} + +extern "C" FTNOIR_PROTOCOL_BASE_EXPORT IProtocolDialog* CALLING_CONVENTION GetDialog( ) +{ + return new LibevdevControls; +} diff --git a/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dll.cpp b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dll.cpp new file mode 100644 index 00000000..79a22d5e --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dll.cpp @@ -0,0 +1,16 @@ +#include "ftnoir_protocol_libevdev.h" +#include +#include "facetracknoir/global-settings.h" + +FTNoIR_ProtocolDll::FTNoIR_ProtocolDll() { +} + +FTNoIR_ProtocolDll::~FTNoIR_ProtocolDll() +{ + +} + +extern "C" FTNOIR_PROTOCOL_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata() +{ + return new FTNoIR_ProtocolDll; +} diff --git a/ftnoir_protocol_libevdev/libevdev-protocol.qrc b/ftnoir_protocol_libevdev/libevdev-protocol.qrc new file mode 100644 index 00000000..70bb415f --- /dev/null +++ b/ftnoir_protocol_libevdev/libevdev-protocol.qrc @@ -0,0 +1,5 @@ + + + images/linux.png + + -- cgit v1.2.3