Skip to content

Instantly share code, notes, and snippets.

@dragonfax
Last active April 17, 2018 02:32
Show Gist options
  • Save dragonfax/e35c3b4b58f9e3dc5555 to your computer and use it in GitHub Desktop.
Save dragonfax/e35c3b4b58f9e3dc5555 to your computer and use it in GitHub Desktop.
output readings from a Griffin PowerMate USB on osx

I was toying around with my PowerMate USB on the Mac.

I noticed that in the PowerMate application, you can set triggers for mouse wheel scrolling. But some applications coughMAMEcough don't pick it up.

Investigating I found that it provides its spinner as a uncommon HID type. So applications ignore it, not knowing how to handle that.

The click is presented as a normal button though. So no big deal there.

  1. brew install libusb
  2. brew install hidapi
  3. gcc -o hid_browser hid_browser.c -I/usr/local//Cellar/hidapi/0.8.0-rc1/include/hidapi/ -lhidapi
  4. ./hid_browser
Hershwild:~ jstillwell$ ./hid_browser 
Manufacturer String: Griffin Technology, Inc.
Product String: Griffin PowerMate
Serial Number String: 
Feature Report
   00 00 00 f2 01 04 
#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];
hid_device *handle;
int i;
/*
// Enumerate and print the HID devices on the system
struct hid_device_info *devs, *cur_dev;
devs = hid_enumerate(0x0, 0x0);
cur_dev = devs;
while (cur_dev) {
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);
printf("\n");
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
printf(" Product: %ls\n", cur_dev->product_string);
printf("\n");
cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);
*/
// Open the device using the VID, PID,
// and optionally the Serial number.
handle = hid_open(0x077d, 0x0410, 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: %ls", wstr);
printf("\n");
// Send a Feature Report to the device
buf[0] = 0x2; // First byte is report number
buf[1] = 0xa0;
buf[2] = 0x0a;
res = hid_send_feature_report(handle, buf, 17);
// Read a Feature Report from the device
buf[0] = 0x2;
res = hid_get_feature_report(handle, buf, sizeof(buf));
// Print out the returned buffer.
printf("Feature Report\n ");
for (i = 0; i < res; i++)
printf("%02hhx ", buf[i]);
printf("\n");
// Set the hid_read() function to be non-blocking.
hid_set_nonblocking(handle, 1);
// Send an Output report to toggle the LED (cmd 0x80)
buf[0] = 1; // First byte is report number
buf[1] = 0x80;
res = hid_write(handle, buf, 65);
// Send an Output report to request the state (cmd 0x81)
buf[1] = 0x81;
hid_write(handle, buf, 65);
// Read requested state
res = hid_read(handle, buf, 65);
if (res < 0)
printf("Unable to read()\n");
// Print out the returned buffer.
for (i = 0; i < res; i++)
printf("buf[%d]: %d\n", i, buf[i]);
return 0;
}
@dragonfax
Copy link
Author

Turns out that you can get usb-utils for the mac (there is a port), and the lsusb command works great to dump the hid descriptors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment