info: use byte descriptors in di_info_get_product_name()

These contain more user-friendly names.

Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
Simon Ser 2022-06-10 19:28:01 +02:00
parent 4346c405b8
commit b4544c5012

34
info.c
View file

@ -43,22 +43,42 @@ di_info_get_edid(const struct di_info *info)
char * char *
di_info_get_product_name(const struct di_info *info) di_info_get_product_name(const struct di_info *info)
{ {
char name[64], serial[32]; char name[256], product_code[32], serial_code[32];
const char *product, *serial;
const struct di_edid_vendor_product *edid_vendor_product; const struct di_edid_vendor_product *edid_vendor_product;
const struct di_edid_display_descriptor *const *display_descs;
size_t i;
edid_vendor_product = di_edid_get_vendor_product(info->edid); edid_vendor_product = di_edid_get_vendor_product(info->edid);
snprintf(product_code, sizeof(product_code), "0x%X" PRIu16,
edid_vendor_product->product);
if (edid_vendor_product->serial != 0) { if (edid_vendor_product->serial != 0) {
snprintf(serial, sizeof(serial), " 0x%X" PRIu32, snprintf(serial_code, sizeof(serial), " 0x%X" PRIu32,
edid_vendor_product->serial); edid_vendor_product->serial);
} else { } else {
serial[0] = '\0'; serial_code[0] = '\0';
} }
/* TODO: use strings from Detailed Timing Descriptors, if any */ product = product_code;
snprintf(name, sizeof(name), "%.3s 0x%X" PRIu16 "%s", serial = serial_code;
edid_vendor_product->manufacturer, display_descs = di_edid_get_display_descriptors(info->edid);
edid_vendor_product->product, serial); for (i = 0; display_descs[i] != NULL; i++) {
const struct di_edid_display_descriptor *desc = display_descs[i];
switch (di_edid_display_descriptor_get_tag(desc)) {
case DI_EDID_DISPLAY_DESCRIPTOR_PRODUCT_SERIAL:
serial = di_edid_display_descriptor_get_string(desc);
break;
case DI_EDID_DISPLAY_DESCRIPTOR_PRODUCT_NAME:
product = di_edid_display_descriptor_get_string(desc);
break;
default:
break; /* Ignore */
}
}
snprintf(name, sizeof(name), "%.3s %s%s",
edid_vendor_product->manufacturer, product, serial);
return strdup(name); return strdup(name);
} }