mirror of
https://github.com/RPCS3/hidapi.git
synced 2026-07-19 13:34:37 -04:00
README.txt: Improve sample code
- use hid_init()/hid_exit() - include windows.h only on Windows
This commit is contained in:
committed by
Alan Ott
parent
1826eabaef
commit
e569477ef1
+9
-1
@@ -46,7 +46,9 @@ which communicates with a heavily hacked up version of the Microchip USB
|
||||
Generic HID sample looks like this (with error checking removed for
|
||||
simplicity):
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "hidapi.h"
|
||||
@@ -61,6 +63,9 @@ int main(int argc, char* argv[])
|
||||
hid_device *handle;
|
||||
int i;
|
||||
|
||||
// Initialize the hidapi library
|
||||
res = hid_init();
|
||||
|
||||
// Open the device using the VID, PID,
|
||||
// and optionally the Serial number.
|
||||
handle = hid_open(0x4d8, 0x3f, NULL);
|
||||
@@ -92,12 +97,15 @@ int main(int argc, char* argv[])
|
||||
res = hid_write(handle, buf, 65);
|
||||
|
||||
// Read requested state
|
||||
hid_read(handle, buf, 65);
|
||||
res = hid_read(handle, buf, 65);
|
||||
|
||||
// Print out the returned buffer.
|
||||
for (i = 0; i < 4; i++)
|
||||
printf("buf[%d]: %d\n", i, buf[i]);
|
||||
|
||||
// Finalize the hidapi library
|
||||
res = hid_exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user