mirror of https://github.com/nirenjan/libx52.git
Add device manager implementation
parent
5a283672c4
commit
ab946b4a1a
|
@ -13,6 +13,7 @@ util/x52charmapgen*
|
||||||
lib/libusbx52/x52test*
|
lib/libusbx52/x52test*
|
||||||
udev/*.rules
|
udev/*.rules
|
||||||
daemon/x52d*
|
daemon/x52d*
|
||||||
|
!daemon/x52d_*.*
|
||||||
x52pro-linux-*.tar.gz
|
x52pro-linux-*.tar.gz
|
||||||
|
|
||||||
# Module files
|
# Module files
|
||||||
|
|
|
@ -10,7 +10,8 @@ bin_PROGRAMS = x52d
|
||||||
|
|
||||||
# Service daemon that manages the X52 device
|
# Service daemon that manages the X52 device
|
||||||
x52d_SOURCES = \
|
x52d_SOURCES = \
|
||||||
x52d_main.c x52d_config_parser.c x52d_config.c
|
x52d_main.c x52d_config_parser.c x52d_config.c \
|
||||||
|
x52d_device.c
|
||||||
|
|
||||||
x52d_CFLAGS = \
|
x52d_CFLAGS = \
|
||||||
-I $(top_srcdir) \
|
-I $(top_srcdir) \
|
||||||
|
@ -22,13 +23,17 @@ x52d_CFLAGS = \
|
||||||
-DLOCALEDIR=\"$(localedir)\" \
|
-DLOCALEDIR=\"$(localedir)\" \
|
||||||
-DLOGDIR=\"$(localstatedir)/log\" \
|
-DLOGDIR=\"$(localstatedir)/log\" \
|
||||||
-DRUNDIR=\"$(runstatedir)\" \
|
-DRUNDIR=\"$(runstatedir)\" \
|
||||||
@INIH_CFLAGS@ $(WARN_CFLAGS)
|
@INIH_CFLAGS@ @X52_INCLUDE@ $(WARN_CFLAGS)
|
||||||
|
|
||||||
x52d_LDFLAGS = @INIH_LIBS@ $(WARN_LDFLAGS)
|
x52d_LDFLAGS = @INIH_LIBS@ $(WARN_LDFLAGS)
|
||||||
x52d_LDADD = ../lib/pinelog/libpinelog.la @LTLIBINTL@
|
x52d_LDADD = \
|
||||||
|
../lib/pinelog/libpinelog.la \
|
||||||
|
../lib/libx52/libx52.la \
|
||||||
|
@LTLIBINTL@
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
x52d_config.def \
|
x52d_config.def \
|
||||||
x52d_config.h \
|
x52d_config.h \
|
||||||
x52d_const.h \
|
x52d_const.h \
|
||||||
|
x52d_device.h \
|
||||||
x52d.conf
|
x52d.conf
|
||||||
|
|
|
@ -0,0 +1,151 @@
|
||||||
|
/*
|
||||||
|
* Saitek X52 Pro MFD & LED driver - Device manager
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "x52d_const.h"
|
||||||
|
#include "x52d_device.h"
|
||||||
|
#include "libx52.h"
|
||||||
|
#include "pinelog.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions
|
||||||
|
*
|
||||||
|
* Thread method to scan and reconnect to the joystick if it has been
|
||||||
|
* disconnected/never connected.
|
||||||
|
*
|
||||||
|
* API wrappers to libx52 functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
static libx52_device *x52_dev;
|
||||||
|
|
||||||
|
static pthread_mutex_t device_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static void *x52_dev_thread(void *param)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
// Check if the device is connected in a loop
|
||||||
|
for (;;) {
|
||||||
|
#define RECONNECT_DELAY 5
|
||||||
|
sleep(RECONNECT_DELAY);
|
||||||
|
if (!libx52_is_connected(x52_dev)) {
|
||||||
|
PINELOG_TRACE("Attempting to connect to X52 device");
|
||||||
|
rc = libx52_connect(x52_dev);
|
||||||
|
if (rc != LIBX52_SUCCESS) {
|
||||||
|
if (rc != LIBX52_ERROR_NO_DEVICE) {
|
||||||
|
PINELOG_ERROR(_("Error %d connecting to device: %s"),
|
||||||
|
rc, libx52_strerror(rc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void x52d_dev_init(void)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
PINELOG_TRACE("Initializing libx52");
|
||||||
|
rc = libx52_init(&x52_dev);
|
||||||
|
|
||||||
|
if (rc != LIBX52_SUCCESS) {
|
||||||
|
PINELOG_FATAL(_("Failure %d initializing libx52: %s"),
|
||||||
|
rc, libx52_strerror(rc));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Create and initialize the threads
|
||||||
|
}
|
||||||
|
|
||||||
|
void x52d_dev_exit(void)
|
||||||
|
{
|
||||||
|
// TODO: Shutdown any threads
|
||||||
|
|
||||||
|
libx52_exit(x52_dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define WRAP_LIBX52(func) \
|
||||||
|
int rc; \
|
||||||
|
pthread_mutex_lock(&device_mutex); \
|
||||||
|
rc = func; \
|
||||||
|
pthread_mutex_unlock(&device_mutex); \
|
||||||
|
if (rc != LIBX52_SUCCESS) { \
|
||||||
|
PINELOG_ERROR(_("Error %d when updating X52 parameter: %s"), \
|
||||||
|
rc, libx52_strerror(rc)); \
|
||||||
|
} \
|
||||||
|
return rc
|
||||||
|
|
||||||
|
int x52d_dev_set_text(uint8_t line, const char *text, uint8_t length)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_text(x52_dev, line, text, length));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_led_state(libx52_led_id led, libx52_led_state state)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_led_state(x52_dev, led, state));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_clock(time_t time, int local)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_clock(x52_dev, time, local));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_clock_timezone(libx52_clock_id clock, int offset)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_clock_timezone(x52_dev, clock, offset));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_clock_format(libx52_clock_id clock, libx52_clock_format format)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_clock_format(x52_dev, clock, format));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_time(uint8_t hour, uint8_t minute)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_time(x52_dev, hour, minute));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_date(uint8_t dd, uint8_t mm, uint8_t yy)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_date(x52_dev, dd, mm, yy));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_date_format(libx52_date_format format)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_date_format(x52_dev, format));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_brightness(uint8_t mfd, uint16_t brightness)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_brightness(x52_dev, mfd, brightness));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_shift(uint8_t state)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_shift(x52_dev, state));
|
||||||
|
}
|
||||||
|
int x52d_dev_set_blink(uint8_t state)
|
||||||
|
{
|
||||||
|
WRAP_LIBX52(libx52_set_blink(x52_dev, state));
|
||||||
|
}
|
||||||
|
int x52d_dev_update(void)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&device_mutex);
|
||||||
|
rc = libx52_update(x52_dev);
|
||||||
|
pthread_mutex_unlock(&device_mutex);
|
||||||
|
|
||||||
|
if (rc != LIBX52_SUCCESS) {
|
||||||
|
if (rc == LIBX52_ERROR_NO_DEVICE) {
|
||||||
|
// TODO: Detach and spawn thread to reconnect
|
||||||
|
libx52_disconnect(x52_dev);
|
||||||
|
} else {
|
||||||
|
PINELOG_ERROR(_("Error %d when updating X52 device: %s"),
|
||||||
|
rc, libx52_strerror(rc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Saitek X52 Pro MFD & LED driver - Device manager header
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef X52D_DEVICE_H
|
||||||
|
#define X52D_DEVICE_H
|
||||||
|
|
||||||
|
#include "libx52.h"
|
||||||
|
|
||||||
|
void x52d_dev_init(void);
|
||||||
|
void x52d_dev_exit(void);
|
||||||
|
|
||||||
|
void x52d_dev_start_thread(void);
|
||||||
|
|
||||||
|
/* Wrapper methods for libx52 calls */
|
||||||
|
int x52d_dev_set_text(uint8_t line, const char *text, uint8_t length);
|
||||||
|
int x52d_dev_set_led_state(libx52_led_id led, libx52_led_state state);
|
||||||
|
int x52d_dev_set_clock(time_t time, int local);
|
||||||
|
int x52d_dev_set_clock_timezone(libx52_clock_id clock, int offset);
|
||||||
|
int x52d_dev_set_clock_format(libx52_clock_id clock, libx52_clock_format format);
|
||||||
|
int x52d_dev_set_time(uint8_t hour, uint8_t minute);
|
||||||
|
int x52d_dev_set_date(uint8_t dd, uint8_t mm, uint8_t yy);
|
||||||
|
int x52d_dev_set_date_format(libx52_date_format format);
|
||||||
|
int x52d_dev_set_brightness(uint8_t mfd, uint16_t brightness);
|
||||||
|
int x52d_dev_set_shift(uint8_t state);
|
||||||
|
int x52d_dev_set_blink(uint8_t state);
|
||||||
|
int x52d_dev_update(void);
|
||||||
|
|
||||||
|
#endif // !defined X52D_DEVICE_H
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Saitek X52 Pro MFD & LED driver - Service daemon
|
* Saitek X52 Pro MFD & LED driver - Service daemon
|
||||||
* * Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
*
|
||||||
|
* Copyright (C) 2021 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -14,3 +14,4 @@ utils/test/x52_test_mfd.c
|
||||||
daemon/x52d_main.c
|
daemon/x52d_main.c
|
||||||
daemon/x52d_config.c
|
daemon/x52d_config.c
|
||||||
daemon/x52d_config_parser.c
|
daemon/x52d_config_parser.c
|
||||||
|
daemon/x52d_device.c
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
||||||
"POT-Creation-Date: 2021-07-15 15:08-0700\n"
|
"POT-Creation-Date: 2021-07-16 00:26-0700\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -370,17 +370,17 @@ msgstr ""
|
||||||
msgid "OK"
|
msgid "OK"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_main.c:32
|
#: daemon/x52d_main.c:33
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d setting log file: %s\n"
|
msgid "Error %d setting log file: %s\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_main.c:40
|
#: daemon/x52d_main.c:44
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Usage: %s [-f] [-v] [-q] [-l log-file] [-o override] [-c config-file]\n"
|
msgid "Usage: %s [-f] [-v] [-q] [-l log-file] [-o override] [-c config-file]\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_main.c:101
|
#: daemon/x52d_main.c:105
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Unable to parse configuration override '%s'\n"
|
msgid "Unable to parse configuration override '%s'\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -427,3 +427,23 @@ msgstr ""
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error processing override '%s.%s=%s'"
|
msgid "Error processing override '%s.%s=%s'"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:45
|
||||||
|
#, c-format
|
||||||
|
msgid "Error %d connecting to device: %s"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:63
|
||||||
|
#, c-format
|
||||||
|
msgid "Failure %d initializing libx52: %s"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:83
|
||||||
|
#, c-format
|
||||||
|
msgid "Error %d when updating X52 parameter: %s"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:145
|
||||||
|
#, c-format
|
||||||
|
msgid "Error %d when updating X52 device: %s"
|
||||||
|
msgstr ""
|
||||||
|
|
28
po/xx_PL.po
28
po/xx_PL.po
|
@ -7,7 +7,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
||||||
"POT-Creation-Date: 2021-07-15 15:08-0700\n"
|
"POT-Creation-Date: 2021-07-16 00:26-0700\n"
|
||||||
"PO-Revision-Date: 2021-07-15 15:09-0700\n"
|
"PO-Revision-Date: 2021-07-15 15:09-0700\n"
|
||||||
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
||||||
"Language-Team: Dummy Language for testing i18n\n"
|
"Language-Team: Dummy Language for testing i18n\n"
|
||||||
|
@ -413,19 +413,19 @@ msgstr "Estingtay aracterchay 0x%02x..."
|
||||||
msgid "OK"
|
msgid "OK"
|
||||||
msgstr "OKay"
|
msgstr "OKay"
|
||||||
|
|
||||||
#: daemon/x52d_main.c:32
|
#: daemon/x52d_main.c:33
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d setting log file: %s\n"
|
msgid "Error %d setting log file: %s\n"
|
||||||
msgstr "Erroray %d ettingsay oglay ilefay: %s\n"
|
msgstr "Erroray %d ettingsay oglay ilefay: %s\n"
|
||||||
|
|
||||||
#: daemon/x52d_main.c:40
|
#: daemon/x52d_main.c:44
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Usage: %s [-f] [-v] [-q] [-l log-file] [-o override] [-c config-file]\n"
|
msgid "Usage: %s [-f] [-v] [-q] [-l log-file] [-o override] [-c config-file]\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Usageay: %s [-f] [-v] [-q] [-l oglay-ilefay] [-o overrideay] [-c onfigcay-"
|
"Usageay: %s [-f] [-v] [-q] [-l oglay-ilefay] [-o overrideay] [-c onfigcay-"
|
||||||
"ilefay]\n"
|
"ilefay]\n"
|
||||||
|
|
||||||
#: daemon/x52d_main.c:101
|
#: daemon/x52d_main.c:105
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Unable to parse configuration override '%s'\n"
|
msgid "Unable to parse configuration override '%s'\n"
|
||||||
msgstr "Unableay otay arsepay onfigurationcay overrideay '%s'\n"
|
msgstr "Unableay otay arsepay onfigurationcay overrideay '%s'\n"
|
||||||
|
@ -472,3 +472,23 @@ msgstr "Onay aluevay oundfay inay overrideay ingstray '%s'"
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error processing override '%s.%s=%s'"
|
msgid "Error processing override '%s.%s=%s'"
|
||||||
msgstr "Erroray ocessingpray overriday '%s.%s=%s'"
|
msgstr "Erroray ocessingpray overriday '%s.%s=%s'"
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:45
|
||||||
|
#, c-format
|
||||||
|
msgid "Error %d connecting to device: %s"
|
||||||
|
msgstr "Erroray %d onnectingcay otay eviceday: %s"
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:63
|
||||||
|
#, c-format
|
||||||
|
msgid "Failure %d initializing libx52: %s"
|
||||||
|
msgstr "Ailurefay %d initializeay libx52: %s"
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:83
|
||||||
|
#, c-format
|
||||||
|
msgid "Error %d when updating X52 parameter: %s"
|
||||||
|
msgstr "Erroray %d enwhay updatingay X52 arameterpay: %s"
|
||||||
|
|
||||||
|
#: daemon/x52d_device.c:145
|
||||||
|
#, c-format
|
||||||
|
msgid "Error %d when updating X52 device: %s"
|
||||||
|
msgstr "Erroray %d enwhay updatingay X52 eviceday: %s"
|
||||||
|
|
Loading…
Reference in New Issue