From f6136fcef01d116ecf44038a9359649bb6577e78 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Sun, 12 Jul 2020 00:08:20 -0700 Subject: [PATCH] Add device info API --- lib/libx52io/io_device.c | 31 +++++++++++++++++++ lib/libx52io/libx52io.h | 66 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/lib/libx52io/io_device.c b/lib/libx52io/io_device.c index 93e03f5..4ba4c2d 100644 --- a/lib/libx52io/io_device.c +++ b/lib/libx52io/io_device.c @@ -85,3 +85,34 @@ void _x52io_release_device_info(libx52io_context *ctx) ctx->parser = NULL; ctx->handle = NULL; } + +uint16_t libx52io_get_vendor_id(libx52io_context *ctx) +{ + return (ctx ? ctx->vid : 0); +} + +uint16_t libx52io_get_product_id(libx52io_context *ctx) +{ + return (ctx ? ctx->pid : 0); +} + +uint16_t libx52io_get_device_version(libx52io_context *ctx) +{ + return (ctx ? ctx->version : 0); +} + +const char * libx52io_get_manufacturer_string(libx52io_context *ctx) +{ + return (ctx ? ctx->manufacturer : NULL); +} + +const char * libx52io_get_product_string(libx52io_context *ctx) +{ + return (ctx ? ctx->product : NULL); +} + +const char * libx52io_get_serial_number_string(libx52io_context *ctx) +{ + return (ctx ? ctx->serial_number : NULL); +} + diff --git a/lib/libx52io/libx52io.h b/lib/libx52io/libx52io.h index 30e46f7..dff593b 100644 --- a/lib/libx52io/libx52io.h +++ b/lib/libx52io/libx52io.h @@ -425,6 +425,72 @@ const char * libx52io_axis_to_str(libx52io_axis axis); */ const char * libx52io_button_to_str(libx52io_button button); +/** + * @brief Get the vendor ID of the connected X52 device. + * + * @param[in] ctx Pointer to the device context + * + * @returns Vendor ID of the connected device. Returns 0 if no device is connected. + */ +uint16_t libx52io_get_vendor_id(libx52io_context *ctx); + +/** + * @brief Get the product ID of the connected X52 device. + * + * @param[in] ctx Pointer to the device context + * + * @returns Product ID of the connected device. Returns 0 if no device is connected. + */ +uint16_t libx52io_get_product_id(libx52io_context *ctx); + +/** + * @brief Get the device version of the connected X52 device. + * + * @param[in] ctx Pointer to the device context + * + * @returns Device version of the connected device. Returns 0 if no device is connected. + */ +uint16_t libx52io_get_device_version(libx52io_context *ctx); + +/** + * @brief Get the manufacturer string of the connected X52 device. + * + * Returns a pointer to a string which can be passed to \c printf or \c puts. + * This pointer must not be freed. + * + * @param[in] ctx Pointer to the device context + * + * @returns Pointer to the manufacturer string, which may be NULL. Return value + * is always NULL if no device is connected. + */ +const char * libx52io_get_manufacturer_string(libx52io_context *ctx); + +/** + * @brief Get the product string of the connected X52 device. + * + * Returns a pointer to a string which can be passed to \c printf or \c puts. + * This pointer must not be freed. + * + * @param[in] ctx Pointer to the device context + * + * @returns Pointer to the product string, which may be NULL. Return value + * is always NULL if no device is connected. + */ +const char * libx52io_get_product_string(libx52io_context *ctx); + +/** + * @brief Get the serial number of the connected X52 device. + * + * Returns a pointer to a string which can be passed to \c printf or \c puts. + * This pointer must not be freed. + * + * @param[in] ctx Pointer to the device context + * + * @returns Pointer to the serial number string, which may be NULL. Return value + * is always NULL if no device is connected. + */ +const char * libx52io_get_serial_number_string(libx52io_context *ctx); + /** @} */ #ifdef __cplusplus