Add denoising to x52evtest

pull/26/head
nirenjan 2020-07-16 04:25:48 -07:00
parent 798714dd1c
commit 104fcb46f9
3 changed files with 51 additions and 13 deletions

View File

@ -8,7 +8,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: 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"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -110,26 +110,26 @@ msgstr ""
msgid "Read timeout"
msgstr ""
#: utils/evtest/ev_test.c:88
#: utils/evtest/ev_test.c:109
#, c-format
msgid "Device ID: vendor 0x%04x product 0x%04x version 0x%04x\n"
msgstr ""
#: utils/evtest/ev_test.c:92
#: utils/evtest/ev_test.c:113
#, c-format
msgid "Device name: \"%s %s\"\n"
msgstr ""
#: utils/evtest/ev_test.c:95
#: utils/evtest/ev_test.c:116
#, c-format
msgid "Serial number: \"%s\"\n"
msgstr ""
#: utils/evtest/ev_test.c:96
#: utils/evtest/ev_test.c:117
msgid "Testing (interrupt to exit)\n"
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
msgid "Event @ %ld.%06ld: %s, value %d\n"
msgstr ""

View File

@ -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: 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"
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
"Language-Team: Dummy Language for testing i18n\n"
@ -110,26 +110,26 @@ msgstr "I/O erroray"
msgid "Read timeout"
msgstr "Eadray imeouttay"
#: utils/evtest/ev_test.c:88
#: utils/evtest/ev_test.c:109
#, c-format
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"
#: utils/evtest/ev_test.c:92
#: utils/evtest/ev_test.c:113
#, c-format
msgid "Device name: \"%s %s\"\n"
msgstr "Eviceday amenay: \"%s %s\"\n"
#: utils/evtest/ev_test.c:95
#: utils/evtest/ev_test.c:116
#, c-format
msgid "Serial number: \"%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"
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
msgid "Event @ %ld.%06ld: %s, value %d\n"
msgstr "Eventay @ %ld.%06ld: %s, aluevay %d\n"

View File

@ -47,12 +47,16 @@ static void signal_handler(int sig)
exit_loop = true;
}
/* Denoising - reduce event noise due to adjacent values being reported */
static bool denoise = true;
/* For i18n */
#define _(x) gettext(x)
int main(int argc, char **argv)
{
libx52io_context *ctx;
libx52io_report last, curr;
int32_t denoise_mask[LIBX52IO_AXIS_MAX] = { 0 };
int rc;
#define CHECK_RC() do { \
if (rc != LIBX52IO_SUCCESS) { \
@ -79,6 +83,23 @@ int main(int argc, char **argv)
rc = libx52io_open(ctx);
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 */
exit_loop = false;
signal(SIGTERM, signal_handler);
@ -98,6 +119,7 @@ int main(int argc, char **argv)
/* Wait until we get an event */
while (!exit_loop) {
struct timeval tv;
bool printed = false;
/* Wait for 1 second before timing out */
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 */
gettimeofday(&tv, NULL);
puts("");
for (int axis = 0; axis < LIBX52IO_AXIS_MAX; 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"),
(long int)tv.tv_sec, (long int)tv.tv_usec,
libx52io_axis_to_str(axis), curr.axis[axis]);
printed = true;
}
}
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"),
(long int)tv.tv_sec, (long int)tv.tv_usec,
libx52io_button_to_str(btn), curr.button[btn]);
printed = true;
}
}
if (printed) {
puts("");
}
memcpy(&last, &curr, sizeof(curr));
}