Skip to content

Commit

Permalink
Add dumping/decoding of manufacturer and product
Browse files Browse the repository at this point in the history
  • Loading branch information
spbnick committed Sep 28, 2013
1 parent 4141049 commit 2254d5c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 16 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ device address is 3 and you probe it like this:

The output will be something like this:

S 64 12 03 00 7D 20 4E 03 00 FF 07 A0 0F 08 00 00 00 00 00
S 65 04 03 20 A0
S 6E 04 03 00 30
S 79 0A 03 4D 00 35 00 30 00 38 00
S 7A 08 03 01 00 00 00 00 00
M 48 00 55 00 49 00 4F 00 4E 00
P 35 00 38 00 30 00
S 64 12 03 00 7D 20 4E 03 00 FF 07 A0 0F 08 00 00 00 00 00
S 65 04 03 20 A0
S 6E 04 03 00 30
S 79 0A 03 4D 00 35 00 30 00 38 00
S 7A 08 03 01 00 00 00 00 00

Huion-decode simply expects huion-probe output on its input. For the
diagnostics dump above it will produce this:

Manufacturer: HUION
Product: 580
Max X: 32000
Max Y: 20000
Max pressure: 2047
Expand Down
28 changes: 25 additions & 3 deletions huion-decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,18 @@ print_unicode(const uint8_t *ptr, int len)
}
}

static void
print_field_unicode(const char *name, const uint8_t *ptr, int len)
{
printf("%14s: ", name);
print_unicode(ptr, len);
putchar('\n');
}

static int
decode_internal_model(const uint8_t *ptr, int len)
{
printf("%14s: ", "Internal model");
print_unicode(ptr + 2, len - 2);
putchar('\n');
print_field_unicode("Internal model", ptr + 2, len - 2);
return 0;
}

Expand Down Expand Up @@ -122,8 +128,24 @@ decode_desc(const uint8_t *buf, int len)
return 0;
}

static int
decode_manufacturer(const uint8_t *buf, int len)
{
print_field_unicode("Manufacturer", buf, len);
return 0;
}

static int
decode_product(const uint8_t *buf, int len)
{
print_field_unicode("Product", buf, len);
return 0;
}

/* List of chunk decoders */
static const struct decoder chunk_list[] = {
{'M', decode_manufacturer},
{'P', decode_product},
{'S', decode_desc},
{'\0', NULL}
};
Expand Down
46 changes: 38 additions & 8 deletions huion-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ libusb_strerror(enum libusb_error err)
LIBUSB_FAILURE_CLEANUP(err, _fmt, ##_args); \
} while (0)

static void
print_chunk(char type, unsigned char *ptr, int len)
{
printf("%c", type);
for (; len > 0; ptr++, len--)
printf(" %.2hhX", *ptr);
printf("\n");
fflush(stdout);
}

static int
probe(uint8_t bus_num, uint8_t dev_addr)
{
Expand All @@ -115,11 +125,12 @@ probe(uint8_t bus_num, uint8_t dev_addr)
size_t i;
libusb_device *dev;
libusb_device_handle *handle = NULL;
unsigned char buf[256];
unsigned char buf[257];
int len;
uint8_t idx_list[] = {0x64, 0x65, 0x6E, 0x79, 0x7A};
uint8_t idx;
const unsigned char *p;

struct libusb_device_descriptor dev_desc;

LIBUSB_GUARD(libusb_init(&ctx), "initialize libusb");

Expand All @@ -137,28 +148,47 @@ probe(uint8_t bus_num, uint8_t dev_addr)
LIBUSB_GUARD(libusb_open(dev, &handle), "open device");
libusb_free_device_list(dev_list, true);
dev_list = NULL;

LIBUSB_GUARD(libusb_get_device_descriptor(dev, &dev_desc),
"get device descriptor");
if (dev_desc.iManufacturer != 0) {
LIBUSB_GUARD(len = libusb_get_string_descriptor(
handle, dev_desc.iManufacturer,
/* English (United States) */
0x0409,
buf, sizeof(buf)),
"get manufacturer string descriptor");
print_chunk('M', buf + 2, len - 2);
}
if (dev_desc.iProduct != 0) {
LIBUSB_GUARD(len = libusb_get_string_descriptor(
handle, dev_desc.iProduct,
/* English (United States) */
0x0409,
buf, sizeof(buf)),
"get product string descriptor");
print_chunk('P', buf + 2, len - 2);
}

for (i = 0; i < sizeof(idx_list) / sizeof(*idx_list); i++)
{
idx = idx_list[i];
buf[0] = idx;

/* Attempt to get the descriptor */
len = libusb_get_string_descriptor(
handle, idx,
/* English (United States) */
0x0409,
buf, sizeof(buf));
buf + 1, sizeof(buf) - 1);

/* If the descriptor doesn't exist */
if (len == LIBUSB_ERROR_PIPE)
continue;
LIBUSB_GUARD(len, "get string descriptor 0x%.2X", idx);

/* Print the descriptor */
printf("S %.2hhX ", idx);
for (p = buf; p < buf + len; p++)
printf(" %.2hhX", *p);
printf("\n");
fflush(stdout);
print_chunk('S', buf, len + 1);
}
result = 0;

Expand Down

0 comments on commit 2254d5c

Please sign in to comment.