From ec374ec29177eccbdb5d1c7a9add533641a510b5 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 11 Jun 2023 17:16:48 +0200 Subject: [PATCH] feat(extiotest): Add testing tool for real EXTIO devices A small but helpful tool to run a quick functional test of a real EXTIO device connected to the target machine. --- src/main/extiotest/Module.mk | 9 ++++++ src/main/extiotest/main.c | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/main/extiotest/Module.mk create mode 100644 src/main/extiotest/main.c diff --git a/src/main/extiotest/Module.mk b/src/main/extiotest/Module.mk new file mode 100644 index 0000000..73ec1b0 --- /dev/null +++ b/src/main/extiotest/Module.mk @@ -0,0 +1,9 @@ +exes += extiotest \ + +libs_extiotest := \ + extiodrv \ + extio \ + util \ + +src_extiotest := \ + main.c \ diff --git a/src/main/extiotest/main.c b/src/main/extiotest/main.c new file mode 100644 index 0000000..3be152b --- /dev/null +++ b/src/main/extiotest/main.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#include + +#include "extiodrv/extio.h" + +#include "util/log.h" + +int main(int argc, char **argv) +{ + HRESULT hr; + const char *port; + HANDLE handle; + struct extiodrv_extio_pad_lights pad_lights[EXTIO_PAD_LIGHT_MAX_PLAYERS]; + + if (argc < 2) { + fprintf(stderr, "Basic functional test of EXTIO\n"); + fprintf(stderr, "Usage: %s COM_PORT\n", argv[0]); + fprintf(stderr, " COM_PORT: For example COM1\n"); + } + + log_to_writer(log_writer_stderr, NULL); + log_set_level(LOG_LEVEL_MISC); + + port = argv[1]; + + hr = extiodrv_device_open(port, &handle); + + if (FAILED(hr)) { + fprintf(stderr, "Opening extio at port '%s' failed: %lX\n", port, hr); + return -1; + } + + memset(&pad_lights, 0, sizeof(pad_lights)); + + hr = extiodrv_extio_transfer( + handle, EXTIODRV_EXTIO_SENSOR_READ_MODE_ALL, pad_lights, false); + + if (FAILED(hr)) { + fprintf(stderr, "Extio transfer failed: %lX\n", hr); + return -1; + } + + hr = extiodrv_device_close(&handle); + + if (FAILED(hr)) { + fprintf(stderr, "Closing extio failed: %lX", hr); + return -1; + } + + return 0; +} \ No newline at end of file