diff options
Diffstat (limited to 'f54test/main.cpp')
-rw-r--r-- | f54test/main.cpp | 63 |
1 files changed, 21 insertions, 42 deletions
diff --git a/f54test/main.cpp b/f54test/main.cpp index d0cf8f7..9b6486a 100644 --- a/f54test/main.cpp +++ b/f54test/main.cpp @@ -34,7 +34,7 @@ #include "f54test.h" #include "display.h" -#define F54TEST_GETOPTS "hd:r:cn" +#define F54TEST_GETOPTS "hd:r:cnt:" static bool stopRequested; @@ -46,12 +46,12 @@ void printHelp(const char *prog_name) fprintf(stdout, "\t-r, --report_type\tReport type.\n"); fprintf(stdout, "\t-c, --continuous\tContinuous mode.\n"); fprintf(stdout, "\t-n, --no_reset\tDo not reset after the report.\n"); + fprintf(stdout, "\t-t, --device-type\t\t\tFilter by device type [touchpad or touchscreen].\n"); } -int RunF54Test(const char * deviceFile, f54_report_types reportType, bool continuousMode, bool noReset) +int RunF54Test(RMIDevice & rmidevice, f54_report_types reportType, bool continuousMode, bool noReset) { int rc; - HIDDevice rmidevice; Display * display; if (continuousMode) @@ -65,10 +65,6 @@ int RunF54Test(const char * deviceFile, f54_report_types reportType, bool contin display->Clear(); - rc = rmidevice.Open(deviceFile); - if (rc) - return rc; - F54Test f54Test(rmidevice, *display); rc = f54Test.Prepare(reportType); @@ -85,8 +81,6 @@ int RunF54Test(const char * deviceFile, f54_report_types reportType, bool contin if (!noReset) rmidevice.Reset(); - rmidevice.Close(); - delete display; return rc; @@ -109,13 +103,14 @@ int main(int argc, char **argv) {"report_type", 1, NULL, 'r'}, {"continuous", 0, NULL, 'c'}, {"no_reset", 0, NULL, 'n'}, + {"device-type", 1, NULL, 't'}, {0, 0, 0, 0}, }; - struct dirent * devDirEntry; - DIR * devDir; f54_report_types reportType = F54_16BIT_IMAGE; bool continuousMode = false; bool noReset = false; + HIDDevice device; + enum RMIDeviceType deviceType = RMI_DEVICE_TYPE_ANY; while ((opt = getopt_long(argc, argv, F54TEST_GETOPTS, long_options, &index)) != -1) { switch (opt) { @@ -134,6 +129,12 @@ int main(int argc, char **argv) case 'n': noReset = true; break; + case 't': + if (!strcasecmp(optarg, "touchpad")) + deviceType = RMI_DEVICE_TYPE_TOUCHPAD; + else if (!strcasecmp(optarg, "touchscreen")) + deviceType = RMI_DEVICE_TYPE_TOUCHSCREEN; + break; default: break; @@ -148,38 +149,16 @@ int main(int argc, char **argv) } if (deviceName) { - rc = RunF54Test(deviceName, reportType, continuousMode, noReset); - if (rc) - return rc; - - return rc; - } else { - char rawDevice[PATH_MAX]; - char deviceFile[PATH_MAX]; - bool found = false; - - devDir = opendir("/dev"); - if (!devDir) - return -1; - - while ((devDirEntry = readdir(devDir)) != NULL) { - if (strstr(devDirEntry->d_name, "hidraw")) { - strncpy(rawDevice, devDirEntry->d_name, PATH_MAX); - snprintf(deviceFile, PATH_MAX, "/dev/%s", devDirEntry->d_name); - rc = RunF54Test(deviceFile, reportType, continuousMode, noReset); - if (rc != 0) { - continue; - } else { - found = true; - break; - } - } + rc = device.Open(deviceName); + if (rc) { + fprintf(stderr, "%s: failed to initialize rmi device (%d): %s\n", argv[0], errno, + strerror(errno)); + return 1; } - closedir(devDir); - - if (!found) - return rc; + } else { + if (!device.FindDevice(deviceType)) + return 1; } - return 0; + return RunF54Test(device, reportType, continuousMode, noReset); } |