diff options
author | Ondrej Čerman <ondrej.cerman@gmail.com> | 2019-12-28 20:02:36 +0100 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-12-29 21:46:38 -0800 |
commit | c125634658751d67492f8640d33247ed3760e481 (patch) | |
tree | c26ad81357f9d8485a6b12823cb40825bb37e84b | |
parent | 145d70e0a9696e194168eafadb3600c034df9e08 (diff) |
inputdevices: Added new vendor info + info from usb.ids
-rw-r--r-- | hardinfo/usb_util.c | 21 | ||||
-rw-r--r-- | includes/usb_util.h | 2 | ||||
-rw-r--r-- | modules/devices/inputdevices.c | 25 |
3 files changed, 36 insertions, 12 deletions
diff --git a/hardinfo/usb_util.c b/hardinfo/usb_util.c index 8b73332f..990ae78e 100644 --- a/hardinfo/usb_util.c +++ b/hardinfo/usb_util.c @@ -317,7 +317,7 @@ static gboolean usb_get_interface_sysfs(int conf, int number, return TRUE; } -void find_usb_ids_file() { +static void find_usb_ids_file() { if (usb_ids_file) return; char *file_search_order[] = { g_build_filename(g_get_user_config_dir(), "hardinfo", "usb.ids", NULL), @@ -333,6 +333,25 @@ void find_usb_ids_file() { } } +void usb_lookup_ids_vendor_product_str(gint vendor_id, gint product_id, + gchar **vendor_str, gchar **product_str) { + ids_query_result result = {}; + gchar *qpath; + + if (!usb_ids_file) + find_usb_ids_file(); + if (!usb_ids_file) + return; + + qpath = g_strdup_printf("%04x/%04x", vendor_id, product_id); + scan_ids_file(usb_ids_file, qpath, &result, -1); + if (result.results[0]) + *vendor_str = g_strdup(result.results[0]); + if (result.results[1]) + *product_str = g_strdup(result.results[1]); + g_free(qpath); +} + static gboolean usb_get_device_sysfs(int bus, int dev, const char* sysfspath, usbd *s) { usbi *intf; gboolean ok; diff --git a/includes/usb_util.h b/includes/usb_util.h index ed752449..e06e3c23 100644 --- a/includes/usb_util.h +++ b/includes/usb_util.h @@ -69,6 +69,8 @@ typedef struct usbi { usbd *usb_get_device_list(); int usbd_list_count(usbd *); void usbd_list_free(usbd *); +void usb_lookup_ids_vendor_product_str(gint vendor_id, gint product_id, + gchar **vendor_str, gchar **product_str); usbd *usb_get_device(int bus, int dev, const gchar* sysfspath); void usbd_free(usbd *); diff --git a/modules/devices/inputdevices.c b/modules/devices/inputdevices.c index 58fb2117..316461b7 100644 --- a/modules/devices/inputdevices.c +++ b/modules/devices/inputdevices.c @@ -40,6 +40,7 @@ __scan_input_devices(void) FILE *dev; gchar buffer[1024]; gchar *tmp, *name = NULL, *phys = NULL; + gchar *vendor_str = NULL, *product_str = NULL, *vendor_tags = NULL; gint bus = 0, vendor = 0, product = 0, version = 0; int d = 0, n = 0; @@ -86,6 +87,10 @@ __scan_input_devices(void) d = 3; // INPUT_PCSPKR } + if (vendor > 0 && product > 0 && g_str_has_prefix(phys, "usb-")) { + usb_lookup_ids_vendor_product_str(vendor, product, &vendor_str, &product_str); + } + tmp = g_strdup_printf("INP%d", ++n); input_list = h_strdup_cprintf("$%s$%s=\n", input_list, @@ -95,24 +100,19 @@ __scan_input_devices(void) tmp, name, input_devices[d].icon); - gchar *v_str = vendor_get_link(name); - if (g_strcmp0(v_str, name) == 0) - v_str = hardinfo_clean_value(v_str, 1); - name = hardinfo_clean_value(name, 1); - gchar *strhash = g_strdup_printf("[%s]\n" - /* Name */ "%s=%s\n" + /* Name */ "$^$%s=%s\n" /* Type */ "%s=%s\n" /* Bus */ "%s=0x%x\n" - /* Vendor */ "%s=[0x%x] %s\n" - /* Product */"%s=0x%x\n" + /* Vendor */ "$^$%s=[0x%x] %s\n" + /* Product */"%s=[0x%x] %s\n" /* Version */"%s=0x%x\n", _("Device Information"), _("Name"), name, _("Type"), input_devices[d].name, _("Bus"), bus, - _("Vendor"), vendor, v_str, - _("Product"), product, + _("Vendor"), vendor, vendor_str ? vendor_str: _("(Unknown)"), + _("Product"), product, product_str ? product_str: _("(Unknown)"), _("Version"), version ); if (phys && phys[1] != 0) { @@ -127,7 +127,10 @@ __scan_input_devices(void) g_free(tmp); g_free(phys); g_free(name); - g_free(v_str); + g_free(vendor_str); + g_free(product_str); + vendor_str = NULL; + product_str = NULL; } } |