Move wstring to string conversion to StringUtils.cpp and update most HID get serial number functions to use it

This commit is contained in:
Adam Honse 2024-07-28 03:50:29 -05:00
parent 366fda30f5
commit b4d15b9545
159 changed files with 623 additions and 930 deletions

View file

@ -11,6 +11,7 @@
#include <string.h>
#include "KeychronKeyboardController.h"
#include "StringUtils.h"
using namespace std::chrono_literals;
@ -19,19 +20,6 @@ KeychronKeyboardController::KeychronKeyboardController(hid_device* dev_handle, c
dev = dev_handle;
version = "";
location = info.path;
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
serial_number = "";
}
else
{
std::wstring return_wstring = serial_string;
serial_number = std::string(return_wstring.begin(), return_wstring.end());
}
}
KeychronKeyboardController::~KeychronKeyboardController()
@ -46,7 +34,15 @@ std::string KeychronKeyboardController::GetDeviceLocation()
std::string KeychronKeyboardController::GetSerialString()
{
return(serial_number);
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 KeychronKeyboardController::GetFirmwareVersion()