mirror of https://github.com/nirenjan/libx52.git
Add routine to check device connectivity
Prior to this change, if the clock thread is disabled, then disconnecting and reconnecting the X52 device would cause the daemon to not detect the transition. As a result, the daemon would stay in a state where it thinks the device is still connected, and therefore, not actually apply any of the saved configuration, until it received a SIGHUP to refresh the configuration. This change adds a routine that sends a dummy vendor command. This vendor command does nothing on my X52 Pro (VID 06a3, PID 0762), but serves as a check to see if the daemon can send vendor commands to the device. If the device is indeed disconnected, then that is a sufficient indicator to disable the update thread and re-enable the acquisition thread.reverse-scroll
parent
0f83cd5a95
commit
f34f84a3ee
|
@ -89,6 +89,8 @@ static void *x52_dev_upd(void *param)
|
|||
#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 */
|
||||
x52d_dev_check();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -230,3 +232,34 @@ int x52d_dev_update(void)
|
|||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void x52d_dev_check(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!libx52_is_connected(x52_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&device_mutex);
|
||||
/* Use a dummy vendor command to check if the device is connected */
|
||||
rc = libx52_vendor_command(x52_dev, 0, 0);
|
||||
pthread_mutex_unlock(&device_mutex);
|
||||
|
||||
if (rc != LIBX52_SUCCESS) {
|
||||
if (rc == LIBX52_ERROR_NO_DEVICE) {
|
||||
// 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;
|
||||
} else {
|
||||
PINELOG_ERROR(_("Error %d when updating X52 device: %s"),
|
||||
rc, libx52_strerror(rc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,5 +27,6 @@ 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);
|
||||
void x52d_dev_check(void);
|
||||
|
||||
#endif // !defined X52D_DEVICE_H
|
||||
|
|
|
@ -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-08-30 11:59-0700\n"
|
||||
"POT-Creation-Date: 2021-08-30 12:33-0700\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -688,29 +688,29 @@ msgstr ""
|
|||
msgid "Starting X52 device update thread"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_device.c:105
|
||||
#: daemon/x52d_device.c:107
|
||||
msgid "Initializing libx52"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_device.c:109
|
||||
#: daemon/x52d_device.c:111
|
||||
#, c-format
|
||||
msgid "Failure %d initializing libx52: %s"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_device.c:128
|
||||
#: daemon/x52d_device.c:130
|
||||
msgid "Shutting down X52 device acquisition thread"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_device.c:131
|
||||
#: daemon/x52d_device.c:133
|
||||
msgid "Shutting down X52 device update thread"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_device.c:144
|
||||
#: daemon/x52d_device.c:146
|
||||
#, c-format
|
||||
msgid "Error %d when updating X52 parameter: %s"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_device.c:224
|
||||
#: daemon/x52d_device.c:226 daemon/x52d_device.c:261
|
||||
#, c-format
|
||||
msgid "Error %d when updating X52 device: %s"
|
||||
msgstr ""
|
||||
|
|
14
po/xx_PL.po
14
po/xx_PL.po
|
@ -7,7 +7,7 @@ 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-08-30 11:59-0700\n"
|
||||
"POT-Creation-Date: 2021-08-30 12:33-0700\n"
|
||||
"PO-Revision-Date: 2021-08-30 10:41-0700\n"
|
||||
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
||||
"Language-Team: Dummy Language for testing i18n\n"
|
||||
|
@ -737,29 +737,29 @@ msgstr "Eviceday onnectedcay, itingwray onfigurationcay"
|
|||
msgid "Starting X52 device update thread"
|
||||
msgstr "Artingstay X52 eviceday updateay eadthray"
|
||||
|
||||
#: daemon/x52d_device.c:105
|
||||
#: daemon/x52d_device.c:107
|
||||
msgid "Initializing libx52"
|
||||
msgstr "Initializingay libx52"
|
||||
|
||||
#: daemon/x52d_device.c:109
|
||||
#: daemon/x52d_device.c:111
|
||||
#, c-format
|
||||
msgid "Failure %d initializing libx52: %s"
|
||||
msgstr "Ailurefay %d initializeay libx52: %s"
|
||||
|
||||
#: daemon/x52d_device.c:128
|
||||
#: daemon/x52d_device.c:130
|
||||
msgid "Shutting down X52 device acquisition thread"
|
||||
msgstr "Uttingshay ownday X52 eviceday acquisitionay eadthray"
|
||||
|
||||
#: daemon/x52d_device.c:131
|
||||
#: daemon/x52d_device.c:133
|
||||
msgid "Shutting down X52 device update thread"
|
||||
msgstr "Uttingshay ownday X52 eviceday updateay eadthray"
|
||||
|
||||
#: daemon/x52d_device.c:144
|
||||
#: daemon/x52d_device.c:146
|
||||
#, c-format
|
||||
msgid "Error %d when updating X52 parameter: %s"
|
||||
msgstr "Erroray %d enwhay updatingay X52 arameterpay: %s"
|
||||
|
||||
#: daemon/x52d_device.c:224
|
||||
#: daemon/x52d_device.c:226 daemon/x52d_device.c:261
|
||||
#, c-format
|
||||
msgid "Error %d when updating X52 device: %s"
|
||||
msgstr "Erroray %d enwhay updatingay X52 eviceday: %s"
|
||||
|
|
Loading…
Reference in New Issue