1 From 2fb04c2245167e247b95400112b5dbea12fcb206 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Wed, 30 Dec 2015 20:02:29 +0100
4 Subject: [PATCH] hidtest: dont' use a C++ source file, since it's pure C
6 This allows to build the test program with toolchains that don't have
9 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
11 hidtest/Makefile.am | 6 +-
12 hidtest/hidtest.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++
13 hidtest/hidtest.cpp | 194 ----------------------------------------------------
14 3 files changed, 197 insertions(+), 197 deletions(-)
15 create mode 100644 hidtest/hidtest.c
16 delete mode 100644 hidtest/hidtest.cpp
18 diff --git a/hidtest/Makefile.am b/hidtest/Makefile.am
19 index d278644..5f52c3f 100644
20 --- a/hidtest/Makefile.am
21 +++ b/hidtest/Makefile.am
22 @@ -4,17 +4,17 @@ AM_CPPFLAGS = -I$(top_srcdir)/hidapi/
24 noinst_PROGRAMS = hidtest-libusb hidtest-hidraw
26 -hidtest_hidraw_SOURCES = hidtest.cpp
27 +hidtest_hidraw_SOURCES = hidtest.c
28 hidtest_hidraw_LDADD = $(top_builddir)/linux/libhidapi-hidraw.la
30 -hidtest_libusb_SOURCES = hidtest.cpp
31 +hidtest_libusb_SOURCES = hidtest.c
32 hidtest_libusb_LDADD = $(top_builddir)/libusb/libhidapi-libusb.la
36 noinst_PROGRAMS = hidtest
38 -hidtest_SOURCES = hidtest.cpp
39 +hidtest_SOURCES = hidtest.c
40 hidtest_LDADD = $(top_builddir)/$(backend)/libhidapi.la
43 diff --git a/hidtest/hidtest.c b/hidtest/hidtest.c
45 index 0000000..94f0a5c
47 +++ b/hidtest/hidtest.c
49 +/*******************************************************
50 + Windows HID simplification
59 + This contents of this file may be used by anyone
60 + for any reason without any conditions and may be
61 + used as a starting point for your own applications
63 +********************************************************/
71 +// Headers needed for sleeping.
73 + #include <windows.h>
78 +int main(int argc, char* argv[])
81 + unsigned char buf[256];
83 + wchar_t wstr[MAX_STR];
88 + UNREFERENCED_PARAMETER(argc);
89 + UNREFERENCED_PARAMETER(argv);
92 + struct hid_device_info *devs, *cur_dev;
97 + devs = hid_enumerate(0x0, 0x0);
100 + printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
102 + printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
103 + printf(" Product: %ls\n", cur_dev->product_string);
104 + printf(" Release: %hx\n", cur_dev->release_number);
105 + printf(" Interface: %d\n", cur_dev->interface_number);
107 + cur_dev = cur_dev->next;
109 + hid_free_enumeration(devs);
111 + // Set up the command buffer.
112 + memset(buf,0x00,sizeof(buf));
117 + // Open the device using the VID, PID,
118 + // and optionally the Serial number.
119 + ////handle = hid_open(0x4d8, 0x3f, L"12345");
120 + handle = hid_open(0x4d8, 0x3f, NULL);
122 + printf("unable to open device\n");
126 + // Read the Manufacturer String
128 + res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
130 + printf("Unable to read manufacturer string\n");
131 + printf("Manufacturer String: %ls\n", wstr);
133 + // Read the Product String
135 + res = hid_get_product_string(handle, wstr, MAX_STR);
137 + printf("Unable to read product string\n");
138 + printf("Product String: %ls\n", wstr);
140 + // Read the Serial Number String
142 + res = hid_get_serial_number_string(handle, wstr, MAX_STR);
144 + printf("Unable to read serial number string\n");
145 + printf("Serial Number String: (%d) %ls", wstr[0], wstr);
148 + // Read Indexed String 1
150 + res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
152 + printf("Unable to read indexed string 1\n");
153 + printf("Indexed String 1: %ls\n", wstr);
155 + // Set the hid_read() function to be non-blocking.
156 + hid_set_nonblocking(handle, 1);
158 + // Try to read from the device. There shoud be no
159 + // data here, but execution should not block.
160 + res = hid_read(handle, buf, 17);
162 + // Send a Feature Report to the device
168 + res = hid_send_feature_report(handle, buf, 17);
170 + printf("Unable to send a feature report.\n");
173 + memset(buf,0,sizeof(buf));
175 + // Read a Feature Report from the device
177 + res = hid_get_feature_report(handle, buf, sizeof(buf));
179 + printf("Unable to get a feature report.\n");
180 + printf("%ls", hid_error(handle));
183 + // Print out the returned buffer.
184 + printf("Feature Report\n ");
185 + for (i = 0; i < res; i++)
186 + printf("%02hhx ", buf[i]);
190 + memset(buf,0,sizeof(buf));
192 + // Toggle LED (cmd 0x80). The first byte is the report number (0x1).
195 + res = hid_write(handle, buf, 17);
197 + printf("Unable to write()\n");
198 + printf("Error: %ls\n", hid_error(handle));
202 + // Request state (cmd 0x81). The first byte is the report number (0x1).
205 + hid_write(handle, buf, 17);
207 + printf("Unable to write() (2)\n");
209 + // Read requested state. hid_read() has been set to be
210 + // non-blocking by the call to hid_set_nonblocking() above.
211 + // This loop demonstrates the non-blocking nature of hid_read().
214 + res = hid_read(handle, buf, sizeof(buf));
216 + printf("waiting...\n");
218 + printf("Unable to read()\n");
226 + printf("Data read:\n ");
227 + // Print out the returned buffer.
228 + for (i = 0; i < res; i++)
229 + printf("%02hhx ", buf[i]);
234 + /* Free static HIDAPI objects. */
243 diff --git a/hidtest/hidtest.cpp b/hidtest/hidtest.cpp
244 deleted file mode 100644
245 index 94f0a5c..0000000
246 --- a/hidtest/hidtest.cpp
249 -/*******************************************************
250 - Windows HID simplification
259 - This contents of this file may be used by anyone
260 - for any reason without any conditions and may be
261 - used as a starting point for your own applications
263 -********************************************************/
271 -// Headers needed for sleeping.
273 - #include <windows.h>
275 - #include <unistd.h>
278 -int main(int argc, char* argv[])
281 - unsigned char buf[256];
282 - #define MAX_STR 255
283 - wchar_t wstr[MAX_STR];
284 - hid_device *handle;
288 - UNREFERENCED_PARAMETER(argc);
289 - UNREFERENCED_PARAMETER(argv);
292 - struct hid_device_info *devs, *cur_dev;
297 - devs = hid_enumerate(0x0, 0x0);
300 - printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
302 - printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
303 - printf(" Product: %ls\n", cur_dev->product_string);
304 - printf(" Release: %hx\n", cur_dev->release_number);
305 - printf(" Interface: %d\n", cur_dev->interface_number);
307 - cur_dev = cur_dev->next;
309 - hid_free_enumeration(devs);
311 - // Set up the command buffer.
312 - memset(buf,0x00,sizeof(buf));
317 - // Open the device using the VID, PID,
318 - // and optionally the Serial number.
319 - ////handle = hid_open(0x4d8, 0x3f, L"12345");
320 - handle = hid_open(0x4d8, 0x3f, NULL);
322 - printf("unable to open device\n");
326 - // Read the Manufacturer String
328 - res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
330 - printf("Unable to read manufacturer string\n");
331 - printf("Manufacturer String: %ls\n", wstr);
333 - // Read the Product String
335 - res = hid_get_product_string(handle, wstr, MAX_STR);
337 - printf("Unable to read product string\n");
338 - printf("Product String: %ls\n", wstr);
340 - // Read the Serial Number String
342 - res = hid_get_serial_number_string(handle, wstr, MAX_STR);
344 - printf("Unable to read serial number string\n");
345 - printf("Serial Number String: (%d) %ls", wstr[0], wstr);
348 - // Read Indexed String 1
350 - res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
352 - printf("Unable to read indexed string 1\n");
353 - printf("Indexed String 1: %ls\n", wstr);
355 - // Set the hid_read() function to be non-blocking.
356 - hid_set_nonblocking(handle, 1);
358 - // Try to read from the device. There shoud be no
359 - // data here, but execution should not block.
360 - res = hid_read(handle, buf, 17);
362 - // Send a Feature Report to the device
368 - res = hid_send_feature_report(handle, buf, 17);
370 - printf("Unable to send a feature report.\n");
373 - memset(buf,0,sizeof(buf));
375 - // Read a Feature Report from the device
377 - res = hid_get_feature_report(handle, buf, sizeof(buf));
379 - printf("Unable to get a feature report.\n");
380 - printf("%ls", hid_error(handle));
383 - // Print out the returned buffer.
384 - printf("Feature Report\n ");
385 - for (i = 0; i < res; i++)
386 - printf("%02hhx ", buf[i]);
390 - memset(buf,0,sizeof(buf));
392 - // Toggle LED (cmd 0x80). The first byte is the report number (0x1).
395 - res = hid_write(handle, buf, 17);
397 - printf("Unable to write()\n");
398 - printf("Error: %ls\n", hid_error(handle));
402 - // Request state (cmd 0x81). The first byte is the report number (0x1).
405 - hid_write(handle, buf, 17);
407 - printf("Unable to write() (2)\n");
409 - // Read requested state. hid_read() has been set to be
410 - // non-blocking by the call to hid_set_nonblocking() above.
411 - // This loop demonstrates the non-blocking nature of hid_read().
414 - res = hid_read(handle, buf, sizeof(buf));
416 - printf("waiting...\n");
418 - printf("Unable to read()\n");
426 - printf("Data read:\n ");
427 - // Print out the returned buffer.
428 - for (i = 0; i < res; i++)
429 - printf("%02hhx ", buf[i]);
434 - /* Free static HIDAPI objects. */