mirror of
https://github.com/RPCS3/hidapi.git
synced 2026-07-21 17:05:32 -04:00
2fb125f4bf
Fixes for Release mode in hidtest-vc8.vcproj
101 lines
2.3 KiB
C++
101 lines
2.3 KiB
C++
/*******************************************************
|
|
Windows HID simplification
|
|
|
|
Alan Ott
|
|
Signal 11 Software
|
|
|
|
8/22/2009
|
|
|
|
Copyright 2009, All Rights Reserved.
|
|
|
|
This software may be used by anyone for any reason so
|
|
long as this copyright notice remains intact.
|
|
********************************************************/
|
|
|
|
#include <windows.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "hidapi.h"
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
int res;
|
|
unsigned char buf[65];
|
|
#define MAX_STR 255
|
|
wchar_t wstr[MAX_STR];
|
|
int handle;
|
|
int i;
|
|
|
|
UNREFERENCED_PARAMETER(argc);
|
|
UNREFERENCED_PARAMETER(argv);
|
|
|
|
// Set up the command buffer.
|
|
memset(buf,0x00,sizeof(buf));
|
|
buf[0] = 0;
|
|
buf[1] = 0x81;
|
|
|
|
|
|
// Open the device using the VID, PID,
|
|
// and optionally the Serial number.
|
|
////handle = hid_open(0x4d8, 0x3f, L"12345");
|
|
handle = hid_open(0x4d8, 0x3f, NULL);
|
|
if (handle < 0)
|
|
printf("Unable to open device\n");
|
|
|
|
// Read the Manufacturer String
|
|
wstr[0] = 0x0000;
|
|
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
|
|
if (res < 0)
|
|
printf("Unable to read manufacturer string\n");
|
|
wprintf(L"Manufacturer String: %s\n", wstr);
|
|
|
|
// Read the Product String
|
|
wstr[0] = 0x0000;
|
|
res = hid_get_product_string(handle, wstr, MAX_STR);
|
|
if (res < 0)
|
|
printf("Unable to read product string\n");
|
|
wprintf(L"Product String: %s\n", wstr);
|
|
|
|
// Read the Serial Number String
|
|
wstr[0] = 0x0000;
|
|
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
|
|
if (res < 0)
|
|
printf("Unable to read serial number string\n");
|
|
wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr);
|
|
|
|
// Read Indexed String 1
|
|
wstr[0] = 0x0000;
|
|
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
|
|
if (res < 0)
|
|
printf("Unable to read indexed string 1\n");
|
|
wprintf(L"Indexed String 1: %s\n", wstr);
|
|
|
|
// Toggle LED (cmd 0x80). The first byte is the report number (0x0).
|
|
buf[0] = 0x0;
|
|
buf[1] = 0x80;
|
|
res = hid_write(handle, buf, 65);
|
|
if (res < 0)
|
|
printf("Unable to write()\n");
|
|
|
|
// Request state (cmd 0x81). The first byte is the report number (0x0).
|
|
buf[0] = 0x0;
|
|
buf[1] = 0x81;
|
|
hid_write(handle, buf, 65);
|
|
if (res < 0)
|
|
printf("Unable to write() (2)\n");
|
|
|
|
// Read requested state
|
|
hid_read(handle, buf, 65);
|
|
if (res < 0)
|
|
printf("Unable to read()\n");
|
|
|
|
// Print out the returned buffer.
|
|
for (i = 0; i < 4; i++)
|
|
printf("buf[%d]: %d\n", i, buf[i]);
|
|
|
|
system("pause");
|
|
|
|
return 0;
|
|
}
|