Skip to content

Instantly share code, notes, and snippets.

@rngtng rngtng/Makefile
Created Feb 19, 2019

Embed
What would you like to do?
Testing mir:ror based on HIDapi 0.8.0-rc1
test: test.c
gcc -o test -lhidapi test.c
run: test
./test
#include <stdio.h>
#include <stdlib.h>
#include "include/hidapi/hidapi.h"
#define MAX_STR 255
int main(int argc, char* argv[])
{
int res;
unsigned char buf[65];
wchar_t wstr[MAX_STR];
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(0x1da8, 0x1301, NULL);
// Read the Manufacturer String
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
printf("Manufacturer String: %ls\n", wstr);
// Read the Product String
res = hid_get_product_string(handle, wstr, MAX_STR);
printf("Product String: %ls\n", wstr);
// Read the Serial Number String
res = hid_get_serial_number_string(handle, wstr, MAX_STR);
printf("Serial Number String: (%d) %ls\n", wstr[0], wstr);
// // Read Indexed String 1
// res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
// printf("Indexed String 1: %ls\n", wstr);
// buf[0] = 0x01;
// buf[1] = 0x01;
// buf[1] = 0x01;
// buf[1] = 0x01;
// buf[1] = 0x07;
// res = hid_write(handle, buf, 65);
// // Toggle LED (cmd 0x80). The first byte is the report number (0x0).
//
// // Request state (cmd 0x81). The first byte is the report number (0x0).
// buf[0] = 0x0;
// buf[1] = 0x81;
// res = hid_write(handle, buf, 65);
// Read requested state
// hid_set_nonblocking(handle, 0);
while(1) {
res = hid_read_timeout(handle, buf, 1, -1);
// Print out the returned buffer.
if(buf[0] != 0) {
printf("buf[%d]: %d\n", 0, buf[0]);
}
}
// Finalize the hidapi library
res = hid_exit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.