diff options
Diffstat (limited to 'ftnoir_protocol_libevdev')
-rw-r--r-- | ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui | 111 | ||||
-rw-r--r-- | ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp | 101 | ||||
-rw-r--r-- | ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.h | 69 | ||||
-rw-r--r-- | ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dialog.cpp | 26 | ||||
-rw-r--r-- | ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dll.cpp | 16 | ||||
-rw-r--r-- | ftnoir_protocol_libevdev/images/linux.png | bin | 0 -> 668 bytes | |||
-rw-r--r-- | ftnoir_protocol_libevdev/libevdev-protocol.qrc | 5 |
7 files changed, 328 insertions, 0 deletions
diff --git a/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui b/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui new file mode 100644 index 00000000..d2b86445 --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui @@ -0,0 +1,111 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>UICLibevdevControls</class> + <widget class="QWidget" name="UICLibevdevControls"> + <property name="windowModality"> + <enum>Qt::NonModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>228</width> + <height>69</height> + </rect> + </property> + <property name="windowTitle"> + <string>VJoy</string> + </property> + <property name="windowIcon"> + <iconset> + <normaloff>:/images/vjoy.png</normaloff>:/images/vjoy.png</iconset> + </property> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <layout class="QVBoxLayout" name="_vertical_layout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Make sure rw for /dev/input/uinput!</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <item> + <widget class="QPushButton" name="btnOK"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>100</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>100</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>OK</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btnCancel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>100</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>100</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + <tabstops> + <tabstop>btnOK</tabstop> + <tabstop>btnCancel</tabstop> + </tabstops> + <resources/> + <connections/> + <slots> + <slot>startEngineClicked()</slot> + <slot>stopEngineClicked()</slot> + <slot>cameraSettingsClicked()</slot> + </slots> +</ui> diff --git a/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp new file mode 100644 index 00000000..70fde395 --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.cpp @@ -0,0 +1,101 @@ +#include "ftnoir_protocol_libevdev.h" +#include "facetracknoir/global-settings.h" +//#include "ftnoir_tracker_base/ftnoir_tracker_types.h" +#include <cstdio> +#include <algorithm> + +#include <sys/types.h> +#include <sys/stat.h> + +#define CHECK_LIBEVDEV(expr) if ((error = (expr)) != 0) goto error; + +static const int max_input = 65535; +static const int mid_input = 32767; +static const int min_input = 0; + +FTNoIR_Protocol::FTNoIR_Protocol() : dev(NULL), uidev(NULL) +{ + 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 = min_input; + absinfo.maximum = max_input; + absinfo.resolution = 1; + absinfo.value = mid_input; + absinfo.flat = 1; + absinfo.fuzz = 0; + + 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)); + + /* do not remove next 3 lines or udev scripts won't assign 0664 permissions -sh */ + CHECK_LIBEVDEV(libevdev_enable_event_type(dev, EV_KEY)); + CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_KEY, BTN_JOYSTICK, NULL)); + CHECK_LIBEVDEV(libevdev_enable_event_code(dev, EV_KEY, BTN_TRIGGER, NULL)); + + CHECK_LIBEVDEV(libevdev_uinput_create_from_device(dev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uidev)); + + return; +error: + if (uidev) + libevdev_uinput_destroy(uidev); + if (dev) + libevdev_free(dev); + if (error) + fprintf(stderr, "libevdev error: %d\n", error); + uidev = NULL; + dev = NULL; +} + +FTNoIR_Protocol::~FTNoIR_Protocol() +{ + if (uidev) + libevdev_uinput_destroy(uidev); + if (dev) + libevdev_free(dev); +} + +void FTNoIR_Protocol::sendHeadposeToGame(const double* headpose) { + static const int axes[] = { + /* translation goes first */ + ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ + }; + + static const int max_value[] = { + 100, + 100, + 100, + 180, + 90, + 180 + }; + + for (int i = 0; i < 6; i++) + { + int value = headpose[i] * mid_input / max_value[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); + } + + (void) libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0); +} + +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..f92bb7bb --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev.h @@ -0,0 +1,69 @@ +/* Copyright (c) 2013 Stanislaw Halik <sthalik@misaki.pl> + * + * 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 <QMessageBox> +#include "facetracknoir/global-settings.h" + +extern "C" { +# include <libevdev-1.0/libevdev/libevdev.h> +# include <libevdev-1.0/libevdev/libevdev-uinput.h> +} + +class FTNoIR_Protocol : public IProtocol +{ +public: + FTNoIR_Protocol(); + virtual ~FTNoIR_Protocol(); + bool checkServerInstallationOK() { + return dev != NULL; + } + void sendHeadposeToGame(const double *headpose); + 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(); + void registerProtocol(IProtocol *) {} + void unRegisterProtocol() {} + +private: + Ui::UICLibevdevControls 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..bb54c354 --- /dev/null +++ b/ftnoir_protocol_libevdev/ftnoir_protocol_libevdev_dialog.cpp @@ -0,0 +1,26 @@ +#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())); +} + +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 <QDebug> +#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/images/linux.png b/ftnoir_protocol_libevdev/images/linux.png Binary files differnew file mode 100644 index 00000000..8836c0e2 --- /dev/null +++ b/ftnoir_protocol_libevdev/images/linux.png 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 @@ +<RCC> + <qresource prefix="/"> + <file>images/linux.png</file> + </qresource> +</RCC> |