Skip to content

Instantly share code, notes, and snippets.

@loentar
Created February 11, 2018 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loentar/939334593a73a11dc2f64bd586b9ad81 to your computer and use it in GitHub Desktop.
Save loentar/939334593a73a11dc2f64bd586b9ad81 to your computer and use it in GitHub Desktop.
Better probing the newer Huion tablets name
static int append_string (char** str, int* str_size, const char* what, bool separate)
{
int rc = snprintf(*str, *str_size, separate ? "%s " : "%s", what);
if (rc >= *str_size)
return 1;
*str += rc;
*str_size -= rc;
return 0;
}
static void uclogic_probe_model (const struct hid_device_id *id, struct hid_device *hdev)
{
int rc;
struct usb_device *usb_dev = hid_to_usb_dev(hdev);
const char *vendor = NULL;
const char *model = NULL;
char str_buf [64];
char* name = hdev->name;
int name_size = sizeof(hdev->name);
rc = usb_string(usb_dev, 0x79, str_buf, sizeof(str_buf));
if (rc > 0) {
model = str_buf;
} else if (id->vendor == USB_VENDOR_ID_HUION) {
/* read OEM device info */
rc = usb_string(usb_dev, 0xC9, str_buf, sizeof(str_buf));
if (rc > 0) {
char* tmp = str_buf;
vendor = strsep(&tmp, "_");
model = strsep(&tmp, "_");
}
}
if (!vendor) {
switch (id->vendor) {
case USB_VENDOR_ID_HUION: vendor = "Huion"; break;
case USB_VENDOR_ID_KYE: vendor = "Genius"; break;
case USB_VENDOR_ID_UCLOGIC: vendor = "UC-Logic"; break;
case USB_VENDOR_ID_POLOSTAR: vendor = "Polostar"; break;
case USB_VENDOR_ID_UGTIZER: vendor = "UGTizer"; break;
case USB_VENDOR_ID_UGEE: vendor = "Ugee"; break;
}
}
if (vendor) {
rc = append_string(&name, &name_size, vendor, true);
if (rc)
return;
}
if (model) {
rc = append_string(&name, &name_size, model, true);
if (rc)
return;
}
append_string(&name, &name_size, "Tablet", false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment