From 073203d3b5422e3be9ead3142a9bb659b4aa06dd Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 28 Jul 2024 18:58:07 -0500 Subject: [PATCH] Fix wstring to string conversion warnings in EKController.cpp --- Controllers/EKController/EKController.cpp | 36 +++++++++++++---------- Controllers/EKController/EKController.h | 8 ++--- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Controllers/EKController/EKController.cpp b/Controllers/EKController/EKController.cpp index 8ced4d9c..71543521 100644 --- a/Controllers/EKController/EKController.cpp +++ b/Controllers/EKController/EKController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include "EKController.h" +#include "StringUtils.cpp" static unsigned char ek_colour_mode_data[][16] = { @@ -48,24 +49,19 @@ static unsigned char ek_speed_mode_data[][9] = EKController::EKController(hid_device* dev_handle, char *_path) { - const int szTemp = 256; - wchar_t tmpName[szTemp]; + dev = dev_handle; + location = _path; - dev = dev_handle; + /*---------------------------------------------------------*\ + | Get device name from HID manufacturer and product strings | + \*---------------------------------------------------------*/ + wchar_t name_string[HID_MAX_STR]; - hid_get_manufacturer_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - device_name = std::string(wName.begin(), wName.end()); + hid_get_manufacturer_string(dev, name_string, HID_MAX_STR); + device_name = StringUtils::wstring_to_string(name_string); - hid_get_product_string(dev, tmpName, szTemp); - wName = std::wstring(tmpName); - device_name.append(" ").append(std::string(wName.begin(), wName.end())); - - hid_get_serial_number_string(dev, tmpName, szTemp); - wName = std::wstring(tmpName); - serial = std::string(wName.begin(), wName.end()); - - location = _path; + hid_get_product_string(dev, name_string, HID_MAX_STR); + device_name.append(" ").append(StringUtils::wstring_to_string(name_string)); current_mode = EK_MODE_STATIC; current_speed = EK_SPEED_NORMAL; @@ -83,7 +79,15 @@ std::string EKController::GetDeviceName() std::string EKController::GetSerial() { - return serial; + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); + + if(ret != 0) + { + return(""); + } + + return(StringUtils::wstring_to_string(serial_string)); } std::string EKController::GetLocation() diff --git a/Controllers/EKController/EKController.h b/Controllers/EKController/EKController.h index bbce8c18..2bb2955f 100644 --- a/Controllers/EKController/EKController.h +++ b/Controllers/EKController/EKController.h @@ -14,9 +14,10 @@ #include #include -#define EK_COLOUR_MODE_DATA_SIZE (sizeof(ek_colour_mode_data[0]) / sizeof(ek_colour_mode_data[0][0])) -#define EK_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ])) -#define EK_PACKET_LENGTH 0x3F +#define EK_COLOUR_MODE_DATA_SIZE (sizeof(ek_colour_mode_data[0]) / sizeof(ek_colour_mode_data[0][0])) +#define EK_DEVICE_NAME_SIZE (sizeof(device_name) / sizeof(device_name[ 0 ])) +#define EK_PACKET_LENGTH 0x3F +#define HID_MAX_STR 255 enum { @@ -68,7 +69,6 @@ public: private: std::string device_name; - std::string serial; std::string location; hid_device* dev;