mirror of https://github.com/nirenjan/libx52.git
Merge device acquisition and update threads
parent
c56f715155
commit
8deb6a1513
|
@ -9,6 +9,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "x52d_const.h"
|
#include "x52d_const.h"
|
||||||
#include "x52d_config.h"
|
#include "x52d_config.h"
|
||||||
|
@ -20,28 +21,18 @@ static libx52_device *x52_dev;
|
||||||
|
|
||||||
static pthread_mutex_t device_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t device_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
/*
|
static pthread_t device_thr;
|
||||||
* Device acquisition thread
|
static volatile bool device_update_needed;
|
||||||
* This is a thread that scans for and opens a supported X52 joystick.
|
|
||||||
*/
|
|
||||||
static pthread_t device_acq_thr;
|
|
||||||
static volatile bool device_acq_thr_enable;
|
|
||||||
static volatile bool device_upd_thr_enable;
|
|
||||||
|
|
||||||
static void *x52_dev_acq(void *param)
|
static void *x52_dev_thr(void *param)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
PINELOG_INFO(_("Starting X52 device acquisition thread"));
|
#define DEV_ACQ_DELAY 5 // seconds
|
||||||
// Check if the device is connected in a loop
|
#define DEV_UPD_DELAY 50000 // microseconds
|
||||||
for (;;) {
|
|
||||||
#define RECONNECT_DELAY 5
|
|
||||||
if (!device_acq_thr_enable) {
|
|
||||||
PINELOG_TRACE("Device acquisition thread disabled. Checking again in %d seconds", RECONNECT_DELAY);
|
|
||||||
sleep(RECONNECT_DELAY);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
PINELOG_INFO(_("Starting X52 device manager thread"));
|
||||||
|
for (;;) {
|
||||||
if (!libx52_is_connected(x52_dev)) {
|
if (!libx52_is_connected(x52_dev)) {
|
||||||
PINELOG_TRACE("Attempting to connect to X52 device");
|
PINELOG_TRACE("Attempting to connect to X52 device");
|
||||||
rc = libx52_connect(x52_dev);
|
rc = libx52_connect(x52_dev);
|
||||||
|
@ -52,61 +43,26 @@ static void *x52_dev_acq(void *param)
|
||||||
} else {
|
} else {
|
||||||
PINELOG_TRACE("No compatible X52 device found");
|
PINELOG_TRACE("No compatible X52 device found");
|
||||||
}
|
}
|
||||||
PINELOG_TRACE("Sleeping for %d seconds before trying to acquire device again", RECONNECT_DELAY);
|
PINELOG_TRACE("Sleeping for %d seconds before trying to acquire device again", DEV_ACQ_DELAY);
|
||||||
sleep(RECONNECT_DELAY);
|
sleep(DEV_ACQ_DELAY);
|
||||||
} else {
|
} else {
|
||||||
|
/* Successfully connected */
|
||||||
PINELOG_INFO(_("Device connected, writing configuration"));
|
PINELOG_INFO(_("Device connected, writing configuration"));
|
||||||
x52d_config_apply();
|
x52d_config_apply();
|
||||||
|
|
||||||
PINELOG_TRACE("Found device, disabling acquisition thread, enable update thread");
|
|
||||||
device_acq_thr_enable = false;
|
|
||||||
device_upd_thr_enable = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PINELOG_TRACE("Device is connected, disable acquisition thread, enable update thread");
|
if (!device_update_needed) {
|
||||||
device_acq_thr_enable = false;
|
usleep(DEV_UPD_DELAY);
|
||||||
device_upd_thr_enable = true;
|
continue;
|
||||||
}
|
|
||||||
#undef RECONNECT_DELAY
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Device update thread
|
|
||||||
* This is a thread that updates the joystick.
|
|
||||||
*/
|
|
||||||
static pthread_t device_upd_thr;
|
|
||||||
static volatile bool device_update_needed;
|
|
||||||
|
|
||||||
static void *x52_dev_upd(void *param)
|
|
||||||
{
|
|
||||||
PINELOG_INFO(_("Starting X52 device update thread"));
|
|
||||||
// Check if the device needs to be updated in a loop
|
|
||||||
for (;;) {
|
|
||||||
#define UPDATE_CHECK_DELAY 50000 // Wait for this many useconds
|
|
||||||
if (!device_update_needed || !device_upd_thr_enable) {
|
|
||||||
usleep(UPDATE_CHECK_DELAY);
|
|
||||||
/* Check if the device is still connected */
|
|
||||||
if (device_upd_thr_enable && !libx52_is_connected(x52_dev)) {
|
|
||||||
// Detach and spawn thread to reconnect
|
|
||||||
PINELOG_TRACE("Disconnecting detached device");
|
|
||||||
libx52_disconnect(x52_dev);
|
|
||||||
|
|
||||||
PINELOG_TRACE("Disabling device update thread");
|
|
||||||
device_upd_thr_enable = false;
|
|
||||||
|
|
||||||
PINELOG_TRACE("Signaling device search thread");
|
|
||||||
device_acq_thr_enable = true;
|
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)x52d_dev_update();
|
(void)x52d_dev_update();
|
||||||
#undef UPDATE_CHECK_DELAY
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef DEV_ACQ_DELAY
|
||||||
|
#undef DEV_UPD_DELAY
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,26 +77,15 @@ void x52d_dev_init(void)
|
||||||
rc, libx52_strerror(rc));
|
rc, libx52_strerror(rc));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and initialize the threads
|
// Create and initialize the thread
|
||||||
pthread_create(&device_acq_thr, NULL, x52_dev_acq, NULL);
|
pthread_create(&device_thr, NULL, x52_dev_thr, NULL);
|
||||||
// With libx52.so.2.3.0, libx52_init will also attempt to connect to a
|
|
||||||
// supported joystick. Check if a device is already connected before
|
|
||||||
// enabling the device acquisition thread.
|
|
||||||
device_acq_thr_enable = !libx52_is_connected(x52_dev);
|
|
||||||
|
|
||||||
pthread_create(&device_upd_thr, NULL, x52_dev_upd, NULL);
|
|
||||||
device_update_needed = false;
|
|
||||||
device_upd_thr_enable = libx52_is_connected(x52_dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void x52d_dev_exit(void)
|
void x52d_dev_exit(void)
|
||||||
{
|
{
|
||||||
// Shutdown any threads
|
// Shutdown any threads
|
||||||
PINELOG_INFO(_("Shutting down X52 device acquisition thread"));
|
PINELOG_INFO(_("Shutting down X52 device manager thread"));
|
||||||
pthread_cancel(device_acq_thr);
|
pthread_cancel(device_thr);
|
||||||
|
|
||||||
PINELOG_INFO(_("Shutting down X52 device update thread"));
|
|
||||||
pthread_cancel(device_upd_thr);
|
|
||||||
|
|
||||||
libx52_exit(x52_dev);
|
libx52_exit(x52_dev);
|
||||||
}
|
}
|
||||||
|
@ -222,15 +167,10 @@ int x52d_dev_update(void)
|
||||||
|
|
||||||
if (rc != LIBX52_SUCCESS) {
|
if (rc != LIBX52_SUCCESS) {
|
||||||
if (rc == LIBX52_ERROR_NO_DEVICE) {
|
if (rc == LIBX52_ERROR_NO_DEVICE) {
|
||||||
// Detach and spawn thread to reconnect
|
// Detach from the existing device, the next thread run will
|
||||||
|
// pick it up.
|
||||||
PINELOG_TRACE("Disconnecting detached device");
|
PINELOG_TRACE("Disconnecting detached device");
|
||||||
libx52_disconnect(x52_dev);
|
libx52_disconnect(x52_dev);
|
||||||
|
|
||||||
PINELOG_TRACE("Disabling device update thread");
|
|
||||||
device_upd_thr_enable = false;
|
|
||||||
|
|
||||||
PINELOG_TRACE("Signaling device search thread");
|
|
||||||
device_acq_thr_enable = true;
|
|
||||||
} else {
|
} else {
|
||||||
PINELOG_ERROR(_("Error %d when updating X52 device: %s"),
|
PINELOG_ERROR(_("Error %d when updating X52 device: %s"),
|
||||||
rc, libx52_strerror(rc));
|
rc, libx52_strerror(rc));
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: x52pro-linux 0.2.2\n"
|
"Project-Id-Version: x52pro-linux 0.2.2\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-09-15 00:04-0700\n"
|
"POT-Creation-Date: 2021-09-15 00:09-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"
|
||||||
|
@ -671,46 +671,38 @@ msgstr ""
|
||||||
msgid "Error processing override '%s.%s=%s'"
|
msgid "Error processing override '%s.%s=%s'"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:35
|
#: daemon/x52d_device.c:34
|
||||||
msgid "Starting X52 device acquisition thread"
|
msgid "Starting X52 device manager thread"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:50
|
#: daemon/x52d_device.c:41
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d connecting to device: %s"
|
msgid "Error %d connecting to device: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:58
|
#: daemon/x52d_device.c:50
|
||||||
msgid "Device connected, writing configuration"
|
msgid "Device connected, writing configuration"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:85
|
#: daemon/x52d_device.c:72
|
||||||
msgid "Starting X52 device update thread"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: daemon/x52d_device.c:116
|
|
||||||
msgid "Initializing libx52"
|
msgid "Initializing libx52"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:120
|
#: daemon/x52d_device.c:76
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Failure %d initializing libx52: %s"
|
msgid "Failure %d initializing libx52: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:139
|
#: daemon/x52d_device.c:87
|
||||||
msgid "Shutting down X52 device acquisition thread"
|
msgid "Shutting down X52 device manager thread"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:142
|
#: daemon/x52d_device.c:100
|
||||||
msgid "Shutting down X52 device update thread"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: daemon/x52d_device.c:155
|
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d when updating X52 parameter: %s"
|
msgid "Error %d when updating X52 parameter: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52d_device.c:235
|
#: daemon/x52d_device.c:175
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d when updating X52 device: %s"
|
msgid "Error %d when updating X52 device: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
40
po/xx_PL.po
40
po/xx_PL.po
|
@ -7,8 +7,8 @@ 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-09-15 00:04-0700\n"
|
"POT-Creation-Date: 2021-09-15 00:09-0700\n"
|
||||||
"PO-Revision-Date: 2021-09-14 17:07-0700\n"
|
"PO-Revision-Date: 2021-09-15 00:12-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"
|
||||||
"Language: xx_PL\n"
|
"Language: xx_PL\n"
|
||||||
|
@ -720,46 +720,38 @@ msgstr "Onay aluevay oundfay inay overrideay ingstray '%s'"
|
||||||
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:35
|
#: daemon/x52d_device.c:34
|
||||||
msgid "Starting X52 device acquisition thread"
|
msgid "Starting X52 device manager thread"
|
||||||
msgstr "Artingstay X52 eviceday acquisitionay eadthray"
|
msgstr "Artingstay X52 eviceday anagermay eadthray"
|
||||||
|
|
||||||
#: daemon/x52d_device.c:50
|
#: daemon/x52d_device.c:41
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d connecting to device: %s"
|
msgid "Error %d connecting to device: %s"
|
||||||
msgstr "Erroray %d onnectingcay otay eviceday: %s"
|
msgstr "Erroray %d onnectingcay otay eviceday: %s"
|
||||||
|
|
||||||
#: daemon/x52d_device.c:58
|
#: daemon/x52d_device.c:50
|
||||||
msgid "Device connected, writing configuration"
|
msgid "Device connected, writing configuration"
|
||||||
msgstr "Eviceday onnectedcay, itingwray onfigurationcay"
|
msgstr "Eviceday onnectedcay, itingwray onfigurationcay"
|
||||||
|
|
||||||
#: daemon/x52d_device.c:85
|
#: daemon/x52d_device.c:72
|
||||||
msgid "Starting X52 device update thread"
|
|
||||||
msgstr "Artingstay X52 eviceday updateay eadthray"
|
|
||||||
|
|
||||||
#: daemon/x52d_device.c:116
|
|
||||||
msgid "Initializing libx52"
|
msgid "Initializing libx52"
|
||||||
msgstr "Initializingay libx52"
|
msgstr "Initializingay libx52"
|
||||||
|
|
||||||
#: daemon/x52d_device.c:120
|
#: daemon/x52d_device.c:76
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Failure %d initializing libx52: %s"
|
msgid "Failure %d initializing libx52: %s"
|
||||||
msgstr "Ailurefay %d initializeay libx52: %s"
|
msgstr "Ailurefay %d initializeay libx52: %s"
|
||||||
|
|
||||||
#: daemon/x52d_device.c:139
|
#: daemon/x52d_device.c:87
|
||||||
msgid "Shutting down X52 device acquisition thread"
|
msgid "Shutting down X52 device manager thread"
|
||||||
msgstr "Uttingshay ownday X52 eviceday acquisitionay eadthray"
|
msgstr "Uttingshay ownday X52 eviceday anagermay eadthray"
|
||||||
|
|
||||||
#: daemon/x52d_device.c:142
|
#: daemon/x52d_device.c:100
|
||||||
msgid "Shutting down X52 device update thread"
|
|
||||||
msgstr "Uttingshay ownday X52 eviceday updateay eadthray"
|
|
||||||
|
|
||||||
#: daemon/x52d_device.c:155
|
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d when updating X52 parameter: %s"
|
msgid "Error %d when updating X52 parameter: %s"
|
||||||
msgstr "Erroray %d enwhay updatingay X52 arameterpay: %s"
|
msgstr "Erroray %d enwhay updatingay X52 arameterpay: %s"
|
||||||
|
|
||||||
#: daemon/x52d_device.c:235
|
#: daemon/x52d_device.c:175
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d when updating X52 device: %s"
|
msgid "Error %d when updating X52 device: %s"
|
||||||
msgstr "Erroray %d enwhay updatingay X52 eviceday: %s"
|
msgstr "Erroray %d enwhay updatingay X52 eviceday: %s"
|
||||||
|
@ -847,7 +839,3 @@ msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay"
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Error %d creating X52 virtual mouse: %s"
|
msgid "Error %d creating X52 virtual mouse: %s"
|
||||||
msgstr "Erroray %d eatingcray X52 irtualvay ousemay: %s"
|
msgstr "Erroray %d eatingcray X52 irtualvay ousemay: %s"
|
||||||
|
|
||||||
#, fuzzy
|
|
||||||
#~ msgid "Starting X52 mouse manager thread"
|
|
||||||
#~ msgstr "Artingstay X52 ockclay anagermay eadthray"
|
|
||||||
|
|
Loading…
Reference in New Issue