From 9f06603e2d752f574b145bc3c4b5e453d7d306d0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 13 Jan 2018 07:46:21 +0100 Subject: proto/libevdev: buffer flush, WIP --- proto-libevdev/ftnoir_protocol_libevdev.cpp | 26 +++++++++++++++++++++++--- proto-libevdev/ftnoir_protocol_libevdev.h | 16 +++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'proto-libevdev') diff --git a/proto-libevdev/ftnoir_protocol_libevdev.cpp b/proto-libevdev/ftnoir_protocol_libevdev.cpp index 8b8e294e..40ce1b80 100644 --- a/proto-libevdev/ftnoir_protocol_libevdev.cpp +++ b/proto-libevdev/ftnoir_protocol_libevdev.cpp @@ -1,10 +1,18 @@ #include "ftnoir_protocol_libevdev.h" #include "api/plugin-api.hpp" -#include -#include +#include +#include #include #include +#include + +#include +#include + +#include "compat/util.hpp" + +#include #define CHECK_LIBEVDEV(expr) if ((error = (expr)) != 0) goto error; @@ -87,11 +95,23 @@ void evdev::pose(const double* headpose) { 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); + int normalized = clamp(value, min_input, max_input); (void) libevdev_uinput_write_event(uidev, EV_ABS, axes[i], normalized); } (void) libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0); } +module_status evdev::initialize() +{ + if (access("/dev/uinput", R_OK | W_OK)) + { + char buf[128] {}; + (void) strerror_r(errno, buf, sizeof(buf)); + return error(tr("Can't open /dev/uinput: %1").arg(buf)); + } + + return status_ok(); +} + OPENTRACK_DECLARE_PROTOCOL(evdev, LibevdevControls, evdevDll) diff --git a/proto-libevdev/ftnoir_protocol_libevdev.h b/proto-libevdev/ftnoir_protocol_libevdev.h index 5606cbdf..7cf59053 100644 --- a/proto-libevdev/ftnoir_protocol_libevdev.h +++ b/proto-libevdev/ftnoir_protocol_libevdev.h @@ -7,13 +7,12 @@ #pragma once #include "ui_ftnoir_libevdev_controls.h" -#include +#include "compat/macros.hpp" #include "api/plugin-api.hpp" +#include +#include -extern "C" { -# include -# include -} +#include class evdev : public IProtocol { @@ -25,8 +24,11 @@ public: } void pose(const double *headpose); QString game_name() { - return otr_tr("Virtual joystick for Linux"); + return _("Virtual joystick for Linux"); } + + module_status initialize() override; + private: struct libevdev* dev; struct libevdev_uinput* uidev; @@ -52,6 +54,6 @@ private slots: class evdevDll : public Metadata { public: - QString name() { return QString("libevdev joystick receiver"); } + QString name() { return _("libevdev joystick receiver"); } QIcon icon() { return QIcon(":/images/linux.png"); } }; -- cgit v1.2.3