python: fix disabling the SSL module
[buildroot-gz.git] / package / hidapi / 0001-hidtest-dont-use-a-C-source-file-since-it-s-pure-C.patch
blob4740cb7b8827f4c6e7457dcce1b9fa67b77ff541
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
7 C++ support.
9 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
10 ---
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/
23 if OS_LINUX
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
33 else
35 # Other OS's
36 noinst_PROGRAMS = hidtest
38 -hidtest_SOURCES = hidtest.cpp
39 +hidtest_SOURCES = hidtest.c
40 hidtest_LDADD = $(top_builddir)/$(backend)/libhidapi.la
42 endif
43 diff --git a/hidtest/hidtest.c b/hidtest/hidtest.c
44 new file mode 100644
45 index 0000000..94f0a5c
46 --- /dev/null
47 +++ b/hidtest/hidtest.c
48 @@ -0,0 +1,194 @@
49 +/*******************************************************
50 + Windows HID simplification
52 + Alan Ott
53 + Signal 11 Software
55 + 8/22/2009
57 + Copyright 2009
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
62 + which use HIDAPI.
63 +********************************************************/
65 +#include <stdio.h>
66 +#include <wchar.h>
67 +#include <string.h>
68 +#include <stdlib.h>
69 +#include "hidapi.h"
71 +// Headers needed for sleeping.
72 +#ifdef _WIN32
73 + #include <windows.h>
74 +#else
75 + #include <unistd.h>
76 +#endif
78 +int main(int argc, char* argv[])
80 + int res;
81 + unsigned char buf[256];
82 + #define MAX_STR 255
83 + wchar_t wstr[MAX_STR];
84 + hid_device *handle;
85 + int i;
87 +#ifdef WIN32
88 + UNREFERENCED_PARAMETER(argc);
89 + UNREFERENCED_PARAMETER(argv);
90 +#endif
92 + struct hid_device_info *devs, *cur_dev;
94 + if (hid_init())
95 + return -1;
97 + devs = hid_enumerate(0x0, 0x0);
98 + cur_dev = devs;
99 + while (cur_dev) {
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);
101 + printf("\n");
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);
106 + printf("\n");
107 + cur_dev = cur_dev->next;
109 + hid_free_enumeration(devs);
111 + // Set up the command buffer.
112 + memset(buf,0x00,sizeof(buf));
113 + buf[0] = 0x01;
114 + buf[1] = 0x81;
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);
121 + if (!handle) {
122 + printf("unable to open device\n");
123 + return 1;
126 + // Read the Manufacturer String
127 + wstr[0] = 0x0000;
128 + res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
129 + if (res < 0)
130 + printf("Unable to read manufacturer string\n");
131 + printf("Manufacturer String: %ls\n", wstr);
133 + // Read the Product String
134 + wstr[0] = 0x0000;
135 + res = hid_get_product_string(handle, wstr, MAX_STR);
136 + if (res < 0)
137 + printf("Unable to read product string\n");
138 + printf("Product String: %ls\n", wstr);
140 + // Read the Serial Number String
141 + wstr[0] = 0x0000;
142 + res = hid_get_serial_number_string(handle, wstr, MAX_STR);
143 + if (res < 0)
144 + printf("Unable to read serial number string\n");
145 + printf("Serial Number String: (%d) %ls", wstr[0], wstr);
146 + printf("\n");
148 + // Read Indexed String 1
149 + wstr[0] = 0x0000;
150 + res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
151 + if (res < 0)
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
163 + buf[0] = 0x2;
164 + buf[1] = 0xa0;
165 + buf[2] = 0x0a;
166 + buf[3] = 0x00;
167 + buf[4] = 0x00;
168 + res = hid_send_feature_report(handle, buf, 17);
169 + if (res < 0) {
170 + printf("Unable to send a feature report.\n");
173 + memset(buf,0,sizeof(buf));
175 + // Read a Feature Report from the device
176 + buf[0] = 0x2;
177 + res = hid_get_feature_report(handle, buf, sizeof(buf));
178 + if (res < 0) {
179 + printf("Unable to get a feature report.\n");
180 + printf("%ls", hid_error(handle));
182 + else {
183 + // Print out the returned buffer.
184 + printf("Feature Report\n ");
185 + for (i = 0; i < res; i++)
186 + printf("%02hhx ", buf[i]);
187 + printf("\n");
190 + memset(buf,0,sizeof(buf));
192 + // Toggle LED (cmd 0x80). The first byte is the report number (0x1).
193 + buf[0] = 0x1;
194 + buf[1] = 0x80;
195 + res = hid_write(handle, buf, 17);
196 + if (res < 0) {
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).
203 + buf[0] = 0x1;
204 + buf[1] = 0x81;
205 + hid_write(handle, buf, 17);
206 + if (res < 0)
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().
212 + res = 0;
213 + while (res == 0) {
214 + res = hid_read(handle, buf, sizeof(buf));
215 + if (res == 0)
216 + printf("waiting...\n");
217 + if (res < 0)
218 + printf("Unable to read()\n");
219 + #ifdef WIN32
220 + Sleep(500);
221 + #else
222 + usleep(500*1000);
223 + #endif
226 + printf("Data read:\n ");
227 + // Print out the returned buffer.
228 + for (i = 0; i < res; i++)
229 + printf("%02hhx ", buf[i]);
230 + printf("\n");
232 + hid_close(handle);
234 + /* Free static HIDAPI objects. */
235 + hid_exit();
237 +#ifdef WIN32
238 + system("pause");
239 +#endif
241 + return 0;
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
247 +++ /dev/null
248 @@ -1,194 +0,0 @@
249 -/*******************************************************
250 - Windows HID simplification
252 - Alan Ott
253 - Signal 11 Software
255 - 8/22/2009
257 - Copyright 2009
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
262 - which use HIDAPI.
263 -********************************************************/
265 -#include <stdio.h>
266 -#include <wchar.h>
267 -#include <string.h>
268 -#include <stdlib.h>
269 -#include "hidapi.h"
271 -// Headers needed for sleeping.
272 -#ifdef _WIN32
273 - #include <windows.h>
274 -#else
275 - #include <unistd.h>
276 -#endif
278 -int main(int argc, char* argv[])
280 - int res;
281 - unsigned char buf[256];
282 - #define MAX_STR 255
283 - wchar_t wstr[MAX_STR];
284 - hid_device *handle;
285 - int i;
287 -#ifdef WIN32
288 - UNREFERENCED_PARAMETER(argc);
289 - UNREFERENCED_PARAMETER(argv);
290 -#endif
292 - struct hid_device_info *devs, *cur_dev;
294 - if (hid_init())
295 - return -1;
297 - devs = hid_enumerate(0x0, 0x0);
298 - cur_dev = devs;
299 - while (cur_dev) {
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);
301 - printf("\n");
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);
306 - printf("\n");
307 - cur_dev = cur_dev->next;
309 - hid_free_enumeration(devs);
311 - // Set up the command buffer.
312 - memset(buf,0x00,sizeof(buf));
313 - buf[0] = 0x01;
314 - buf[1] = 0x81;
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);
321 - if (!handle) {
322 - printf("unable to open device\n");
323 - return 1;
326 - // Read the Manufacturer String
327 - wstr[0] = 0x0000;
328 - res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
329 - if (res < 0)
330 - printf("Unable to read manufacturer string\n");
331 - printf("Manufacturer String: %ls\n", wstr);
333 - // Read the Product String
334 - wstr[0] = 0x0000;
335 - res = hid_get_product_string(handle, wstr, MAX_STR);
336 - if (res < 0)
337 - printf("Unable to read product string\n");
338 - printf("Product String: %ls\n", wstr);
340 - // Read the Serial Number String
341 - wstr[0] = 0x0000;
342 - res = hid_get_serial_number_string(handle, wstr, MAX_STR);
343 - if (res < 0)
344 - printf("Unable to read serial number string\n");
345 - printf("Serial Number String: (%d) %ls", wstr[0], wstr);
346 - printf("\n");
348 - // Read Indexed String 1
349 - wstr[0] = 0x0000;
350 - res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
351 - if (res < 0)
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
363 - buf[0] = 0x2;
364 - buf[1] = 0xa0;
365 - buf[2] = 0x0a;
366 - buf[3] = 0x00;
367 - buf[4] = 0x00;
368 - res = hid_send_feature_report(handle, buf, 17);
369 - if (res < 0) {
370 - printf("Unable to send a feature report.\n");
373 - memset(buf,0,sizeof(buf));
375 - // Read a Feature Report from the device
376 - buf[0] = 0x2;
377 - res = hid_get_feature_report(handle, buf, sizeof(buf));
378 - if (res < 0) {
379 - printf("Unable to get a feature report.\n");
380 - printf("%ls", hid_error(handle));
382 - else {
383 - // Print out the returned buffer.
384 - printf("Feature Report\n ");
385 - for (i = 0; i < res; i++)
386 - printf("%02hhx ", buf[i]);
387 - printf("\n");
390 - memset(buf,0,sizeof(buf));
392 - // Toggle LED (cmd 0x80). The first byte is the report number (0x1).
393 - buf[0] = 0x1;
394 - buf[1] = 0x80;
395 - res = hid_write(handle, buf, 17);
396 - if (res < 0) {
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).
403 - buf[0] = 0x1;
404 - buf[1] = 0x81;
405 - hid_write(handle, buf, 17);
406 - if (res < 0)
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().
412 - res = 0;
413 - while (res == 0) {
414 - res = hid_read(handle, buf, sizeof(buf));
415 - if (res == 0)
416 - printf("waiting...\n");
417 - if (res < 0)
418 - printf("Unable to read()\n");
419 - #ifdef WIN32
420 - Sleep(500);
421 - #else
422 - usleep(500*1000);
423 - #endif
426 - printf("Data read:\n ");
427 - // Print out the returned buffer.
428 - for (i = 0; i < res; i++)
429 - printf("%02hhx ", buf[i]);
430 - printf("\n");
432 - hid_close(handle);
434 - /* Free static HIDAPI objects. */
435 - hid_exit();
437 -#ifdef WIN32
438 - system("pause");
439 -#endif
441 - return 0;
444 2.7.4