Fix wstring to string conversion in CoolerMaster controllers

This commit is contained in:
Adam Honse
2024-07-31 01:02:34 -05:00
parent 10e6e8c91f
commit 8f7e4963de
18 changed files with 173 additions and 153 deletions

View File

@@ -12,24 +12,14 @@
#include <cstring>
#include "CMMMController.h"
#include "StringUtils.h"
CMMMController::CMMMController(hid_device* dev_handle, char *_path, uint16_t pid) : product_id(pid)
{
const int szTemp = HID_MAX_STR;
wchar_t tmpName[szTemp];
dev = dev_handle;
location = _path;
current_speed = CM_MM_SPEED_3;
hid_get_manufacturer_string(dev, tmpName, szTemp);
std::wstring wName = std::wstring(tmpName);
vendor = std::string(wName.begin(), wName.end());
hid_get_indexed_string(dev, 2, tmpName, szTemp);
wName = std::wstring(tmpName);
serial = std::string(wName.begin(), wName.end());
if(product_id == CM_MM530_PID || product_id == CM_MM531_PID)
{
command_code = CM_MM5XX_COMMAND;
@@ -125,12 +115,28 @@ void CMMMController::GetModeStatus()
std::string CMMMController::GetDeviceVendor()
{
return vendor;
wchar_t vendor_string[HID_MAX_STR];
int ret = hid_get_manufacturer_string(dev, vendor_string, HID_MAX_STR);
if(ret != 0)
{
return("");
}
return(StringUtils::wstring_to_string(vendor_string));
}
std::string CMMMController::GetSerial()
{
return serial;
wchar_t serial_string[HID_MAX_STR];
int ret = hid_get_indexed_string(dev, 2, serial_string, HID_MAX_STR);
if(ret != 0)
{
return("");
}
return(StringUtils::wstring_to_string(serial_string));
}
std::string CMMMController::GetLocation()