mirror of https://github.com/nirenjan/libx52.git
Add denoising to x52evtest
parent
798714dd1c
commit
104fcb46f9
|
@ -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: 2020-07-13 18:02-0700\n"
|
"POT-Creation-Date: 2020-07-16 04:24-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"
|
||||||
|
@ -110,26 +110,26 @@ msgstr ""
|
||||||
msgid "Read timeout"
|
msgid "Read timeout"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:88
|
#: utils/evtest/ev_test.c:109
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n"
|
msgid "Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:92
|
#: utils/evtest/ev_test.c:113
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Device name: \"%s %s\"\n"
|
msgid "Device name: \"%s %s\"\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:95
|
#: utils/evtest/ev_test.c:116
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Serial number: \"%s\"\n"
|
msgid "Serial number: \"%s\"\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:96
|
#: utils/evtest/ev_test.c:117
|
||||||
msgid "Testing (interrupt to exit)\n"
|
msgid "Testing (interrupt to exit)\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:125 utils/evtest/ev_test.c:132
|
#: utils/evtest/ev_test.c:157 utils/evtest/ev_test.c:165
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Event @ %ld.%06ld: %s, value %d\n"
|
msgid "Event @ %ld.%06ld: %s, value %d\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
12
po/xx_PL.po
12
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: 2020-07-13 18:02-0700\n"
|
"POT-Creation-Date: 2020-07-16 04:24-0700\n"
|
||||||
"PO-Revision-Date: 2020-07-13 18:05-0700\n"
|
"PO-Revision-Date: 2020-07-13 18:05-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"
|
||||||
|
@ -110,26 +110,26 @@ msgstr "I/O erroray"
|
||||||
msgid "Read timeout"
|
msgid "Read timeout"
|
||||||
msgstr "Eadray imeouttay"
|
msgstr "Eadray imeouttay"
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:88
|
#: utils/evtest/ev_test.c:109
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n"
|
msgid "Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n"
|
||||||
msgstr "Eviceday IDay: endorvay 0x%04x oductpray 0x%04x ersionvay 0x%04x\n"
|
msgstr "Eviceday IDay: endorvay 0x%04x oductpray 0x%04x ersionvay 0x%04x\n"
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:92
|
#: utils/evtest/ev_test.c:113
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Device name: \"%s %s\"\n"
|
msgid "Device name: \"%s %s\"\n"
|
||||||
msgstr "Eviceday amenay: \"%s %s\"\n"
|
msgstr "Eviceday amenay: \"%s %s\"\n"
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:95
|
#: utils/evtest/ev_test.c:116
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Serial number: \"%s\"\n"
|
msgid "Serial number: \"%s\"\n"
|
||||||
msgstr "Erialsay umbernay: \"%s\"\n"
|
msgstr "Erialsay umbernay: \"%s\"\n"
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:96
|
#: utils/evtest/ev_test.c:117
|
||||||
msgid "Testing (interrupt to exit)\n"
|
msgid "Testing (interrupt to exit)\n"
|
||||||
msgstr "Estingtay (interruptay otay exitay)\n"
|
msgstr "Estingtay (interruptay otay exitay)\n"
|
||||||
|
|
||||||
#: utils/evtest/ev_test.c:125 utils/evtest/ev_test.c:132
|
#: utils/evtest/ev_test.c:157 utils/evtest/ev_test.c:165
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Event @ %ld.%06ld: %s, value %d\n"
|
msgid "Event @ %ld.%06ld: %s, value %d\n"
|
||||||
msgstr "Eventay @ %ld.%06ld: %s, aluevay %d\n"
|
msgstr "Eventay @ %ld.%06ld: %s, aluevay %d\n"
|
||||||
|
|
|
@ -47,12 +47,16 @@ static void signal_handler(int sig)
|
||||||
exit_loop = true;
|
exit_loop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Denoising - reduce event noise due to adjacent values being reported */
|
||||||
|
static bool denoise = true;
|
||||||
|
|
||||||
/* For i18n */
|
/* For i18n */
|
||||||
#define _(x) gettext(x)
|
#define _(x) gettext(x)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
libx52io_context *ctx;
|
libx52io_context *ctx;
|
||||||
libx52io_report last, curr;
|
libx52io_report last, curr;
|
||||||
|
int32_t denoise_mask[LIBX52IO_AXIS_MAX] = { 0 };
|
||||||
int rc;
|
int rc;
|
||||||
#define CHECK_RC() do { \
|
#define CHECK_RC() do { \
|
||||||
if (rc != LIBX52IO_SUCCESS) { \
|
if (rc != LIBX52IO_SUCCESS) { \
|
||||||
|
@ -79,6 +83,23 @@ int main(int argc, char **argv)
|
||||||
rc = libx52io_open(ctx);
|
rc = libx52io_open(ctx);
|
||||||
CHECK_RC();
|
CHECK_RC();
|
||||||
|
|
||||||
|
/* Initialize denoising */
|
||||||
|
if (denoise) {
|
||||||
|
for (int i = LIBX52IO_AXIS_X; i < LIBX52IO_AXIS_MAX; i++) {
|
||||||
|
int32_t min, max;
|
||||||
|
rc = libx52io_get_axis_range(ctx, i, &min, &max);
|
||||||
|
CHECK_RC();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Denoising algorithm ignores the last few bits of the axis,
|
||||||
|
* and is based on the maximum value of the axis. The mask is
|
||||||
|
* ~(max >> 6) which will do nothing for the axis with a small
|
||||||
|
* range, but reduce the noise on those with a larger range.
|
||||||
|
*/
|
||||||
|
denoise_mask[i] = ~(max >> 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Set up the signal handler to terminate the loop on SIGTERM or SIGINT */
|
/* Set up the signal handler to terminate the loop on SIGTERM or SIGINT */
|
||||||
exit_loop = false;
|
exit_loop = false;
|
||||||
signal(SIGTERM, signal_handler);
|
signal(SIGTERM, signal_handler);
|
||||||
|
@ -98,6 +119,7 @@ int main(int argc, char **argv)
|
||||||
/* Wait until we get an event */
|
/* Wait until we get an event */
|
||||||
while (!exit_loop) {
|
while (!exit_loop) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
bool printed = false;
|
||||||
|
|
||||||
/* Wait for 1 second before timing out */
|
/* Wait for 1 second before timing out */
|
||||||
rc = libx52io_read_timeout(ctx, &curr, 1000);
|
rc = libx52io_read_timeout(ctx, &curr, 1000);
|
||||||
|
@ -119,12 +141,23 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* Get the current timeval - we don't need a timezone */
|
/* Get the current timeval - we don't need a timezone */
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
puts("");
|
|
||||||
for (int axis = 0; axis < LIBX52IO_AXIS_MAX; axis++) {
|
for (int axis = 0; axis < LIBX52IO_AXIS_MAX; axis++) {
|
||||||
if (last.axis[axis] != curr.axis[axis]) {
|
if (last.axis[axis] != curr.axis[axis]) {
|
||||||
|
/* Account for denoising */
|
||||||
|
if (denoise) {
|
||||||
|
int32_t last_v = last.axis[axis] & denoise_mask[axis];
|
||||||
|
int32_t curr_v = curr.axis[axis] & denoise_mask[axis];
|
||||||
|
|
||||||
|
if (last_v == curr_v) {
|
||||||
|
/* Within the noise threshold */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printf(_("Event @ %ld.%06ld: %s, value %d\n"),
|
printf(_("Event @ %ld.%06ld: %s, value %d\n"),
|
||||||
(long int)tv.tv_sec, (long int)tv.tv_usec,
|
(long int)tv.tv_sec, (long int)tv.tv_usec,
|
||||||
libx52io_axis_to_str(axis), curr.axis[axis]);
|
libx52io_axis_to_str(axis), curr.axis[axis]);
|
||||||
|
printed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int btn = 0; btn < LIBX52IO_BUTTON_MAX; btn++) {
|
for (int btn = 0; btn < LIBX52IO_BUTTON_MAX; btn++) {
|
||||||
|
@ -132,9 +165,14 @@ int main(int argc, char **argv)
|
||||||
printf(_("Event @ %ld.%06ld: %s, value %d\n"),
|
printf(_("Event @ %ld.%06ld: %s, value %d\n"),
|
||||||
(long int)tv.tv_sec, (long int)tv.tv_usec,
|
(long int)tv.tv_sec, (long int)tv.tv_usec,
|
||||||
libx52io_button_to_str(btn), curr.button[btn]);
|
libx52io_button_to_str(btn), curr.button[btn]);
|
||||||
|
printed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (printed) {
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(&last, &curr, sizeof(curr));
|
memcpy(&last, &curr, sizeof(curr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue