From 016851478a90ade0c2c6dc3c0bf7f92b40acea24 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Tue, 14 Sep 2021 10:02:21 -0700 Subject: [PATCH] Add framework for virtual mouse driver This change adds the configuration and build related changes for supporting the virtual mouse. Subsequent commits will add support for reading the IO interface and translating it to mouse commands. --- daemon/Makefile.am | 9 +++++++ daemon/x52d.conf | 11 +++++++++ daemon/x52d_config.def | 10 ++++++++ daemon/x52d_config.h | 5 ++++ daemon/x52d_mouse_evdev.c | 51 +++++++++++++++++++++++++++++++++++++++ po/POTFILES.in | 1 + po/x52pro-linux.pot | 19 ++++++++++++++- po/xx_PL.po | 21 ++++++++++++++-- 8 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 daemon/x52d_mouse_evdev.c diff --git a/daemon/Makefile.am b/daemon/Makefile.am index c8ab6af..9e0e52d 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -35,6 +35,15 @@ x52d_LDADD = \ libx52.la \ @LTLIBINTL@ +if HAVE_EVDEV +x52d_SOURCES += \ + daemon/x52d_mouse_evdev.c + +x52d_CFLAGS += -DHAVE_EVDEV @EVDEV_CFLAGS@ +x52d_LDFLAGS += @EVDEV_LIBS@ +x52d_LDADD += libx52io.la +endif + x52dconfdir = @sysconfdir@/x52d x52dconf_DATA = daemon/x52d.conf diff --git a/daemon/x52d.conf b/daemon/x52d.conf index b1f44ea..ae770b8 100644 --- a/daemon/x52d.conf +++ b/daemon/x52d.conf @@ -74,6 +74,17 @@ Clutch=green MFD=128 LED=128 +###################################################################### +# Mouse - only valid on Linux +###################################################################### +[Mouse] + +# Enabled controls whether the virtual mouse is enabled or not. +Enabled=yes + +# Speed is proportional to the speed of updates to the virtual mouse +Speed=0 + ###################################################################### # Profiles - only valid on Linux ###################################################################### diff --git a/daemon/x52d_config.def b/daemon/x52d_config.def index 244e8a0..9fab8ab 100644 --- a/daemon/x52d_config.def +++ b/daemon/x52d_config.def @@ -65,6 +65,16 @@ CFG(LED, Clutch, leds[LIBX52_LED_CLUTCH], led, green) CFG(Brightness, MFD, brightness[0], int, 128) CFG(Brightness, LED, brightness[1], int, 128) +/********************************************************************** + * Mouse Settings + *********************************************************************/ +// Enabled controls whether the virtual mouse is enabled or not. +CFG(Mouse, Enabled, mouse_enabled, bool, true) + +// Speed is a value that is proportional to the speed of updates to the +// virtual mouse +CFG(Mouse, Speed, mouse_speed, int, 0) + /********************************************************************** * Profiles - only valid on Linux *********************************************************************/ diff --git a/daemon/x52d_config.h b/daemon/x52d_config.h index ac4975a..e959a99 100644 --- a/daemon/x52d_config.h +++ b/daemon/x52d_config.h @@ -37,6 +37,9 @@ struct x52d_config { int brightness[2]; + bool mouse_enabled; + int mouse_speed; + bool clutch_enabled; bool clutch_latched; @@ -66,6 +69,8 @@ void x52d_cfg_set_LED_POV(libx52_led_state param); void x52d_cfg_set_LED_Clutch(libx52_led_state param); void x52d_cfg_set_Brightness_MFD(uint16_t param); void x52d_cfg_set_Brightness_LED(uint16_t param); +void x52d_cfg_set_Mouse_Enabled(bool param); +void x52d_cfg_set_Mouse_Speed(int param); void x52d_cfg_set_Profiles_Directory(char* param); void x52d_cfg_set_Profiles_ClutchEnabled(bool param); void x52d_cfg_set_Profiles_ClutchLatched(bool param); diff --git a/daemon/x52d_mouse_evdev.c b/daemon/x52d_mouse_evdev.c new file mode 100644 index 0000000..efad03d --- /dev/null +++ b/daemon/x52d_mouse_evdev.c @@ -0,0 +1,51 @@ +/* + * Saitek X52 Pro MFD & LED driver - Mouse driver + * + * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0 + */ + +#include "config.h" +#include +#include + +#include "pinelog.h" +#include "x52d_config.h" +#include "x52d_const.h" + +// Mouse speed is the delay between subsequent mouse reports +#define DEFAULT_MOUSE_SPEED 250000 + +static bool mouse_enabled = false; +static int mouse_speed = DEFAULT_MOUSE_SPEED; + +#define MAX_MOUSE_SPEED 5 +static const int mouse_speed_map[MAX_MOUSE_SPEED] = { + 250000, + 200000, + 150000, + 100000, + 50000, +}; + +void x52d_cfg_set_Mouse_Enabled(bool enabled) +{ + PINELOG_DEBUG(_("Setting mouse enable to %s"), + enabled ? _("on") : _("off")); + mouse_enabled = enabled; +} + +void x52d_cfg_set_Mouse_Speed(int speed) +{ + int new_speed; + if (speed >= 0 && speed < MAX_MOUSE_SPEED) { + new_speed = mouse_speed_map[speed]; + PINELOG_DEBUG(_("Setting mouse speed to %d (delay %d ms)"), + speed, new_speed); + mouse_speed = new_speed; + } else { + PINELOG_INFO(_("Ignoring mouse speed %d outside supported range (0-%d)"), + speed, MAX_MOUSE_SPEED); + } +} diff --git a/po/POTFILES.in b/po/POTFILES.in index 4a869a0..4cc9b25 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -17,3 +17,4 @@ daemon/x52d_clock.c daemon/x52d_config.c daemon/x52d_config_parser.c daemon/x52d_device.c +daemon/x52d_mouse_evdev.c diff --git a/po/x52pro-linux.pot b/po/x52pro-linux.pot index 1517827..85322d8 100644 --- a/po/x52pro-linux.pot +++ b/po/x52pro-linux.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: x52pro-linux 0.2.2\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n" -"POT-Creation-Date: 2021-09-14 01:00-0700\n" +"POT-Creation-Date: 2021-09-14 09:52-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -143,10 +143,12 @@ msgid "Unknown LED state %d" msgstr "" #: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 +#: daemon/x52d_mouse_evdev.c:35 msgid "off" msgstr "" #: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 +#: daemon/x52d_mouse_evdev.c:35 msgid "on" msgstr "" @@ -714,3 +716,18 @@ msgstr "" #, c-format msgid "Error %d when updating X52 device: %s" msgstr "" + +#: daemon/x52d_mouse_evdev.c:34 +#, c-format +msgid "Setting mouse enable to %s" +msgstr "" + +#: daemon/x52d_mouse_evdev.c:44 +#, c-format +msgid "Setting mouse speed to %d (delay %d ms)" +msgstr "" + +#: daemon/x52d_mouse_evdev.c:48 +#, c-format +msgid "Ignoring mouse speed %d outside supported range (0-%d)" +msgstr "" diff --git a/po/xx_PL.po b/po/xx_PL.po index 982730b..922efd6 100644 --- a/po/xx_PL.po +++ b/po/xx_PL.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: x52pro-linux 0.2.1\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n" -"POT-Creation-Date: 2021-09-14 01:00-0700\n" -"PO-Revision-Date: 2021-08-30 10:41-0700\n" +"POT-Creation-Date: 2021-09-14 09:52-0700\n" +"PO-Revision-Date: 2021-09-14 09:54-0700\n" "Last-Translator: Nirenjan Krishnan \n" "Language-Team: Dummy Language for testing i18n\n" "Language: xx_PL\n" @@ -143,10 +143,12 @@ msgid "Unknown LED state %d" msgstr "Unknownay EDLay atestay %d" #: libx52/x52_stringify.c:47 daemon/x52d_clock.c:28 +#: daemon/x52d_mouse_evdev.c:35 msgid "off" msgstr "offay" #: libx52/x52_stringify.c:48 daemon/x52d_clock.c:28 +#: daemon/x52d_mouse_evdev.c:35 msgid "on" msgstr "onay" @@ -763,3 +765,18 @@ msgstr "Erroray %d enwhay updatingay X52 arameterpay: %s" #, c-format msgid "Error %d when updating X52 device: %s" msgstr "Erroray %d enwhay updatingay X52 eviceday: %s" + +#: daemon/x52d_mouse_evdev.c:34 +#, c-format +msgid "Setting mouse enable to %s" +msgstr "Ettingsay ousemay enableay otay %s" + +#: daemon/x52d_mouse_evdev.c:44 +#, c-format +msgid "Setting mouse speed to %d (delay %d ms)" +msgstr "Ettingsay ousemay eedspay otay %d (elayday %d ms)" + +#: daemon/x52d_mouse_evdev.c:48 +#, c-format +msgid "Ignoring mouse speed %d outside supported range (0-%d)" +msgstr "Ignoringay ousemay eedspay %d outsideay upportedsay angeray (0-%d)"