From b4d15b95454bbe538ac48d7c21bf3c28f956e7f4 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 28 Jul 2024 03:50:29 -0500 Subject: [PATCH] Move wstring to string conversion to StringUtils.cpp and update most HID get serial number functions to use it --- .../AMDWraithPrismController.cpp | 7 ++-- .../AOCKeyboardController.cpp | 6 ++-- .../AOCMouseController/AOCMouseController.cpp | 6 ++-- .../AOCMousematController.cpp | 6 ++-- .../ASRockPolychromeUSBController.cpp | 6 ++-- .../AlienwareController.cpp | 5 ++- .../AnnePro2Controller/AnnePro2Controller.cpp | 6 ++-- .../AsusAuraCoreController.cpp | 6 ++-- .../AsusAuraCoreLaptopController.cpp | 15 +++----- .../AsusAuraHeadsetStandController.cpp | 6 ++-- .../AsusAuraKeyboardController.cpp | 6 ++-- .../AsusAuraMonitorController.cpp | 6 ++-- .../AsusAuraMouseController.cpp | 6 ++-- .../AsusAuraMouseGen1Controller.cpp | 6 ++-- .../AsusAuraMousematController.cpp | 6 ++-- .../AsusAuraTUFKeyboardController.cpp | 6 ++-- .../AsusAuraUSBController.cpp | 6 ++-- .../AsusROGAllyController.cpp | 6 ++-- .../AsusCerberusKeyboardController.cpp | 6 ++-- .../AsusSagarisKeyboardController.cpp | 6 ++-- .../AsusStrixClawController.cpp | 6 ++-- .../CherryKeyboardController.cpp | 6 ++-- .../CorsairLightingNodeController.cpp | 6 ++-- .../CorsairK55RGBPROXTController.cpp | 6 ++-- .../CorsairK65MiniController.cpp | 6 ++-- .../CorsairK95PlatinumXTController.cpp | 6 ++-- .../CorsairPeripheralController.cpp | 6 ++-- .../CorsairPeripheralV2Controller.cpp | 13 +++---- .../CorsairWirelessController.cpp | 6 ++-- .../CougarKeyboardController.cpp | 14 +++----- .../CougarRevengerSTController.cpp | 24 ++++++------- .../CougarRevengerSTController.h | 1 - .../CryorigH7QuadLumiController.cpp | 6 ++-- Controllers/DRGBController/.gitkeep | 0 Controllers/DRGBController/DRGBController.cpp | 7 ++-- .../DarkProjectKeyboardController.cpp | 29 +++++++++------- .../DasKeyboardController.cpp | 18 ++++------ .../DuckyKeyboardController.cpp | 6 ++-- .../EVisionKeyboardController.cpp | 14 ++++---- .../EVisionV2KeyboardController.cpp | 12 +++---- .../GaiZhongGaiController.cpp | 6 ++-- .../ATC800Controller.cpp | 6 ++-- .../GigabyteAorusPCCaseController.cpp | 6 ++-- .../HoltekA070Controller.cpp | 6 ++-- .../HoltekA1FAController.cpp | 6 ++-- .../HyperXAlloyElite2Controller.cpp | 6 ++-- .../HyperXAlloyEliteController.cpp | 6 ++-- .../HyperXAlloyFPSController.cpp | 6 ++-- .../HyperXAlloyOrigins60and65Controller.cpp | 6 ++-- .../HyperXAlloyOriginsController.cpp | 6 ++-- .../HyperXAlloyOriginsCoreController.cpp | 6 ++-- .../HyperXMicrophoneController.cpp | 24 ++++++------- .../HyperXMicrophoneController.h | 1 - .../HyperXPulsefireDartController.cpp | 6 ++-- .../HyperXPulsefireFPSProController.cpp | 6 ++-- .../HyperXPulsefireHasteController.cpp | 6 ++-- .../HyperXPulsefireRaidController.cpp | 25 ++++++-------- .../HyperXPulsefireRaidController.h | 1 - .../HyperXPulsefireSurgeController.cpp | 6 ++-- .../HyperXMousematController.cpp | 6 ++-- .../InstantMouseController.cpp | 24 ++++++------- .../InstantMouseController.h | 1 - .../IntelArcA770LEController.cpp | 6 ++-- .../KeychronKeyboardController.cpp | 24 ++++++------- .../KeychronKeyboardController.h | 1 - .../LGMonitorController.cpp | 24 ++++++------- .../LGMonitorController/LGMonitorController.h | 1 - .../LegoDimensionsToypadBaseController.cpp | 24 ++++++------- .../LegoDimensionsToypadBaseController.h | 1 - .../LenovoMotherboardController.cpp | 24 ++++++------- .../LenovoMotherboardController.h | 1 - .../LexipMouseController.cpp | 25 ++++++-------- .../LexipMouseController.h | 1 - .../LightSaltController.cpp | 21 ++++++------ .../LightSaltController/LightSaltController.h | 1 - .../MSI3ZoneController/MSI3ZoneController.cpp | 6 ++-- .../MSIMysticLight112Controller.cpp | 28 ++++++--------- .../MSIMysticLight112Controller.h | 2 -- .../MSIMysticLight162Controller.cpp | 28 ++++++--------- .../MSIMysticLight162Controller.h | 2 -- .../MSIMysticLight185Controller.cpp | 30 ++++++---------- .../MSIMysticLight185Controller.h | 2 -- .../MSIMysticLight64Controller.cpp | 19 +++++------ .../MSIOptixController/MSIOptixController.cpp | 25 ++++++-------- .../MSIOptixController/MSIOptixController.h | 1 - .../MSIVigorGK30Controller.cpp | 25 ++++++-------- .../MountainKeyboardController.cpp | 6 ++-- .../N5312AController/N5312AController.cpp | 26 ++++++-------- .../N5312AController/N5312AController.h | 1 - .../NZXTHue1Controller/NZXTHue1Controller.cpp | 6 ++-- .../NZXTHue2Controller/NZXTHue2Controller.cpp | 8 ++--- .../NZXTKrakenController.cpp | 6 ++-- .../NZXTMouseController.cpp | 6 ++-- .../NollieController/NollieController.cpp | 6 ++-- .../NollieController/NollieController.h | 33 ++++++++++++++++++ .../NollieController/RGBController_Nollie.h | 34 ------------------- .../NvidiaESAController.cpp | 25 ++++++-------- .../NvidiaESAController/NvidiaESAController.h | 1 - .../OKSController/OKSKeyboardController.cpp | 6 ++-- .../RedragonMouseController.cpp | 6 ++-- .../RoccatBurstController.cpp | 24 ++++++------- .../RoccatBurstController.h | 1 - .../RoccatBurstProAirController.cpp | 24 ++++++------- .../RoccatBurstProAirController.h | 1 - .../RoccatEloController.cpp | 24 ++++++------- .../RoccatEloController/RoccatEloController.h | 1 - .../RoccatHordeAimoController.cpp | 24 ++++++------- .../RoccatHordeAimoController.h | 1 - .../RoccatKoneAimoController.cpp | 15 +++++--- .../RoccatKoneAimoController.h | 1 - .../RoccatKoneProAirController.cpp | 24 ++++++------- .../RoccatKoneProAirController.h | 1 - .../RoccatKoneProController.cpp | 24 ++++++------- .../RoccatKoneProController.h | 1 - .../RoccatKoneXPController.cpp | 6 ++-- .../RoccatKovaController.cpp | 17 ++++------ .../RoccatSenseAimoController.cpp | 7 ++-- .../RoccatVulcanKeyboardController.cpp | 9 ++--- .../SRGBmodsLEDControllerV1.cpp | 6 ++-- .../SRGBmodsPicoController.cpp | 6 ++-- .../SonyDS4Controller/SonyDS4Controller.cpp | 21 ++++++------ .../SonyDS4Controller/SonyDS4Controller.h | 2 +- .../SonyDualSenseController.cpp | 7 ++-- .../SteelSeriesApex3Controller.cpp | 8 ++--- .../SteelSeriesArctis5Controller.cpp | 24 ++++++------- .../SteelSeriesArctis5Controller.h | 1 - .../SteelSeriesMouseController.cpp | 8 ++--- .../SteelSeriesOldApexController.cpp | 8 ++--- .../SteelSeriesQCKMatController.cpp | 6 ++-- .../SteelSeriesRivalController.cpp | 8 ++--- .../SteelSeriesSenseiController.cpp | 9 +++-- .../SteelSeriesSiberiaController.cpp | 8 ++--- .../TecknetController/TecknetController.cpp | 15 +++++--- .../TecknetController/TecknetController.h | 1 - .../ThermaltakePoseidonZRGBController.cpp | 6 ++-- .../ThermaltakeRiingController.cpp | 6 ++-- .../ThermaltakeRiingQuadController.cpp | 15 +++++--- .../ThermaltakeRiingQuadController.h | 1 - .../ThingMController/BlinkController.cpp | 16 +++++---- .../TrustGXT114Controller.cpp | 25 ++++++-------- .../TrustGXT114Controller.h | 1 - .../TrustGXT180Controller.cpp | 25 ++++++-------- .../TrustGXT180Controller.h | 1 - .../ValkyrieKeyboardController.cpp | 6 ++-- .../VS_XG270QG_Controller.cpp | 9 ++--- .../WinbondGamingKeyboardController.cpp | 26 ++++++-------- .../WinbondGamingKeyboardController.h | 2 +- .../WootingKeyboardController.cpp | 11 +++++- .../WootingKeyboardController.h | 1 - .../WootingOneKeyboardController.cpp | 4 --- .../WootingTwoKeyboardController.cpp | 4 --- .../WushiController/WushiL50USBController.cpp | 11 +++++- .../WushiController/WushiL50USBController.h | 1 - .../ZETEdgeAirProController.cpp | 24 ++++++------- .../ZETEdgeAirProController.h | 1 - .../ZETBladeOpticalController.cpp | 8 ++--- .../ZalmanZSyncController.cpp | 6 ++-- StringUtils.cpp | 9 +++++ StringUtils.h | 6 ++-- 159 files changed, 623 insertions(+), 930 deletions(-) delete mode 100644 Controllers/DRGBController/.gitkeep diff --git a/Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp b/Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp index 814022c3..6108fff1 100644 --- a/Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp +++ b/Controllers/AMDWraithPrismController/AMDWraithPrismController.cpp @@ -9,12 +9,11 @@ | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#include #include -#include #include #include #include "AMDWraithPrismController.h" +#include "StringUtils.h" AMDWraithPrismController::AMDWraithPrismController(hid_device* dev_handle, const char* path) { @@ -57,9 +56,7 @@ std::string AMDWraithPrismController::GetSerialString() return(""); } - std::wstring_convert, wchar_t> converter; - - return(converter.to_bytes(serial_string)); + return(StringUtils::wstring_to_string(serial_string)); } std::string AMDWraithPrismController::GetFirmwareVersionString() diff --git a/Controllers/AOCKeyboardController/AOCKeyboardController.cpp b/Controllers/AOCKeyboardController/AOCKeyboardController.cpp index ed5791d0..e35c9e39 100644 --- a/Controllers/AOCKeyboardController/AOCKeyboardController.cpp +++ b/Controllers/AOCKeyboardController/AOCKeyboardController.cpp @@ -13,6 +13,7 @@ #include #include #include "AOCKeyboardController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -42,10 +43,7 @@ std::string AOCKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void AOCKeyboardController::SetLightingConfig diff --git a/Controllers/AOCMouseController/AOCMouseController.cpp b/Controllers/AOCMouseController/AOCMouseController.cpp index d68e6386..0ffbd190 100644 --- a/Controllers/AOCMouseController/AOCMouseController.cpp +++ b/Controllers/AOCMouseController/AOCMouseController.cpp @@ -11,6 +11,7 @@ #include #include "AOCMouseController.h" +#include "StringUtils.h" AOCMouseController::AOCMouseController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string AOCMouseController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/AOCMousematController/AOCMousematController.cpp b/Controllers/AOCMousematController/AOCMousematController.cpp index 4d6d2cd2..4d8b0e1c 100644 --- a/Controllers/AOCMousematController/AOCMousematController.cpp +++ b/Controllers/AOCMousematController/AOCMousematController.cpp @@ -11,6 +11,7 @@ #include #include "AOCMousematController.h" +#include "StringUtils.h" AOCMousematController::AOCMousematController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string AOCMousematController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/ASRockPolychromeUSBController/ASRockPolychromeUSBController.cpp b/Controllers/ASRockPolychromeUSBController/ASRockPolychromeUSBController.cpp index 4c2a3621..bfe8a4f5 100755 --- a/Controllers/ASRockPolychromeUSBController/ASRockPolychromeUSBController.cpp +++ b/Controllers/ASRockPolychromeUSBController/ASRockPolychromeUSBController.cpp @@ -15,6 +15,7 @@ #include "RGBController.h" #include "ResourceManager.h" #include "SettingsManager.h" +#include "StringUtils.h" #include "ASRockPolychromeUSBController.h" #include "dmiinfo.h" @@ -80,10 +81,7 @@ std::string PolychromeUSBController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void PolychromeUSBController::SetDeviceInfo() diff --git a/Controllers/AlienwareController/AlienwareController.cpp b/Controllers/AlienwareController/AlienwareController.cpp index 08d89639..f57c6759 100644 --- a/Controllers/AlienwareController/AlienwareController.cpp +++ b/Controllers/AlienwareController/AlienwareController.cpp @@ -19,6 +19,7 @@ #include "RGBController.h" #include "AlienwareController.h" #include "LogManager.h" +#include "StringUtils.h" typedef uint32_t alienware_platform_id; @@ -87,9 +88,7 @@ AlienwareController::AlienwareController(hid_device* dev_handle, const hid_devic /*-----------------------------------------------------*\ | Get serial number | \*-----------------------------------------------------*/ - std::wstring tmp_serial_number; - tmp_serial_number = info.serial_number; - serial_number = std::string(tmp_serial_number.begin(), tmp_serial_number.end()); + serial_number = StringUtils::wstring_to_string(info.serial_number); /*-----------------------------------------------------*\ | Get zone information by checking firmware | diff --git a/Controllers/AnnePro2Controller/AnnePro2Controller.cpp b/Controllers/AnnePro2Controller/AnnePro2Controller.cpp index edf5a7c9..7c1a48b9 100644 --- a/Controllers/AnnePro2Controller/AnnePro2Controller.cpp +++ b/Controllers/AnnePro2Controller/AnnePro2Controller.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include "AnnePro2Controller.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -39,10 +40,7 @@ std::string AnnePro2Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void AnnePro2Controller::SendDirect(unsigned char frame_count, unsigned char * frame_data) diff --git a/Controllers/AsusAuraCoreController/AsusAuraCoreController/AsusAuraCoreController.cpp b/Controllers/AsusAuraCoreController/AsusAuraCoreController/AsusAuraCoreController.cpp index a16c138e..e7021974 100644 --- a/Controllers/AsusAuraCoreController/AsusAuraCoreController/AsusAuraCoreController.cpp +++ b/Controllers/AsusAuraCoreController/AsusAuraCoreController/AsusAuraCoreController.cpp @@ -11,6 +11,7 @@ #include #include "AsusAuraCoreController.h" +#include "StringUtils.h" #define AURA_CORE_MAX_MESSAGE_SIZE 64 @@ -49,10 +50,7 @@ std::string AuraCoreController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void AuraCoreController::SendBrightness diff --git a/Controllers/AsusAuraCoreController/AsusAuraCoreLaptopController/AsusAuraCoreLaptopController.cpp b/Controllers/AsusAuraCoreController/AsusAuraCoreLaptopController/AsusAuraCoreLaptopController.cpp index 07177a6b..3afc98dd 100644 --- a/Controllers/AsusAuraCoreController/AsusAuraCoreLaptopController/AsusAuraCoreLaptopController.cpp +++ b/Controllers/AsusAuraCoreController/AsusAuraCoreLaptopController/AsusAuraCoreLaptopController.cpp @@ -11,6 +11,7 @@ #include "AsusAuraCoreLaptopController.h" #include "SettingsManager.h" +#include "StringUtils.h" static uint8_t packet_map[ASUSAURACORELAPTOP_KEYCOUNT + ASUSAURACORELAPTOP_LIGHTBARCOUNT + @@ -95,21 +96,15 @@ std::string AsusAuraCoreLaptopController::GetDeviceName() std::string AsusAuraCoreLaptopController::GetSerial() { - const uint8_t sz = HID_MAX_STR; - wchar_t tmp[sz]; + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); - int ret = hid_get_serial_number_string(dev, tmp, sz); - - if (ret != 0) + if(ret != 0) { - LOG_DEBUG("[%s] Get HID Serial string failed", device_name.c_str()); return(""); } - std::wstring w_tmp = std::wstring(tmp); - std::string serial = std::string(w_tmp.begin(), w_tmp.end()); - - return serial; + return(StringUtils::wstring_to_string(serial_string)); } std::string AsusAuraCoreLaptopController::GetLocation() diff --git a/Controllers/AsusAuraUSBController/AsusAuraHeadsetStandController/AsusAuraHeadsetStandController.cpp b/Controllers/AsusAuraUSBController/AsusAuraHeadsetStandController/AsusAuraHeadsetStandController.cpp index ac56158d..f6929dc7 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraHeadsetStandController/AsusAuraHeadsetStandController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraHeadsetStandController/AsusAuraHeadsetStandController.cpp @@ -11,6 +11,7 @@ #include #include "AsusAuraHeadsetStandController.h" +#include "StringUtils.h" AuraHeadsetStandController::AuraHeadsetStandController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string AuraHeadsetStandController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string AuraHeadsetStandController::GetVersion() diff --git a/Controllers/AsusAuraUSBController/AsusAuraKeyboardController/AsusAuraKeyboardController.cpp b/Controllers/AsusAuraUSBController/AsusAuraKeyboardController/AsusAuraKeyboardController.cpp index 08d07a73..4d73222c 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraKeyboardController/AsusAuraKeyboardController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraKeyboardController/AsusAuraKeyboardController.cpp @@ -11,6 +11,7 @@ #include #include "AsusAuraKeyboardController.h" +#include "StringUtils.h" AuraKeyboardController::AuraKeyboardController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string AuraKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void AuraKeyboardController::SendDirect diff --git a/Controllers/AsusAuraUSBController/AsusAuraMonitorController/AsusAuraMonitorController.cpp b/Controllers/AsusAuraUSBController/AsusAuraMonitorController/AsusAuraMonitorController.cpp index 8d1b9418..b3020516 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraMonitorController/AsusAuraMonitorController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraMonitorController/AsusAuraMonitorController.cpp @@ -12,6 +12,7 @@ #include #include "AsusAuraMonitorController.h" #include "LogManager.h" +#include "StringUtils.h" AuraMonitorController::AuraMonitorController(hid_device* dev_handle, const char* path, uint16_t pid) { @@ -40,10 +41,7 @@ std::string AuraMonitorController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void AuraMonitorController::BeginUpdate() diff --git a/Controllers/AsusAuraUSBController/AsusAuraMouseController/AsusAuraMouseController.cpp b/Controllers/AsusAuraUSBController/AsusAuraMouseController/AsusAuraMouseController.cpp index 78d8cab1..d34a0ad1 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraMouseController/AsusAuraMouseController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraMouseController/AsusAuraMouseController.cpp @@ -11,6 +11,7 @@ #include #include "AsusAuraMouseController.h" +#include "StringUtils.h" AuraMouseController::AuraMouseController(hid_device* dev_handle, const char* path, uint16_t pid) { @@ -65,10 +66,7 @@ std::string AuraMouseController::GetSerialString() return(""); } - std::wstring serial_wstring = serial_string; - std::string return_string = CleanSerial(serial_wstring); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string AuraMouseController::GetVersion(bool wireless, int protocol) diff --git a/Controllers/AsusAuraUSBController/AsusAuraMouseGen1Controller/AsusAuraMouseGen1Controller.cpp b/Controllers/AsusAuraUSBController/AsusAuraMouseGen1Controller/AsusAuraMouseGen1Controller.cpp index 0a1fb44a..f3ca5910 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraMouseGen1Controller/AsusAuraMouseGen1Controller.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraMouseGen1Controller/AsusAuraMouseGen1Controller.cpp @@ -13,6 +13,7 @@ #include #include #include "AsusAuraMouseGen1Controller.h" +#include "StringUtils.h" AsusAuraMouseGen1Controller::AsusAuraMouseGen1Controller(hid_device* dev_handle, const char* path, uint16_t pid) { @@ -41,10 +42,7 @@ std::string AsusAuraMouseGen1Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string AsusAuraMouseGen1Controller::GetVersion() diff --git a/Controllers/AsusAuraUSBController/AsusAuraMousematController/AsusAuraMousematController.cpp b/Controllers/AsusAuraUSBController/AsusAuraMousematController/AsusAuraMousematController.cpp index 0d423ad6..a50469b9 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraMousematController/AsusAuraMousematController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraMousematController/AsusAuraMousematController.cpp @@ -11,6 +11,7 @@ #include #include "AsusAuraMousematController.h" +#include "StringUtils.h" AuraMousematController::AuraMousematController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string AuraMousematController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string AuraMousematController::GetVersion() diff --git a/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController/AsusAuraTUFKeyboardController.cpp b/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController/AsusAuraTUFKeyboardController.cpp index 8c814974..532b54d5 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController/AsusAuraTUFKeyboardController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController/AsusAuraTUFKeyboardController.cpp @@ -17,6 +17,7 @@ #include #include #include "AsusAuraTUFKeyboardController.h" +#include "StringUtils.h" AuraTUFKeyboardController::AuraTUFKeyboardController(hid_device* dev_handle, const char* path, uint16_t pid, unsigned short version) { @@ -70,10 +71,7 @@ std::string AuraTUFKeyboardController::GetSerialString() return(""); } - std::wstring serial_wstring = serial_string; - std::string return_string = clean_serial(serial_wstring); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string AuraTUFKeyboardController::GetVersion() diff --git a/Controllers/AsusAuraUSBController/AsusAuraUSBController/AsusAuraUSBController.cpp b/Controllers/AsusAuraUSBController/AsusAuraUSBController/AsusAuraUSBController.cpp index b97163e6..7509f2d7 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraUSBController/AsusAuraUSBController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraUSBController/AsusAuraUSBController.cpp @@ -12,6 +12,7 @@ #include #include "AsusAuraUSBController.h" #include "LogManager.h" +#include "StringUtils.h" AuraUSBController::AuraUSBController(hid_device* dev_handle, const char* path) { @@ -52,10 +53,7 @@ std::string AuraUSBController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } const std::vector& AuraUSBController::GetAuraDevices() const diff --git a/Controllers/AsusAuraUSBController/AsusROGAllyController/AsusROGAllyController.cpp b/Controllers/AsusAuraUSBController/AsusROGAllyController/AsusROGAllyController.cpp index 50c924e1..e44b17b7 100644 --- a/Controllers/AsusAuraUSBController/AsusROGAllyController/AsusROGAllyController.cpp +++ b/Controllers/AsusAuraUSBController/AsusROGAllyController/AsusROGAllyController.cpp @@ -11,6 +11,7 @@ #include #include "AsusROGAllyController.h" +#include "StringUtils.h" ROGAllyController::ROGAllyController(hid_device* dev_handle, const char* path) { @@ -40,10 +41,7 @@ std::string ROGAllyController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string ROGAllyController::GetVersion() diff --git a/Controllers/AsusLegacyUSBController/AsusCerberusKeyboardController/AsusCerberusKeyboardController.cpp b/Controllers/AsusLegacyUSBController/AsusCerberusKeyboardController/AsusCerberusKeyboardController.cpp index 6be64912..c13acad1 100644 --- a/Controllers/AsusLegacyUSBController/AsusCerberusKeyboardController/AsusCerberusKeyboardController.cpp +++ b/Controllers/AsusLegacyUSBController/AsusCerberusKeyboardController/AsusCerberusKeyboardController.cpp @@ -17,6 +17,7 @@ #include #include #include "AsusCerberusKeyboardController.h" +#include "StringUtils.h" #define ASUS_CERBERUS_KB_PACKET_SIZE 8 @@ -47,10 +48,7 @@ std::string AsusCerberusKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string AsusCerberusKeyboardController::GetVersion() diff --git a/Controllers/AsusLegacyUSBController/AsusSagarisKeyboardController/AsusSagarisKeyboardController.cpp b/Controllers/AsusLegacyUSBController/AsusSagarisKeyboardController/AsusSagarisKeyboardController.cpp index deabfcdb..24336fb2 100644 --- a/Controllers/AsusLegacyUSBController/AsusSagarisKeyboardController/AsusSagarisKeyboardController.cpp +++ b/Controllers/AsusLegacyUSBController/AsusSagarisKeyboardController/AsusSagarisKeyboardController.cpp @@ -16,6 +16,7 @@ #include #include "AsusSagarisKeyboardController.h" #include "LogManager.h" +#include "StringUtils.h" #define ASUS_SAGARIS_KB_PACKET_SIZE 65 @@ -51,10 +52,7 @@ std::string AsusSagarisKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } sagaris_mode AsusSagarisKeyboardController::GetMode() diff --git a/Controllers/AsusLegacyUSBController/AsusStrixClawController/AsusStrixClawController.cpp b/Controllers/AsusLegacyUSBController/AsusStrixClawController/AsusStrixClawController.cpp index 9d82cdfb..7a5a3f01 100644 --- a/Controllers/AsusLegacyUSBController/AsusStrixClawController/AsusStrixClawController.cpp +++ b/Controllers/AsusLegacyUSBController/AsusStrixClawController/AsusStrixClawController.cpp @@ -12,6 +12,7 @@ #include #include #include "AsusStrixClawController.h" +#include "StringUtils.h" StrixClawController::StrixClawController(hid_device* dev_handle, const char* path) { @@ -39,10 +40,7 @@ std::string StrixClawController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string StrixClawController::GetVersion() diff --git a/Controllers/CherryKeyboardController/CherryKeyboardController.cpp b/Controllers/CherryKeyboardController/CherryKeyboardController.cpp index ea40572b..e6125f47 100644 --- a/Controllers/CherryKeyboardController/CherryKeyboardController.cpp +++ b/Controllers/CherryKeyboardController/CherryKeyboardController.cpp @@ -11,6 +11,7 @@ #include #include "CherryKeyboardController.h" +#include "StringUtils.h" CherryKeyboardController::CherryKeyboardController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string CherryKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CherryKeyboardController::SetKeyboardColors diff --git a/Controllers/CorsairLightingNodeController/CorsairLightingNodeController.cpp b/Controllers/CorsairLightingNodeController/CorsairLightingNodeController.cpp index a91b2a03..026fb78f 100644 --- a/Controllers/CorsairLightingNodeController/CorsairLightingNodeController.cpp +++ b/Controllers/CorsairLightingNodeController/CorsairLightingNodeController.cpp @@ -15,6 +15,7 @@ #include #include "CorsairLightingNodeController.h" #include "CorsairDeviceGuard.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -78,10 +79,7 @@ std::string CorsairLightingNodeController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CorsairLightingNodeController::SetBrightness(unsigned char brightness) diff --git a/Controllers/CorsairPeripheralController/CorsairK55RGBPROXTController.cpp b/Controllers/CorsairPeripheralController/CorsairK55RGBPROXTController.cpp index 60737fc1..6a4f9d6a 100644 --- a/Controllers/CorsairPeripheralController/CorsairK55RGBPROXTController.cpp +++ b/Controllers/CorsairPeripheralController/CorsairK55RGBPROXTController.cpp @@ -9,6 +9,7 @@ #include "CorsairK55RGBPROXTController.h" #include "LogManager.h" +#include "StringUtils.h" #define COLOR_BANK_SIZE 137 #define HID_PACKET_LENGTH 65 @@ -70,10 +71,7 @@ std::string CorsairK55RGBPROXTController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CorsairK55RGBPROXTController::LightingControl() diff --git a/Controllers/CorsairPeripheralController/CorsairK65MiniController.cpp b/Controllers/CorsairPeripheralController/CorsairK65MiniController.cpp index b7dfe3f3..f7d62d74 100644 --- a/Controllers/CorsairPeripheralController/CorsairK65MiniController.cpp +++ b/Controllers/CorsairPeripheralController/CorsairK65MiniController.cpp @@ -9,6 +9,7 @@ #include "CorsairK65MiniController.h" #include "LogManager.h" +#include "StringUtils.h" CorsairK65MiniController::CorsairK65MiniController(hid_device* dev_handle, const char* path) { @@ -43,10 +44,7 @@ std::string CorsairK65MiniController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CorsairK65MiniController::LightingControl() diff --git a/Controllers/CorsairPeripheralController/CorsairK95PlatinumXTController.cpp b/Controllers/CorsairPeripheralController/CorsairK95PlatinumXTController.cpp index 4f67f85b..61d855a7 100644 --- a/Controllers/CorsairPeripheralController/CorsairK95PlatinumXTController.cpp +++ b/Controllers/CorsairPeripheralController/CorsairK95PlatinumXTController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include "CorsairK95PlatinumXTController.h" +#include "StringUtils.h" CorsairK95PlatinumXTController::CorsairK95PlatinumXTController(hid_device* dev_handle, const char* path) { @@ -49,10 +50,7 @@ std::string CorsairK95PlatinumXTController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CorsairK95PlatinumXTController::Init() diff --git a/Controllers/CorsairPeripheralController/CorsairPeripheralController.cpp b/Controllers/CorsairPeripheralController/CorsairPeripheralController.cpp index 07bcd7f0..3eebeb3e 100644 --- a/Controllers/CorsairPeripheralController/CorsairPeripheralController.cpp +++ b/Controllers/CorsairPeripheralController/CorsairPeripheralController.cpp @@ -12,6 +12,7 @@ #include #include "CorsairPeripheralController.h" #include "LogManager.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -133,10 +134,7 @@ std::string CorsairPeripheralController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CorsairPeripheralController::SetLEDs(std::vectorcolors) diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp index fb483670..2a9a0639 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include "CorsairPeripheralV2Controller.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -151,21 +152,15 @@ std::string CorsairPeripheralV2Controller::GetName() std::string CorsairPeripheralV2Controller::GetSerialString() { - const uint8_t sz = HID_MAX_STR; - wchar_t tmp[sz]; - - int ret = hid_get_serial_number_string(dev, tmp, sz); + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); if(ret != 0) { - LOG_DEBUG("[%s] Get HID Serial string failed", device_name.c_str()); return(""); } - std::wstring w_tmp = std::wstring(tmp); - std::string serial = std::string(w_tmp.begin(), w_tmp.end()); - - return serial; + return(StringUtils::wstring_to_string(serial_string)); } void CorsairPeripheralV2Controller::SetRenderMode(corsair_v2_device_mode mode) diff --git a/Controllers/CorsairWirelessController/CorsairWirelessController.cpp b/Controllers/CorsairWirelessController/CorsairWirelessController.cpp index 6feff835..ead3e09a 100644 --- a/Controllers/CorsairWirelessController/CorsairWirelessController.cpp +++ b/Controllers/CorsairWirelessController/CorsairWirelessController.cpp @@ -11,6 +11,7 @@ #include #include "CorsairWirelessController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -59,10 +60,7 @@ std::string CorsairWirelessController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CorsairWirelessController::SetLEDs(std::vectorcolors) diff --git a/Controllers/CougarController/CougarKeyboardController/CougarKeyboardController.cpp b/Controllers/CougarController/CougarKeyboardController/CougarKeyboardController.cpp index 58d5ebb0..5a4fa047 100644 --- a/Controllers/CougarController/CougarKeyboardController/CougarKeyboardController.cpp +++ b/Controllers/CougarController/CougarKeyboardController/CougarKeyboardController.cpp @@ -11,6 +11,7 @@ #include #include "CougarKeyboardController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -82,20 +83,15 @@ std::string CougarKeyboardController::GetDeviceName() std::string CougarKeyboardController::GetSerial() { - const uint8_t sz = HID_MAX_STR; - wchar_t tmp[sz]; + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); - int ret = hid_get_serial_number_string(dev, tmp, sz); - - if (ret != 0) + if(ret != 0) { return(""); } - std::wstring w_tmp = std::wstring(tmp); - std::string serial = std::string(w_tmp.begin(), w_tmp.end()); - - return serial; + return(StringUtils::wstring_to_string(serial_string)); } std::string CougarKeyboardController::GetLocation() diff --git a/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.cpp b/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.cpp index bb2046ff..ff9807f4 100644 --- a/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.cpp +++ b/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.cpp @@ -11,6 +11,7 @@ #include #include "CougarRevengerSTController.h" +#include "StringUtils.h" CougarRevengerSTController::CougarRevengerSTController(hid_device* dev_handle, const hid_device_info& info) { @@ -18,19 +19,6 @@ CougarRevengerSTController::CougarRevengerSTController(hid_device* dev_handle, c location = info.path; version = ""; - 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()); - } - ActivateMode(0, DIRECT_MODE_VALUE); ActivateMode(1, DIRECT_MODE_VALUE); ActivateMode(2, DIRECT_MODE_VALUE); @@ -48,7 +36,15 @@ std::string CougarRevengerSTController::GetDeviceLocation() std::string CougarRevengerSTController::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 CougarRevengerSTController::GetFirmwareVersion() diff --git a/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.h b/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.h index e3fea30f..51ade0d4 100644 --- a/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.h +++ b/Controllers/CougarController/CougarRevengerSTController/CougarRevengerSTController.h @@ -242,7 +242,6 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; void Apply(); diff --git a/Controllers/CryorigH7QuadLumiController/CryorigH7QuadLumiController.cpp b/Controllers/CryorigH7QuadLumiController/CryorigH7QuadLumiController.cpp index 261761e2..06abb8f1 100644 --- a/Controllers/CryorigH7QuadLumiController/CryorigH7QuadLumiController.cpp +++ b/Controllers/CryorigH7QuadLumiController/CryorigH7QuadLumiController.cpp @@ -15,6 +15,7 @@ #include #include "CryorigH7QuadLumiController.h" #include "LogManager.h" +#include "StringUtils.h" CryorigH7QuadLumiController::CryorigH7QuadLumiController(hid_device* dev_handle, const char* path) { @@ -49,10 +50,7 @@ std::string CryorigH7QuadLumiController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void CryorigH7QuadLumiController::SetChannelEffect diff --git a/Controllers/DRGBController/.gitkeep b/Controllers/DRGBController/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Controllers/DRGBController/DRGBController.cpp b/Controllers/DRGBController/DRGBController.cpp index 16d52099..fbd64f4f 100644 --- a/Controllers/DRGBController/DRGBController.cpp +++ b/Controllers/DRGBController/DRGBController.cpp @@ -11,6 +11,7 @@ #include #include "DRGBController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -30,13 +31,13 @@ std::string DRGBController::GetSerialString() { wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - return(return_string); + + return(StringUtils::wstring_to_string(serial_string)); } unsigned short DRGBController::GetDevicePID() diff --git a/Controllers/DarkProject/DarkProjectKeyboardController.cpp b/Controllers/DarkProject/DarkProjectKeyboardController.cpp index 94ee08a5..131c9612 100644 --- a/Controllers/DarkProject/DarkProjectKeyboardController.cpp +++ b/Controllers/DarkProject/DarkProjectKeyboardController.cpp @@ -9,8 +9,9 @@ | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#include "LogManager.h" #include "DarkProjectKeyboardController.h" +#include "LogManager.h" +#include "StringUtils.h" static uint8_t packet_map[88] = { @@ -57,26 +58,28 @@ DarkProjectKeyboardController::~DarkProjectKeyboardController() std::string DarkProjectKeyboardController::GetDeviceName() { - const int szTemp = HID_MAX_STR; - wchar_t tmpName[szTemp]; + wchar_t name_string[128]; + int ret = hid_get_manufacturer_string(dev, name_string, 128); - hid_get_manufacturer_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - std::string name = std::string(wName.begin(), wName.end()); + if(ret != 0) + { + return(""); + } - return name; + return(StringUtils::wstring_to_string(name_string)); } std::string DarkProjectKeyboardController::GetSerial() { - const int szTemp = HID_MAX_STR; - wchar_t tmpName[szTemp]; + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); - hid_get_serial_number_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - std::string serial = std::string(wName.begin(), wName.end()); + if(ret != 0) + { + return(""); + } - return serial; + return(StringUtils::wstring_to_string(serial_string)); } std::string DarkProjectKeyboardController::GetLocation() diff --git a/Controllers/DasKeyboardController/DasKeyboardController.cpp b/Controllers/DasKeyboardController/DasKeyboardController.cpp index 6ae6b232..929bbba4 100644 --- a/Controllers/DasKeyboardController/DasKeyboardController.cpp +++ b/Controllers/DasKeyboardController/DasKeyboardController.cpp @@ -11,6 +11,7 @@ #include #include "DasKeyboardController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -36,22 +37,15 @@ std::string DasKeyboardController::GetDeviceLocation() std::string DasKeyboardController::GetSerialString() { - wchar_t serial_string[128] = {}; - int err = hid_get_serial_number_string(dev, serial_string, 128); + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); - std::string return_string; - if(err == 0) + if(ret != 0) { - std::wstring return_wstring = serial_string; - return_string = std::string(return_wstring.begin(), return_wstring.end()); + return(""); } - if(return_string.empty()) - { - return_string = version; - } - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string DasKeyboardController::GetVersionString() diff --git a/Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp b/Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp index 188e0be2..74060b2b 100644 --- a/Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp +++ b/Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp @@ -11,6 +11,7 @@ #include #include "DuckyKeyboardController.h" +#include "StringUtils.h" DuckyKeyboardController::DuckyKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid) { @@ -41,10 +42,7 @@ std::string DuckyKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } unsigned short DuckyKeyboardController::GetUSBPID() diff --git a/Controllers/EVisionKeyboardController/EVisionKeyboardController.cpp b/Controllers/EVisionKeyboardController/EVisionKeyboardController.cpp index 66425664..db3c90b9 100644 --- a/Controllers/EVisionKeyboardController/EVisionKeyboardController.cpp +++ b/Controllers/EVisionKeyboardController/EVisionKeyboardController.cpp @@ -12,6 +12,7 @@ #include #include "EVisionKeyboardController.h" +#include "StringUtils.h" EVisionKeyboardController::EVisionKeyboardController(hid_device* dev_handle, const char* path) { @@ -39,10 +40,7 @@ std::string EVisionKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void EVisionKeyboardController::SetKeyboardColors @@ -64,7 +62,7 @@ void EVisionKeyboardController::SetKeyboardColors { packet_size = size; } - + SendKeyboardData ( &color_data[packet_offset], @@ -149,7 +147,7 @@ void EVisionKeyboardController::SendKeyboardBegin() usb_buf[0x01] = EVISION_KB_COMMAND_BEGIN; usb_buf[0x02] = 0x00; usb_buf[0x03] = EVISION_KB_COMMAND_BEGIN; - + /*-----------------------------------------------------*\ | Send packet | \*-----------------------------------------------------*/ @@ -175,7 +173,7 @@ void EVisionKeyboardController::SendKeyboardEnd() usb_buf[0x01] = EVISION_KB_COMMAND_END; usb_buf[0x02] = 0x00; usb_buf[0x03] = EVISION_KB_COMMAND_END; - + /*-----------------------------------------------------*\ | Send packet | \*-----------------------------------------------------*/ @@ -211,7 +209,7 @@ void EVisionKeyboardController::SendKeyboardData | Copy in data bytes | \*-----------------------------------------------------*/ memcpy(&usb_buf[0x08], data, data_size); - + /*-----------------------------------------------------*\ | Compute Checksum | \*-----------------------------------------------------*/ diff --git a/Controllers/EVisionKeyboardController/EVisionV2KeyboardController.cpp b/Controllers/EVisionKeyboardController/EVisionV2KeyboardController.cpp index abd5e266..d2e98910 100644 --- a/Controllers/EVisionKeyboardController/EVisionV2KeyboardController.cpp +++ b/Controllers/EVisionKeyboardController/EVisionV2KeyboardController.cpp @@ -12,6 +12,7 @@ #include #include "LogManager.h" #include "EVisionV2KeyboardController.h" +#include "StringUtils.h" #define BLANK_SPACE 6 #define query_check_buffer(c) \ @@ -102,20 +103,15 @@ std::string EVisionV2KeyboardController::GetDeviceName() std::string EVisionV2KeyboardController::GetSerial() { - const uint8_t sz = HID_MAX_STR; - wchar_t tmp[sz]; - - int ret = hid_get_serial_number_string(dev, tmp, sz); + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); if(ret != 0) { return(""); } - std::wstring w_tmp = std::wstring(tmp); - std::string serial = std::string(w_tmp.begin(), w_tmp.end()); - - return serial; + return(StringUtils::wstring_to_string(serial_string)); } std::string EVisionV2KeyboardController::GetLocation() diff --git a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp index 09e9f14c..2148d405 100644 --- a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp +++ b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp @@ -12,6 +12,7 @@ #include #include #include "GaiZhongGaiController.h" +#include "StringUtils.h" /*---------------------------------------------------------------*\ | https://oshwlab.com/yangdsada/GaiZhongGai-Keyboard-68-4PRO | @@ -172,10 +173,7 @@ std::string GaiZhongGaiKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string GaiZhongGaiKeyboardController::GetVersion() diff --git a/Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.cpp b/Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.cpp index 60407a4e..2d97b53c 100644 --- a/Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.cpp +++ b/Controllers/GigabyteAorusCPUCoolerController/ATC800Controller.cpp @@ -11,6 +11,7 @@ #include #include "ATC800Controller.h" +#include "StringUtils.h" ATC800Controller::ATC800Controller(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string ATC800Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void ATC800Controller::DisableTempRPMIndicator() diff --git a/Controllers/GigabyteAorusPCCaseController/GigabyteAorusPCCaseController.cpp b/Controllers/GigabyteAorusPCCaseController/GigabyteAorusPCCaseController.cpp index 40919e07..3cfd7305 100644 --- a/Controllers/GigabyteAorusPCCaseController/GigabyteAorusPCCaseController.cpp +++ b/Controllers/GigabyteAorusPCCaseController/GigabyteAorusPCCaseController.cpp @@ -11,6 +11,7 @@ #include #include "GigabyteAorusPCCaseController.h" +#include "StringUtils.h" GigabyteAorusPCCaseController::GigabyteAorusPCCaseController(hid_device *dev_handle, const char *path) { @@ -38,10 +39,7 @@ std::string GigabyteAorusPCCaseController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void GigabyteAorusPCCaseController::SendColor(uint8_t red, uint8_t green, uint8_t blue) diff --git a/Controllers/HoltekController/HoltekA070Controller/HoltekA070Controller.cpp b/Controllers/HoltekController/HoltekA070Controller/HoltekA070Controller.cpp index 620c02dd..d96173c5 100644 --- a/Controllers/HoltekController/HoltekA070Controller/HoltekA070Controller.cpp +++ b/Controllers/HoltekController/HoltekA070Controller/HoltekA070Controller.cpp @@ -11,6 +11,7 @@ #include #include "HoltekA070Controller.h" +#include "StringUtils.h" HoltekA070Controller::HoltekA070Controller(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string HoltekA070Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/HoltekController/HoltekA1FAController/HoltekA1FAController.cpp b/Controllers/HoltekController/HoltekA1FAController/HoltekA1FAController.cpp index 093d3c96..d692f4df 100644 --- a/Controllers/HoltekController/HoltekA1FAController/HoltekA1FAController.cpp +++ b/Controllers/HoltekController/HoltekA1FAController/HoltekA1FAController.cpp @@ -11,6 +11,7 @@ #include #include "HoltekA1FAController.h" +#include "StringUtils.h" HoltekA1FAController::HoltekA1FAController(hid_device *dev_handle, const char *path) { @@ -38,10 +39,7 @@ std::string HoltekA1FAController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return (return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyElite2Controller/HyperXAlloyElite2Controller.cpp b/Controllers/HyperXKeyboardController/HyperXAlloyElite2Controller/HyperXAlloyElite2Controller.cpp index 50915dd7..b32eccb5 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyElite2Controller/HyperXAlloyElite2Controller.cpp +++ b/Controllers/HyperXKeyboardController/HyperXAlloyElite2Controller/HyperXAlloyElite2Controller.cpp @@ -11,6 +11,7 @@ #include #include "HyperXAlloyElite2Controller.h" +#include "StringUtils.h" /*-----------------------------------------*\ | Skip these indices in the color output | @@ -43,10 +44,7 @@ std::string HyperXAlloyElite2Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void HyperXAlloyElite2Controller::SetLEDsDirect(const std::vector& colors) diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyEliteController/HyperXAlloyEliteController.cpp b/Controllers/HyperXKeyboardController/HyperXAlloyEliteController/HyperXAlloyEliteController.cpp index 1f309994..a802b2d1 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyEliteController/HyperXAlloyEliteController.cpp +++ b/Controllers/HyperXKeyboardController/HyperXAlloyEliteController/HyperXAlloyEliteController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXAlloyEliteController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -54,10 +55,7 @@ std::string HyperXAlloyEliteController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void HyperXAlloyEliteController::SetMode diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyFPSController/HyperXAlloyFPSController.cpp b/Controllers/HyperXKeyboardController/HyperXAlloyFPSController/HyperXAlloyFPSController.cpp index d7c5f7a9..a93270af 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyFPSController/HyperXAlloyFPSController.cpp +++ b/Controllers/HyperXKeyboardController/HyperXAlloyFPSController/HyperXAlloyFPSController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXAlloyFPSController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -50,10 +51,7 @@ std::string HyperXAlloyFPSController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void HyperXAlloyFPSController::SetLEDsDirect(std::vector colors) diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyOrigins60and65Controller/HyperXAlloyOrigins60and65Controller.cpp b/Controllers/HyperXKeyboardController/HyperXAlloyOrigins60and65Controller/HyperXAlloyOrigins60and65Controller.cpp index 69c94386..1a960e59 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyOrigins60and65Controller/HyperXAlloyOrigins60and65Controller.cpp +++ b/Controllers/HyperXKeyboardController/HyperXAlloyOrigins60and65Controller/HyperXAlloyOrigins60and65Controller.cpp @@ -11,6 +11,7 @@ #include #include "HyperXAlloyOrigins60and65Controller.h" +#include "StringUtils.h" HyperXAlloyOrigins60and65Controller::HyperXAlloyOrigins60and65Controller(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string HyperXAlloyOrigins60and65Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void HyperXAlloyOrigins60and65Controller::SetLEDsDirect(std::vector colors) diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsController/HyperXAlloyOriginsController.cpp b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsController/HyperXAlloyOriginsController.cpp index 6ab2707d..ff589553 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsController/HyperXAlloyOriginsController.cpp +++ b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsController/HyperXAlloyOriginsController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXAlloyOriginsController.h" +#include "StringUtils.h" // Skip these indices in the color output static unsigned int skip_idx[] = { 23, 29, 41, 47, 59, 70, 71, 87, 88, 93, 99, 100, 102, 108, 113, 114, 120, 123, 124 }; @@ -41,10 +42,7 @@ std::string HyperXAlloyOriginsController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void HyperXAlloyOriginsController::SetLEDsDirect(std::vector colors) diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController/HyperXAlloyOriginsCoreController.cpp b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController/HyperXAlloyOriginsCoreController.cpp index 8c8e8fa8..6ab625ec 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController/HyperXAlloyOriginsCoreController.cpp +++ b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController/HyperXAlloyOriginsCoreController.cpp @@ -12,6 +12,7 @@ #include #include "HyperXAlloyOriginsCoreController.h" +#include "StringUtils.h" // Skip these indices in the color output static unsigned int skip_idx[] = {6, 7, 14, 15, 22, 23, 30, 31, 38, 39, 44, 46, 47, 54, 55, 58, 60, 61, 62, 63, 70, 71, 78, 79, 86, 87, 94, 95, 101, 102, 103, 109, 110, 111, 118, 119}; @@ -53,10 +54,7 @@ std::string HyperXAlloyOriginsCoreController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string HyperXAlloyOriginsCoreController::GetFirmwareVersion() diff --git a/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.cpp b/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.cpp index 3035edb0..c6c676be 100644 --- a/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.cpp +++ b/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXMicrophoneController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -19,19 +20,6 @@ HyperXMicrophoneController::HyperXMicrophoneController(hidapi_wrapper hid_wrappe wrapper = hid_wrapper; dev = dev_handle; location = path; - - wchar_t serial_string[128]; - int ret = wrapper.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()); - } } HyperXMicrophoneController::~HyperXMicrophoneController() @@ -53,7 +41,15 @@ std::string HyperXMicrophoneController::GetDeviceLocation() std::string HyperXMicrophoneController::GetSerialString() { - return serial_number; + wchar_t serial_string[128]; + int ret = wrapper.hid_get_serial_number_string(dev, serial_string, 128); + + if(ret != 0) + { + return(""); + } + + return(StringUtils::wstring_to_string(serial_string)); } void HyperXMicrophoneController::SaveColors(std::vector colors, unsigned int num_frames) diff --git a/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.h b/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.h index 127c11b2..5e02b59f 100644 --- a/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.h +++ b/Controllers/HyperXMicrophoneController/HyperXMicrophoneController.h @@ -34,7 +34,6 @@ private: hidapi_wrapper wrapper; hid_device* dev; std::string location; - std::string serial_number; std::mutex lock; void SendEOT(uint8_t frame_count); diff --git a/Controllers/HyperXMouseController/HyperXPulsefireDartController/HyperXPulsefireDartController.cpp b/Controllers/HyperXMouseController/HyperXPulsefireDartController/HyperXPulsefireDartController.cpp index ca3c13c0..9b7472d2 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireDartController/HyperXPulsefireDartController.cpp +++ b/Controllers/HyperXMouseController/HyperXPulsefireDartController/HyperXPulsefireDartController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXPulsefireDartController.h" +#include "StringUtils.h" HyperXPulsefireDartController::HyperXPulsefireDartController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string HyperXPulsefireDartController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/HyperXMouseController/HyperXPulsefireFPSProController/HyperXPulsefireFPSProController.cpp b/Controllers/HyperXMouseController/HyperXPulsefireFPSProController/HyperXPulsefireFPSProController.cpp index b2d66e42..3908ade5 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireFPSProController/HyperXPulsefireFPSProController.cpp +++ b/Controllers/HyperXMouseController/HyperXPulsefireFPSProController/HyperXPulsefireFPSProController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXPulsefireFPSProController.h" +#include "StringUtils.h" HyperXPulsefireFPSProController::HyperXPulsefireFPSProController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string HyperXPulsefireFPSProController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/HyperXMouseController/HyperXPulsefireHasteController/HyperXPulsefireHasteController.cpp b/Controllers/HyperXMouseController/HyperXPulsefireHasteController/HyperXPulsefireHasteController.cpp index 65965fee..152877a7 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireHasteController/HyperXPulsefireHasteController.cpp +++ b/Controllers/HyperXMouseController/HyperXPulsefireHasteController/HyperXPulsefireHasteController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXPulsefireHasteController.h" +#include "StringUtils.h" HyperXPulsefireHasteController::HyperXPulsefireHasteController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string HyperXPulsefireHasteController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void HyperXPulsefireHasteController::SendDirect diff --git a/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.cpp b/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.cpp index 5c2d729f..7042da94 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.cpp +++ b/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXPulsefireRaidController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -19,20 +20,6 @@ HyperXPulsefireRaidController::HyperXPulsefireRaidController(hid_device* dev_han dev = dev_handle; location = info.path; version = ""; - - 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()); - } - } HyperXPulsefireRaidController::~HyperXPulsefireRaidController() @@ -47,7 +34,15 @@ std::string HyperXPulsefireRaidController::GetDeviceLocation() std::string HyperXPulsefireRaidController::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 HyperXPulsefireRaidController::GetFirmwareVersion() diff --git a/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.h b/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.h index 2f2b903f..156751db 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.h +++ b/Controllers/HyperXMouseController/HyperXPulsefireRaidController/HyperXPulsefireRaidController.h @@ -44,7 +44,6 @@ protected: private: std::string location; - std::string serial_number; std::string version; void Send(unsigned char* packet); diff --git a/Controllers/HyperXMouseController/HyperXPulsefireSurgeController/HyperXPulsefireSurgeController.cpp b/Controllers/HyperXMouseController/HyperXPulsefireSurgeController/HyperXPulsefireSurgeController.cpp index 7e54f7a7..2305db44 100644 --- a/Controllers/HyperXMouseController/HyperXPulsefireSurgeController/HyperXPulsefireSurgeController.cpp +++ b/Controllers/HyperXMouseController/HyperXPulsefireSurgeController/HyperXPulsefireSurgeController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXPulsefireSurgeController.h" +#include "StringUtils.h" HyperXPulsefireSurgeController::HyperXPulsefireSurgeController(hid_device* dev_handle, const char* path) { @@ -38,10 +39,7 @@ std::string HyperXPulsefireSurgeController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/HyperXMousematController/HyperXMousematController.cpp b/Controllers/HyperXMousematController/HyperXMousematController.cpp index 8c1dcc92..a627bfdd 100644 --- a/Controllers/HyperXMousematController/HyperXMousematController.cpp +++ b/Controllers/HyperXMousematController/HyperXMousematController.cpp @@ -11,6 +11,7 @@ #include #include "HyperXMousematController.h" +#include "StringUtils.h" HyperXMousematController::HyperXMousematController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path) { @@ -39,10 +40,7 @@ std::string HyperXMousematController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } /*-------------------------------------------------------------------------------------------------*\ diff --git a/Controllers/InstantMouseController/InstantMouseController.cpp b/Controllers/InstantMouseController/InstantMouseController.cpp index e714ae9b..ff9e0f9e 100644 --- a/Controllers/InstantMouseController/InstantMouseController.cpp +++ b/Controllers/InstantMouseController/InstantMouseController.cpp @@ -11,25 +11,13 @@ #include #include "InstantMouseController.h" +#include "StringUtils.h" InstantMouseController::InstantMouseController(hid_device* dev_handle, const hid_device_info& info) { dev = dev_handle; location = info.path; version = ""; - - 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()); - } } InstantMouseController::~InstantMouseController() @@ -44,7 +32,15 @@ std::string InstantMouseController::GetDeviceLocation() std::string InstantMouseController::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 InstantMouseController::GetFirmwareVersion() diff --git a/Controllers/InstantMouseController/InstantMouseController.h b/Controllers/InstantMouseController/InstantMouseController.h index bd4fa384..eaa023c5 100644 --- a/Controllers/InstantMouseController/InstantMouseController.h +++ b/Controllers/InstantMouseController/InstantMouseController.h @@ -56,6 +56,5 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/IntelArcA770LEController/IntelArcA770LEController.cpp b/Controllers/IntelArcA770LEController/IntelArcA770LEController.cpp index da763310..2d273925 100644 --- a/Controllers/IntelArcA770LEController/IntelArcA770LEController.cpp +++ b/Controllers/IntelArcA770LEController/IntelArcA770LEController.cpp @@ -14,6 +14,7 @@ #include #include #include "IntelArcA770LEController.h" +#include "StringUtils.h" IntelArcA770LEController::IntelArcA770LEController(hid_device* dev_handle, const char* path) { @@ -41,10 +42,7 @@ std::string IntelArcA770LEController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string IntelArcA770LEController::GetFirmwareVersionString() diff --git a/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp b/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp index 95eb836d..c6ed6969 100644 --- a/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp +++ b/Controllers/KeychronKeyboardController/KeychronKeyboardController.cpp @@ -11,6 +11,7 @@ #include #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() diff --git a/Controllers/KeychronKeyboardController/KeychronKeyboardController.h b/Controllers/KeychronKeyboardController/KeychronKeyboardController.h index 6ae24da2..c553a8bb 100644 --- a/Controllers/KeychronKeyboardController/KeychronKeyboardController.h +++ b/Controllers/KeychronKeyboardController/KeychronKeyboardController.h @@ -106,7 +106,6 @@ protected: private: std::string location; - std::string serial_number; std::string version; std::vector led_sequence_positions; diff --git a/Controllers/LGMonitorController/LGMonitorController.cpp b/Controllers/LGMonitorController/LGMonitorController.cpp index 608ec978..03e586c3 100644 --- a/Controllers/LGMonitorController/LGMonitorController.cpp +++ b/Controllers/LGMonitorController/LGMonitorController.cpp @@ -11,25 +11,13 @@ #include #include "LGMonitorController.h" +#include "StringUtils.h" LGMonitorController::LGMonitorController(hid_device* dev_handle, const hid_device_info& info) { dev = dev_handle; location = info.path; version = ""; - - 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()); - } } LGMonitorController::~LGMonitorController() @@ -44,7 +32,15 @@ std::string LGMonitorController::GetDeviceLocation() std::string LGMonitorController::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 LGMonitorController::GetFirmwareVersion() diff --git a/Controllers/LGMonitorController/LGMonitorController.h b/Controllers/LGMonitorController/LGMonitorController.h index 6033900a..3ac650a4 100644 --- a/Controllers/LGMonitorController/LGMonitorController.h +++ b/Controllers/LGMonitorController/LGMonitorController.h @@ -59,7 +59,6 @@ private: std::string description; std::string location; std::string version; - std::string serial_number; bool on = false; bool direct_mode_enabled = false; diff --git a/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.cpp b/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.cpp index eb725294..c6ca53b9 100644 --- a/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.cpp +++ b/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.cpp @@ -11,6 +11,7 @@ #include #include "LegoDimensionsToypadBaseController.h" +#include "StringUtils.h" LegoDimensionsToypadBaseController::LegoDimensionsToypadBaseController(hid_device* dev_handle, const hid_device_info& info) { @@ -18,19 +19,6 @@ LegoDimensionsToypadBaseController::LegoDimensionsToypadBaseController(hid_devic location = info.path; version = ""; - 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()); - } - Activate(); } @@ -46,7 +34,15 @@ std::string LegoDimensionsToypadBaseController::GetDeviceLocation() std::string LegoDimensionsToypadBaseController::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 LegoDimensionsToypadBaseController::GetFirmwareVersion() diff --git a/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.h b/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.h index ef6350ea..20c645aa 100644 --- a/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.h +++ b/Controllers/LegoDimensionsToypadBaseController/LegoDimensionsToypadBaseController.h @@ -50,7 +50,6 @@ protected: private: std::string location; - std::string serial_number; std::string version; void Activate(); diff --git a/Controllers/LenovoMotherboardController/LenovoMotherboardController.cpp b/Controllers/LenovoMotherboardController/LenovoMotherboardController.cpp index e3e1800e..88bbf4ee 100644 --- a/Controllers/LenovoMotherboardController/LenovoMotherboardController.cpp +++ b/Controllers/LenovoMotherboardController/LenovoMotherboardController.cpp @@ -11,25 +11,13 @@ #include #include "LenovoMotherboardController.h" +#include "StringUtils.h" LenovoMotherboardController::LenovoMotherboardController(hid_device* dev_handle, const hid_device_info& info) { dev = dev_handle; location = info.path; version = ""; - - 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()); - } } LenovoMotherboardController::~LenovoMotherboardController() @@ -44,7 +32,15 @@ std::string LenovoMotherboardController::GetDeviceLocation() std::string LenovoMotherboardController::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 LenovoMotherboardController::GetFirmwareVersion() diff --git a/Controllers/LenovoMotherboardController/LenovoMotherboardController.h b/Controllers/LenovoMotherboardController/LenovoMotherboardController.h index 56179ed3..b1f37a28 100644 --- a/Controllers/LenovoMotherboardController/LenovoMotherboardController.h +++ b/Controllers/LenovoMotherboardController/LenovoMotherboardController.h @@ -55,6 +55,5 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/LexipMouseController/LexipMouseController.cpp b/Controllers/LexipMouseController/LexipMouseController.cpp index 9b09fa72..64332838 100644 --- a/Controllers/LexipMouseController/LexipMouseController.cpp +++ b/Controllers/LexipMouseController/LexipMouseController.cpp @@ -11,26 +11,13 @@ #include #include "LexipMouseController.h" +#include "StringUtils.h" LexipMouseController::LexipMouseController(hid_device* dev_handle, const hid_device_info& info) { dev = dev_handle; location = info.path; version = ""; - - 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()); - } - } LexipMouseController::~LexipMouseController() @@ -45,7 +32,15 @@ std::string LexipMouseController::GetDeviceLocation() std::string LexipMouseController::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 LexipMouseController::GetFirmwareVersion() diff --git a/Controllers/LexipMouseController/LexipMouseController.h b/Controllers/LexipMouseController/LexipMouseController.h index 9722bc1a..2cdd1392 100644 --- a/Controllers/LexipMouseController/LexipMouseController.h +++ b/Controllers/LexipMouseController/LexipMouseController.h @@ -33,6 +33,5 @@ protected: private: std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/LightSaltController/LightSaltController.cpp b/Controllers/LightSaltController/LightSaltController.cpp index 7abc32fb..b12918c5 100644 --- a/Controllers/LightSaltController/LightSaltController.cpp +++ b/Controllers/LightSaltController/LightSaltController.cpp @@ -11,6 +11,7 @@ #include #include "LightSaltController.h" +#include "StringUtils.h" static const int mode_map[LIGHTSALT_MODE_MAXIMUM][6] = { @@ -41,16 +42,6 @@ LightSaltController::LightSaltController(hid_device* dev_handle, const hid_devic dev = dev_handle; device_location = info.path; - if(hid_get_serial_number_string(dev, usb_string, 128) == 0) - { - std::wstring tmp_wstring = usb_string; - serial = std::string(tmp_wstring.begin(), tmp_wstring.end()); - } - else - { - serial = ""; - } - if(hid_get_manufacturer_string(dev, usb_string, 128) == 0) { std::wstring tmp_wstring = usb_string; @@ -98,7 +89,15 @@ std::string LightSaltController::GetDeviceLocation() std::string LightSaltController::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 LightSaltController::GetManufacturer() diff --git a/Controllers/LightSaltController/LightSaltController.h b/Controllers/LightSaltController/LightSaltController.h index ec28a9fc..c9a9abdc 100644 --- a/Controllers/LightSaltController/LightSaltController.h +++ b/Controllers/LightSaltController/LightSaltController.h @@ -96,7 +96,6 @@ private: hid_device* dev; std::string device_location; - std::string serial; std::string manufacturer; std::string product; std::string device_model; diff --git a/Controllers/MSI3ZoneController/MSI3ZoneController.cpp b/Controllers/MSI3ZoneController/MSI3ZoneController.cpp index af31e40a..5e8350ae 100644 --- a/Controllers/MSI3ZoneController/MSI3ZoneController.cpp +++ b/Controllers/MSI3ZoneController/MSI3ZoneController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include "MSI3ZoneController.h" +#include "StringUtils.h" MSI3ZoneController::MSI3ZoneController(hid_device* dev_handle, const char* path) { @@ -44,10 +45,7 @@ std::string MSI3ZoneController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void MSI3ZoneController::SetLEDs(std::vector colors) diff --git a/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.cpp b/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.cpp index 87010004..f9d75bcf 100644 --- a/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.cpp +++ b/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.cpp @@ -13,6 +13,7 @@ #include #include #include "MSIMysticLight112Controller.h" +#include "StringUtils.h" #define BITSET(val, bit, pos) ((unsigned char)std::bitset<8>(val).set((pos), (bit)).to_ulong()) @@ -45,7 +46,6 @@ MSIMysticLight112Controller::MSIMysticLight112Controller location = path; ReadName(); - ReadSerial(); ReadFwVersion(); ReadSettings(); } @@ -158,7 +158,15 @@ std::string MSIMysticLight112Controller::GetDeviceLocation() std::string MSIMysticLight112Controller::GetSerial() { - return chip_id; + 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)); } bool MSIMysticLight112Controller::ReadSettings() @@ -377,22 +385,6 @@ bool MSIMysticLight112Controller::ReadFwVersion() return(ret_val > 0); } -void MSIMysticLight112Controller::ReadSerial() -{ - wchar_t serial[256]; - - /*-----------------------------------------------------*\ - | Get the serial number string from HID | - \*-----------------------------------------------------*/ - hid_get_serial_number_string(dev, serial, 256); - - /*-----------------------------------------------------*\ - | Convert wchar_t into std::wstring into std::string | - \*-----------------------------------------------------*/ - std::wstring wserial = std::wstring(serial); - chip_id = std::string(wserial.begin(), wserial.end()); -} - void MSIMysticLight112Controller::ReadName() { wchar_t tname[256]; diff --git a/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.h b/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.h index 316333b6..d11c2fe9 100644 --- a/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.h +++ b/Controllers/MSIMysticLightController/MSIMysticLight112Controller/MSIMysticLight112Controller.h @@ -90,7 +90,6 @@ public: private: bool ReadSettings(); bool ReadFwVersion(); - void ReadSerial(); void ReadName(); ZoneData* GetZoneData ( @@ -103,7 +102,6 @@ private: std::string location; std::string version_APROM; std::string version_LDROM; - std::string chip_id; FeaturePacket_112 data; FeaturePacket_112 zone_based_per_led_data; diff --git a/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.cpp b/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.cpp index 15a99345..3b860560 100644 --- a/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.cpp +++ b/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.cpp @@ -14,6 +14,7 @@ #include #include #include "MSIMysticLight162Controller.h" +#include "StringUtils.h" #define BITSET(val, bit, pos) ((unsigned char)std::bitset<8>(val).set((pos), (bit)).to_ulong()) @@ -93,7 +94,6 @@ MSIMysticLight162Controller::MSIMysticLight162Controller location = path; ReadName(); - ReadSerial(); ReadFwVersion(); ReadSettings(); } @@ -204,7 +204,15 @@ std::string MSIMysticLight162Controller::GetDeviceLocation() std::string MSIMysticLight162Controller::GetSerial() { - return chip_id; + 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)); } bool MSIMysticLight162Controller::ReadSettings() @@ -400,22 +408,6 @@ bool MSIMysticLight162Controller::ReadFwVersion() return(ret_val > 0); } -void MSIMysticLight162Controller::ReadSerial() -{ - wchar_t serial[256]; - - /*-----------------------------------------------------*\ - | Get the serial number string from HID | - \*-----------------------------------------------------*/ - hid_get_serial_number_string(dev, serial, 256); - - /*-----------------------------------------------------*\ - | Convert wchar_t into std::wstring into std::string | - \*-----------------------------------------------------*/ - std::wstring wserial = std::wstring(serial); - chip_id = std::string(wserial.begin(), wserial.end()); -} - void MSIMysticLight162Controller::ReadName() { wchar_t tname[256]; diff --git a/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.h b/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.h index 978a3932..403b192c 100644 --- a/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.h +++ b/Controllers/MSIMysticLightController/MSIMysticLight162Controller/MSIMysticLight162Controller.h @@ -78,7 +78,6 @@ public: private: bool ReadSettings(); bool ReadFwVersion(); - void ReadSerial(); void ReadName(); ZoneData* GetZoneData ( @@ -91,7 +90,6 @@ private: std::string location; std::string version_APROM; std::string version_LDROM; - std::string chip_id; FeaturePacket_162 data; size_t numof_onboard_leds; diff --git a/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.cpp b/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.cpp index 2c83ca1c..bf18d152 100644 --- a/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.cpp +++ b/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.cpp @@ -19,6 +19,7 @@ #include #include #include "MSIMysticLight185Controller.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -343,14 +344,13 @@ MSIMysticLight185Controller::MSIMysticLight185Controller location = path; ReadName(); - ReadSerial(); ReadFwVersion(); ReadSettings(); } if(pid == MSI_USB_PID_COMMON) { - std::string pidStr(chip_id.substr(0, 4)); + std::string pidStr(GetSerial().substr(0, 4)); pid = std::stoi(pidStr, nullptr, 16); } @@ -622,7 +622,15 @@ std::string MSIMysticLight185Controller::GetDeviceLocation() std::string MSIMysticLight185Controller::GetSerial() { - return chip_id; + 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)); } bool MSIMysticLight185Controller::ReadSettings() @@ -1034,22 +1042,6 @@ bool MSIMysticLight185Controller::ReadFwVersion() return (ret_val > 0); } -void MSIMysticLight185Controller::ReadSerial() -{ - wchar_t serial[256]; - - /*-----------------------------------------------------*\ - | Get the serial number string from HID | - \*-----------------------------------------------------*/ - hid_get_serial_number_string(dev, serial, 256); - - /*-----------------------------------------------------*\ - | Convert wchar_t into std::wstring into std::string | - \*-----------------------------------------------------*/ - std::wstring wserial = std::wstring(serial); - chip_id = std::string(wserial.begin(), wserial.end()); -} - void MSIMysticLight185Controller::ReadName() { wchar_t tname[256]; diff --git a/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.h b/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.h index 3396fd4c..90434d6e 100644 --- a/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.h +++ b/Controllers/MSIMysticLightController/MSIMysticLight185Controller/MSIMysticLight185Controller.h @@ -115,7 +115,6 @@ public: private: bool ReadSettings(); bool ReadFwVersion(); - void ReadSerial(); void ReadName(); ZoneData* GetZoneData ( @@ -134,7 +133,6 @@ private: std::string location; std::string version_APROM; std::string version_LDROM; - std::string chip_id; FeaturePacket_185 data; FeaturePacket_PerLED_185 per_led_data_onboard_and_sync; diff --git a/Controllers/MSIMysticLightController/MSIMysticLight64Controller/MSIMysticLight64Controller.cpp b/Controllers/MSIMysticLightController/MSIMysticLight64Controller/MSIMysticLight64Controller.cpp index 1a790890..c62b8887 100644 --- a/Controllers/MSIMysticLightController/MSIMysticLight64Controller/MSIMysticLight64Controller.cpp +++ b/Controllers/MSIMysticLightController/MSIMysticLight64Controller/MSIMysticLight64Controller.cpp @@ -15,6 +15,7 @@ #include #include #include "MSIMysticLight64Controller.h" +#include "StringUtils.h" MSIMysticLight64Controller::MSIMysticLight64Controller ( @@ -103,17 +104,13 @@ std::string MSIMysticLight64Controller::GetDeviceLocation() std::string MSIMysticLight64Controller::GetSerial() { - wchar_t serial[256]; + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); - /*-----------------------------------------------------*\ - | Get the serial number string from HID | - \*-----------------------------------------------------*/ - hid_get_serial_number_string(dev, serial, 256); + if(ret != 0) + { + return(""); + } - /*-----------------------------------------------------*\ - | Convert wchar_t into std::wstring into std::string | - \*-----------------------------------------------------*/ - std::wstring wserial = std::wstring(serial); - - return (std::string(wserial.begin(), wserial.end())); + return(StringUtils::wstring_to_string(serial_string)); } diff --git a/Controllers/MSIOptixController/MSIOptixController.cpp b/Controllers/MSIOptixController/MSIOptixController.cpp index 8898c11f..4eb24e80 100644 --- a/Controllers/MSIOptixController/MSIOptixController.cpp +++ b/Controllers/MSIOptixController/MSIOptixController.cpp @@ -11,26 +11,13 @@ #include #include "MSIOptixController.h" +#include "StringUtils.h" MSIOptixController::MSIOptixController(hid_device* dev_handle, const hid_device_info& info) { dev = dev_handle; location = info.path; version = ""; - - 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()); - } - } MSIOptixController::~MSIOptixController() @@ -45,7 +32,15 @@ std::string MSIOptixController::GetDeviceLocation() std::string MSIOptixController::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 MSIOptixController::GetFirmwareVersion() diff --git a/Controllers/MSIOptixController/MSIOptixController.h b/Controllers/MSIOptixController/MSIOptixController.h index 63dc4b6d..48d747e5 100644 --- a/Controllers/MSIOptixController/MSIOptixController.h +++ b/Controllers/MSIOptixController/MSIOptixController.h @@ -82,7 +82,6 @@ protected: private: std::string location; - std::string serial_number; std::string version; unsigned char GetMysteriousFlag(unsigned char mode_value); diff --git a/Controllers/MSIVigorController/MSIVigorGK30Controller.cpp b/Controllers/MSIVigorController/MSIVigorGK30Controller.cpp index 00b0ed0a..5823b0e8 100644 --- a/Controllers/MSIVigorController/MSIVigorGK30Controller.cpp +++ b/Controllers/MSIVigorController/MSIVigorGK30Controller.cpp @@ -12,6 +12,7 @@ #include #include #include "MSIVigorGK30Controller.h" +#include "StringUtils.h" static unsigned char argb_colour_index_data[2][2][2] = { //B0 B1 @@ -26,20 +27,6 @@ MSIVigorGK30Controller::MSIVigorGK30Controller(hid_device* dev_handle, const hid dev = dev_handle; location = info.path; version = ""; - - 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()); - } - } MSIVigorGK30Controller::~MSIVigorGK30Controller() @@ -54,7 +41,15 @@ std::string MSIVigorGK30Controller::GetDeviceLocation() std::string MSIVigorGK30Controller::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 MSIVigorGK30Controller::GetFirmwareVersion() diff --git a/Controllers/MountainKeyboardController/MountainKeyboardController.cpp b/Controllers/MountainKeyboardController/MountainKeyboardController.cpp index 713a4e8a..688230f2 100644 --- a/Controllers/MountainKeyboardController/MountainKeyboardController.cpp +++ b/Controllers/MountainKeyboardController/MountainKeyboardController.cpp @@ -13,6 +13,7 @@ #include #include #include "MountainKeyboardController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -42,10 +43,7 @@ std::string MountainKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void MountainKeyboardController::SelectMode(unsigned char mode_idx) diff --git a/Controllers/N5312AController/N5312AController.cpp b/Controllers/N5312AController/N5312AController.cpp index 90e43c92..f810f15b 100644 --- a/Controllers/N5312AController/N5312AController.cpp +++ b/Controllers/N5312AController/N5312AController.cpp @@ -10,8 +10,9 @@ \*---------------------------------------------------------*/ #include -#include "N5312AController.h" #include "LogManager.h" +#include "N5312AController.h" +#include "StringUtils.h" N5312AController::N5312AController(hid_device* dev_handle, const hid_device_info& info) { @@ -19,19 +20,6 @@ N5312AController::N5312AController(hid_device* dev_handle, const hid_device_info location = info.path; version = ""; - 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()); - } - SendInit(); } @@ -47,7 +35,15 @@ std::string N5312AController::GetDeviceLocation() std::string N5312AController::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 N5312AController::GetFirmwareVersion() diff --git a/Controllers/N5312AController/N5312AController.h b/Controllers/N5312AController/N5312AController.h index 232a7aeb..55229da7 100644 --- a/Controllers/N5312AController/N5312AController.h +++ b/Controllers/N5312AController/N5312AController.h @@ -55,7 +55,6 @@ private: hid_device* dev; std::string location; - std::string serial_number; std::string version; void SendInit(); diff --git a/Controllers/NZXTHue1Controller/NZXTHue1Controller.cpp b/Controllers/NZXTHue1Controller/NZXTHue1Controller.cpp index 0bf98972..3ba4125b 100644 --- a/Controllers/NZXTHue1Controller/NZXTHue1Controller.cpp +++ b/Controllers/NZXTHue1Controller/NZXTHue1Controller.cpp @@ -11,6 +11,7 @@ #include #include "NZXTHue1Controller.h" +#include "StringUtils.h" NZXTHue1Controller::NZXTHue1Controller(hid_device* dev_handle, unsigned int /*fan_channels*/, const char* path) { @@ -45,10 +46,7 @@ std::string NZXTHue1Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } unsigned int NZXTHue1Controller::GetAccessoryType() diff --git a/Controllers/NZXTHue2Controller/NZXTHue2Controller.cpp b/Controllers/NZXTHue2Controller/NZXTHue2Controller.cpp index 0c67ed75..f59bf1ec 100644 --- a/Controllers/NZXTHue2Controller/NZXTHue2Controller.cpp +++ b/Controllers/NZXTHue2Controller/NZXTHue2Controller.cpp @@ -13,8 +13,9 @@ #include #include #include -#include "NZXTHue2Controller.h" #include "LogManager.h" +#include "NZXTHue2Controller.h" +#include "StringUtils.h" NZXTHue2Controller::NZXTHue2Controller(hid_device* dev_handle, unsigned int rgb_channels, unsigned int fan_channels, const char* path) { @@ -83,10 +84,7 @@ std::string NZXTHue2Controller::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void NZXTHue2Controller::SendFan diff --git a/Controllers/NZXTKrakenController/NZXTKrakenController.cpp b/Controllers/NZXTKrakenController/NZXTKrakenController.cpp index 04785995..3acec09f 100644 --- a/Controllers/NZXTKrakenController/NZXTKrakenController.cpp +++ b/Controllers/NZXTKrakenController/NZXTKrakenController.cpp @@ -13,6 +13,7 @@ #include #include #include "NZXTKrakenController.h" +#include "StringUtils.h" static void SetColor(const std::vector& colors, unsigned char* color_data) { @@ -67,10 +68,7 @@ std::string NZXTKrakenController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void NZXTKrakenController::UpdateStatus() diff --git a/Controllers/NZXTMouseController/NZXTMouseController.cpp b/Controllers/NZXTMouseController/NZXTMouseController.cpp index e21543d3..6bffc8ca 100644 --- a/Controllers/NZXTMouseController/NZXTMouseController.cpp +++ b/Controllers/NZXTMouseController/NZXTMouseController.cpp @@ -11,6 +11,7 @@ #include #include "NZXTMouseController.h" +#include "StringUtils.h" NZXTMouseController::NZXTMouseController(hid_device* dev_handle, const char* path) { @@ -48,10 +49,7 @@ std::string NZXTMouseController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void NZXTMouseController::SetLEDs diff --git a/Controllers/NollieController/NollieController.cpp b/Controllers/NollieController/NollieController.cpp index 1849edea..56628839 100644 --- a/Controllers/NollieController/NollieController.cpp +++ b/Controllers/NollieController/NollieController.cpp @@ -11,7 +11,7 @@ #include #include "NollieController.h" -#include "RGBController_Nollie.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -37,9 +37,7 @@ std::string NollieController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } unsigned short NollieController::GetUSBPID() diff --git a/Controllers/NollieController/NollieController.h b/Controllers/NollieController/NollieController.h index 72d0dcde..df7e12ce 100644 --- a/Controllers/NollieController/NollieController.h +++ b/Controllers/NollieController/NollieController.h @@ -16,6 +16,39 @@ #include #include "RGBController.h" +#define NOLLIE_12_CH_LED_NUM 42 +#define NOLLIE_8_CH_LED_NUM 126 +#define NOLLIE_1_CH_LED_NUM 630 +#define NOLLIE_HS_CH_LED_NUM 256 +#define NOLLIE_FS_CH_LED_NUM 525 + +#define NOLLIE32_CHANNELS_NUM 32 +#define NOLLIE32_PID 0x4714 +#define NOLLIE32_VID 0x3061 + +#define NOLLIE16_CHANNELS_NUM 16 +#define NOLLIE16_PID 0x4716 +#define NOLLIE16_VID 0x3061 + +#define NOLLIE8_CHANNELS_NUM 8 +#define NOLLIE8_PID 0x1F01 +#define NOLLIE8_VID 0x16D2 + +#define NOLLIE1_CHANNELS_NUM 1 +#define NOLLIE1_PID 0x1F11 +#define NOLLIE1_VID 0x16D2 + +#define NOLLIE28_12_CHANNELS_NUM 12 +#define NOLLIE28_12_VID 0x16D2 +#define NOLLIE28_12_PID 0x1616 +#define NOLLIE28_L1_PID 0x1617 +#define NOLLIE28_L2_PID 0x1618 + +#define NOLLIE32_MOS_TRIGGER_CH 26 +#define NOLLIE32_MOS_TRIGGER_LED 20 +#define NOLLIE32_FLAG1_CHANNEL 15 +#define NOLLIE32_FLAG2_CHANNEL 31 + class NollieController { public: diff --git a/Controllers/NollieController/RGBController_Nollie.h b/Controllers/NollieController/RGBController_Nollie.h index c2db915b..31a0478c 100644 --- a/Controllers/NollieController/RGBController_Nollie.h +++ b/Controllers/NollieController/RGBController_Nollie.h @@ -14,40 +14,6 @@ #include "RGBController.h" #include "NollieController.h" -#define NOLLIE_12_CH_LED_NUM 42 -#define NOLLIE_8_CH_LED_NUM 126 -#define NOLLIE_1_CH_LED_NUM 630 -#define NOLLIE_HS_CH_LED_NUM 256 -#define NOLLIE_FS_CH_LED_NUM 525 - -#define NOLLIE32_CHANNELS_NUM 32 -#define NOLLIE32_PID 0x4714 -#define NOLLIE32_VID 0x3061 - -#define NOLLIE16_CHANNELS_NUM 16 -#define NOLLIE16_PID 0x4716 -#define NOLLIE16_VID 0x3061 - -#define NOLLIE8_CHANNELS_NUM 8 -#define NOLLIE8_PID 0x1F01 -#define NOLLIE8_VID 0x16D2 - -#define NOLLIE1_CHANNELS_NUM 1 -#define NOLLIE1_PID 0x1F11 -#define NOLLIE1_VID 0x16D2 - -#define NOLLIE28_12_CHANNELS_NUM 12 -#define NOLLIE28_12_VID 0x16D2 -#define NOLLIE28_12_PID 0x1616 -#define NOLLIE28_L1_PID 0x1617 -#define NOLLIE28_L2_PID 0x1618 - -#define NOLLIE32_MOS_TRIGGER_CH 26 -#define NOLLIE32_MOS_TRIGGER_LED 20 -#define NOLLIE32_FLAG1_CHANNEL 15 -#define NOLLIE32_FLAG2_CHANNEL 31 - - class RGBController_Nollie : public RGBController { public: diff --git a/Controllers/NvidiaESAController/NvidiaESAController.cpp b/Controllers/NvidiaESAController/NvidiaESAController.cpp index f7b115b5..42bfd63d 100644 --- a/Controllers/NvidiaESAController/NvidiaESAController.cpp +++ b/Controllers/NvidiaESAController/NvidiaESAController.cpp @@ -11,26 +11,13 @@ #include #include "NvidiaESAController.h" +#include "StringUtils.h" NvidiaESAController::NvidiaESAController(hid_device* dev_handle, const hid_device_info& info) { dev = dev_handle; location = info.path; version = ""; - - 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()); - } - } NvidiaESAController::~NvidiaESAController() @@ -45,7 +32,15 @@ std::string NvidiaESAController::GetDeviceLocation() std::string NvidiaESAController::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 NvidiaESAController::GetFirmwareVersion() diff --git a/Controllers/NvidiaESAController/NvidiaESAController.h b/Controllers/NvidiaESAController/NvidiaESAController.h index d1991f66..a684fa0d 100644 --- a/Controllers/NvidiaESAController/NvidiaESAController.h +++ b/Controllers/NvidiaESAController/NvidiaESAController.h @@ -32,6 +32,5 @@ protected: private: std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/OKSController/OKSKeyboardController.cpp b/Controllers/OKSController/OKSKeyboardController.cpp index f52d0370..0af54e3c 100644 --- a/Controllers/OKSController/OKSKeyboardController.cpp +++ b/Controllers/OKSController/OKSKeyboardController.cpp @@ -11,6 +11,7 @@ #include #include "OKSKeyboardController.h" +#include "StringUtils.h" OKSKeyboardController::OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid) { @@ -41,10 +42,7 @@ std::string OKSKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } unsigned short OKSKeyboardController::GetUSBPID() diff --git a/Controllers/RedragonController/RedragonMouseController.cpp b/Controllers/RedragonController/RedragonMouseController.cpp index 251a2202..95e1104a 100644 --- a/Controllers/RedragonController/RedragonMouseController.cpp +++ b/Controllers/RedragonController/RedragonMouseController.cpp @@ -11,6 +11,7 @@ #include #include "RedragonMouseController.h" +#include "StringUtils.h" RedragonMouseController::RedragonMouseController(hid_device* dev_handle, const char* path) { @@ -43,10 +44,7 @@ std::string RedragonMouseController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void RedragonMouseController::SendMouseColor diff --git a/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.cpp b/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.cpp index 40812887..a7543435 100644 --- a/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.cpp +++ b/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.cpp @@ -11,6 +11,7 @@ #include #include "RoccatBurstController.h" +#include "StringUtils.h" RoccatBurstController::RoccatBurstController(hid_device* dev_handle, const hid_device_info& info) { @@ -18,19 +19,6 @@ RoccatBurstController::RoccatBurstController(hid_device* dev_handle, const hid_d 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()); - } - SetupDirectMode(); } @@ -46,7 +34,15 @@ std::string RoccatBurstController::GetFirmwareVersion() std::string RoccatBurstController::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 RoccatBurstController::GetDeviceLocation() diff --git a/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.h b/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.h index bf2fe09f..c594f83b 100644 --- a/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.h +++ b/Controllers/RoccatController/RoccatBurstController/RoccatBurstController.h @@ -63,7 +63,6 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; unsigned int CalculateCRC(unsigned char* bytes); diff --git a/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.cpp b/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.cpp index cc09a24e..364469ca 100644 --- a/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.cpp +++ b/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.cpp @@ -11,25 +11,13 @@ #include #include "RoccatBurstProAirController.h" +#include "StringUtils.h" RoccatBurstProAirController::RoccatBurstProAirController(hid_device* dev_handle, const hid_device_info& info) { 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()); - } } RoccatBurstProAirController::~RoccatBurstProAirController() @@ -44,7 +32,15 @@ std::string RoccatBurstProAirController::GetFirmwareVersion() std::string RoccatBurstProAirController::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 RoccatBurstProAirController::GetDeviceLocation() diff --git a/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.h b/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.h index 22ec62fe..8dea220a 100644 --- a/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.h +++ b/Controllers/RoccatController/RoccatBurstProAirController/RoccatBurstProAirController.h @@ -50,6 +50,5 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/RoccatController/RoccatEloController/RoccatEloController.cpp b/Controllers/RoccatController/RoccatEloController/RoccatEloController.cpp index f46ceccb..6442349c 100644 --- a/Controllers/RoccatController/RoccatEloController/RoccatEloController.cpp +++ b/Controllers/RoccatController/RoccatEloController/RoccatEloController.cpp @@ -12,6 +12,7 @@ #include #include #include "RoccatEloController.h" +#include "StringUtils.h" RoccatEloController::RoccatEloController(hid_device* dev_handle, const hid_device_info& info) { @@ -19,19 +20,6 @@ RoccatEloController::RoccatEloController(hid_device* dev_handle, const hid_devic location = info.path; version = ""; - 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()); - } - SendInit(); } @@ -47,7 +35,15 @@ std::string RoccatEloController::GetDeviceLocation() std::string RoccatEloController::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)); } void RoccatEloController::SendInit() diff --git a/Controllers/RoccatController/RoccatEloController/RoccatEloController.h b/Controllers/RoccatController/RoccatEloController/RoccatEloController.h index 5ad27bcc..6847925f 100644 --- a/Controllers/RoccatController/RoccatEloController/RoccatEloController.h +++ b/Controllers/RoccatController/RoccatEloController/RoccatEloController.h @@ -33,7 +33,6 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; void SendInit(); diff --git a/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.cpp b/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.cpp index 25a71369..99ac6eb1 100644 --- a/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.cpp +++ b/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.cpp @@ -11,6 +11,7 @@ #include #include "RoccatHordeAimoController.h" +#include "StringUtils.h" RoccatHordeAimoController::RoccatHordeAimoController(hid_device* dev_handle, const hid_device_info& info) { @@ -18,19 +19,6 @@ RoccatHordeAimoController::RoccatHordeAimoController(hid_device* dev_handle, con 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()); - } - InitialPacket(); } @@ -59,7 +47,15 @@ std::string RoccatHordeAimoController::GetFirmwareVersion() std::string RoccatHordeAimoController::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 RoccatHordeAimoController::GetDeviceLocation() diff --git a/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.h b/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.h index 64e8d1f4..458c8f9b 100644 --- a/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.h +++ b/Controllers/RoccatController/RoccatHordeAimoController/RoccatHordeAimoController.h @@ -34,7 +34,6 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; void InitialPacket(); diff --git a/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.cpp b/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.cpp index 59206409..c01e002c 100644 --- a/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.cpp +++ b/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.cpp @@ -11,6 +11,7 @@ #include #include "RoccatKoneAimoController.h" +#include "StringUtils.h" RoccatKoneAimoController::RoccatKoneAimoController(hid_device* dev_handle, char *_path) { @@ -28,10 +29,6 @@ RoccatKoneAimoController::RoccatKoneAimoController(hid_device* dev_handle, char 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()); - /*-----------------------------------------------------*\ | Init usb buffer to 0 and add first two bytes | \*-----------------------------------------------------*/ @@ -54,7 +51,15 @@ std::string RoccatKoneAimoController::GetDeviceName() std::string RoccatKoneAimoController::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 RoccatKoneAimoController::GetLocation() diff --git a/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.h b/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.h index 33b1279b..9e06a752 100644 --- a/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.h +++ b/Controllers/RoccatController/RoccatKoneAimoController/RoccatKoneAimoController.h @@ -50,7 +50,6 @@ public: private: std::string device_name; - std::string serial; std::string location; hid_device* dev; unsigned char usb_colors_buf[USB_COLOR_BUFF_LEN]; // USB buffer to be sent everytime we update mouse's LEDs diff --git a/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.cpp b/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.cpp index b72ee8b4..591a7413 100644 --- a/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.cpp +++ b/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.cpp @@ -11,25 +11,13 @@ #include #include "RoccatKoneProAirController.h" +#include "StringUtils.h" RoccatKoneProAirController::RoccatKoneProAirController(hid_device* dev_handle, const hid_device_info& info) { 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()); - } } RoccatKoneProAirController::~RoccatKoneProAirController() @@ -44,7 +32,15 @@ std::string RoccatKoneProAirController::GetFirmwareVersion() std::string RoccatKoneProAirController::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 RoccatKoneProAirController::GetDeviceLocation() diff --git a/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.h b/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.h index 775165f7..a911ca25 100644 --- a/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.h +++ b/Controllers/RoccatController/RoccatKoneProAirController/RoccatKoneProAirController.h @@ -56,7 +56,6 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; void SendRGB(bool direct, std::vector colors, unsigned char mode_value, unsigned char speed, unsigned char brightness); diff --git a/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.cpp b/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.cpp index 92bb4e0b..27c60673 100644 --- a/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.cpp +++ b/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.cpp @@ -11,6 +11,7 @@ #include #include "RoccatKoneProController.h" +#include "StringUtils.h" RoccatKoneProController::RoccatKoneProController(hid_device* dev_handle, const hid_device_info& info) { @@ -18,19 +19,6 @@ RoccatKoneProController::RoccatKoneProController(hid_device* dev_handle, const h 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()); - } - SetupDirectMode(); } @@ -46,7 +34,15 @@ std::string RoccatKoneProController::GetFirmwareVersion() std::string RoccatKoneProController::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 RoccatKoneProController::GetDeviceLocation() diff --git a/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.h b/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.h index 4f292735..4b25a7c2 100644 --- a/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.h +++ b/Controllers/RoccatController/RoccatKoneProController/RoccatKoneProController.h @@ -63,7 +63,6 @@ public: private: hid_device* dev; std::string location; - std::string serial_number; std::string version; unsigned int CalculateCRC(unsigned char* bytes); diff --git a/Controllers/RoccatController/RoccatKoneXPController/RoccatKoneXPController.cpp b/Controllers/RoccatController/RoccatKoneXPController/RoccatKoneXPController.cpp index e9a0c15d..b320b269 100644 --- a/Controllers/RoccatController/RoccatKoneXPController/RoccatKoneXPController.cpp +++ b/Controllers/RoccatController/RoccatKoneXPController/RoccatKoneXPController.cpp @@ -14,6 +14,7 @@ #include #include "LogManager.h" #include "RoccatKoneXPController.h" +#include "StringUtils.h" RoccatKoneXPController::RoccatKoneXPController(hid_device* dev_handle, char *path) { @@ -53,10 +54,7 @@ std::string RoccatKoneXPController::GetSerial() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } diff --git a/Controllers/RoccatController/RoccatKovaController/RoccatKovaController.cpp b/Controllers/RoccatController/RoccatKovaController/RoccatKovaController.cpp index 42170b5e..b3d52ba1 100644 --- a/Controllers/RoccatController/RoccatKovaController/RoccatKovaController.cpp +++ b/Controllers/RoccatController/RoccatKovaController/RoccatKovaController.cpp @@ -10,8 +10,9 @@ \*---------------------------------------------------------*/ #include -#include "RoccatKovaController.h" #include "LogManager.h" +#include "RoccatKovaController.h" +#include "StringUtils.h" RoccatKovaController::RoccatKovaController(hid_device* dev_handle, char *path) { @@ -34,21 +35,15 @@ std::string RoccatKovaController::GetLocation() std::string RoccatKovaController::GetSerial() { - const uint8_t sz = ROCCAT_KOVA_HID_MAX_STR; - wchar_t tmp[sz]; - - uint8_t ret = hid_get_serial_number_string(dev, tmp, sz); + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); if(ret != 0) { - LOG_DEBUG("[Roccat Kova] Get HID Serial string failed"); - return ""; + return(""); } - std::wstring w_tmp = std::wstring(tmp); - std::string serial = std::string(w_tmp.begin(), w_tmp.end()); - - return serial; + return(StringUtils::wstring_to_string(serial_string)); } std::string RoccatKovaController::GetFirmwareVersion() diff --git a/Controllers/RoccatController/RoccatSenseAimoController/RoccatSenseAimoController.cpp b/Controllers/RoccatController/RoccatSenseAimoController/RoccatSenseAimoController.cpp index 43118f29..58108be4 100644 --- a/Controllers/RoccatController/RoccatSenseAimoController/RoccatSenseAimoController.cpp +++ b/Controllers/RoccatController/RoccatSenseAimoController/RoccatSenseAimoController.cpp @@ -12,6 +12,7 @@ #include #include "LogManager.h" #include "RoccatSenseAimoController.h" +#include "StringUtils.h" RoccatSenseAimoController::RoccatSenseAimoController(hid_device* dev_handle, char *path) { @@ -51,11 +52,7 @@ std::string RoccatSenseAimoController::GetSerial() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); - + return(StringUtils::wstring_to_string(serial_string)); } std::string RoccatSenseAimoController::GetLocation() diff --git a/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp b/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp index 241b75d8..db039bdd 100644 --- a/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp +++ b/Controllers/RoccatController/RoccatVulcanKeyboardController/RoccatVulcanKeyboardController.cpp @@ -14,8 +14,9 @@ #include #include #include -#include "RoccatVulcanKeyboardController.h" #include "LogManager.h" +#include "RoccatVulcanKeyboardController.h" +#include "StringUtils.h" RoccatVulcanKeyboardController::RoccatVulcanKeyboardController(hid_device* dev_ctrl_handle, hid_device* dev_led_handle, char *path, uint16_t pid) { @@ -41,11 +42,7 @@ std::string RoccatVulcanKeyboardController::GetSerial() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); - + return(StringUtils::wstring_to_string(serial_string)); } std::string RoccatVulcanKeyboardController::GetLocation() diff --git a/Controllers/SRGBmodsController/SRGBmodsLEDControllerV1/SRGBmodsLEDControllerV1.cpp b/Controllers/SRGBmodsController/SRGBmodsLEDControllerV1/SRGBmodsLEDControllerV1.cpp index 6344d930..1d4c7b6b 100644 --- a/Controllers/SRGBmodsController/SRGBmodsLEDControllerV1/SRGBmodsLEDControllerV1.cpp +++ b/Controllers/SRGBmodsController/SRGBmodsLEDControllerV1/SRGBmodsLEDControllerV1.cpp @@ -11,6 +11,7 @@ #include #include "SRGBmodsLEDControllerV1.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -40,10 +41,7 @@ std::string SRGBmodsLEDControllerV1::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void SRGBmodsLEDControllerV1::SetChannelLEDs(unsigned char /*channel*/, RGBColor* colors, unsigned int num_colors) diff --git a/Controllers/SRGBmodsController/SRGBmodsPicoController/SRGBmodsPicoController.cpp b/Controllers/SRGBmodsController/SRGBmodsPicoController/SRGBmodsPicoController.cpp index 888cd693..6b2a5aa8 100644 --- a/Controllers/SRGBmodsController/SRGBmodsPicoController/SRGBmodsPicoController.cpp +++ b/Controllers/SRGBmodsController/SRGBmodsPicoController/SRGBmodsPicoController.cpp @@ -11,6 +11,7 @@ #include #include "SRGBmodsPicoController.h" +#include "StringUtils.h" using namespace std::chrono_literals; @@ -65,10 +66,7 @@ std::string SRGBmodsPicoController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void SRGBmodsPicoController::SetChannelLEDs(unsigned char channel, RGBColor* colors, unsigned int num_colors) diff --git a/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.cpp b/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.cpp index af40d578..2668f731 100644 --- a/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.cpp +++ b/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.cpp @@ -12,18 +12,19 @@ #include #include #include "SonyDS4Controller.h" +#include "StringUtils.h" SonyDS4Controller::SonyDS4Controller(hid_device * device_handle, const char * device_path) { - this->device_handle = device_handle; + this->dev = device_handle; unsigned char readBuffer[64]; unsigned char reportBuffer[64]; reportBuffer[0] = 0x02; - hid_get_feature_report(device_handle, reportBuffer, 64); + hid_get_feature_report(dev, reportBuffer, 64); for (int i = 0; i < 5; i++) { - hid_read(device_handle, readBuffer, 64); + hid_read(dev, readBuffer, 64); if (readBuffer[0] == 17) { is_bluetooth = true; @@ -36,7 +37,7 @@ SonyDS4Controller::SonyDS4Controller(hid_device * device_handle, const char * de SonyDS4Controller::~SonyDS4Controller() { - hid_close(device_handle); + hid_close(dev); } std::string SonyDS4Controller::GetLocation() @@ -47,16 +48,14 @@ std::string SonyDS4Controller::GetLocation() std::string SonyDS4Controller::GetSerialString() { wchar_t serial_string[128]; - int ret = hid_get_serial_number_string(device_handle, serial_string, 128); + int ret = hid_get_serial_number_string(dev, serial_string, 128); + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void SonyDS4Controller::SetColors(unsigned char red, unsigned char green, unsigned char blue) @@ -103,7 +102,7 @@ void SonyDS4Controller::sendReportBT(unsigned char red, unsigned char green, uns outbuffer[76] = (0x00FF0000 & crc) >> 16; outbuffer[77] = (0xFF000000 & crc) >> 24; - hid_write(device_handle, outbuffer, 78); + hid_write(dev, outbuffer, 78); } void SonyDS4Controller::sendReportUSB(unsigned char red, unsigned char green, unsigned char blue) @@ -123,5 +122,5 @@ void SonyDS4Controller::sendReportUSB(unsigned char red, unsigned char green, un 0x00 }; - hid_write(device_handle, buffer, 11); + hid_write(dev, buffer, 11); } diff --git a/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.h b/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.h index 51d82574..6d7b389b 100644 --- a/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.h +++ b/Controllers/SonyGamepadController/SonyDS4Controller/SonyDS4Controller.h @@ -26,7 +26,7 @@ public: void SetColors(unsigned char red, unsigned char green, unsigned char blue); private: - hid_device* device_handle; + hid_device* dev; bool is_bluetooth = false; std::string location; diff --git a/Controllers/SonyGamepadController/SonyDualSenseController/SonyDualSenseController.cpp b/Controllers/SonyGamepadController/SonyDualSenseController/SonyDualSenseController.cpp index c416d43f..2cd3ebfd 100644 --- a/Controllers/SonyGamepadController/SonyDualSenseController/SonyDualSenseController.cpp +++ b/Controllers/SonyGamepadController/SonyDualSenseController/SonyDualSenseController.cpp @@ -13,6 +13,7 @@ #include #include #include "SonyDualSenseController.h" +#include "StringUtils.h" SonyDualSenseController::SonyDualSenseController(hid_device * device_handle, const char * device_path, bool is_bluetooth) { @@ -35,15 +36,13 @@ std::string SonyDualSenseController::GetSerialString() { wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void SonyDualSenseController::SetColors(std::vector colors, unsigned char brightness, unsigned char mode_value) diff --git a/Controllers/SteelSeriesController/SteelSeriesApex3Controller/SteelSeriesApex3Controller.cpp b/Controllers/SteelSeriesController/SteelSeriesApex3Controller/SteelSeriesApex3Controller.cpp index ddc604d5..1b9aecdc 100644 --- a/Controllers/SteelSeriesController/SteelSeriesApex3Controller/SteelSeriesApex3Controller.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesApex3Controller/SteelSeriesApex3Controller.cpp @@ -11,6 +11,7 @@ #include #include "SteelSeriesApex3Controller.h" +#include "StringUtils.h" SteelSeriesApex3Controller::SteelSeriesApex3Controller(hid_device* dev_handle, const char* path) { @@ -33,13 +34,10 @@ std::string SteelSeriesApex3Controller::GetSerialString() wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); - if (ret != 0) + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } diff --git a/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.cpp b/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.cpp index ccb84447..1684038d 100644 --- a/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.cpp @@ -11,25 +11,13 @@ #include #include "SteelSeriesArctis5Controller.h" +#include "StringUtils.h" SteelSeriesArctis5Controller::SteelSeriesArctis5Controller(hid_device* dev_handle, const hid_device_info& info) { dev = dev_handle; location = info.path; version = ""; - - 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()); - } } SteelSeriesArctis5Controller::~SteelSeriesArctis5Controller() @@ -44,7 +32,15 @@ std::string SteelSeriesArctis5Controller::GetDeviceLocation() std::string SteelSeriesArctis5Controller::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 SteelSeriesArctis5Controller::GetFirmwareVersion() diff --git a/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.h b/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.h index 2a32ccd5..dae3c38d 100644 --- a/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.h +++ b/Controllers/SteelSeriesController/SteelSeriesArctis5Controller/SteelSeriesArctis5Controller.h @@ -32,7 +32,6 @@ public: private: std::string location; - std::string serial_number; std::string version; hid_device* dev; diff --git a/Controllers/SteelSeriesController/SteelSeriesMouseController/SteelSeriesMouseController.cpp b/Controllers/SteelSeriesController/SteelSeriesMouseController/SteelSeriesMouseController.cpp index 73ecc0eb..165077eb 100644 --- a/Controllers/SteelSeriesController/SteelSeriesMouseController/SteelSeriesMouseController.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesMouseController/SteelSeriesMouseController.cpp @@ -11,6 +11,7 @@ #include #include "SteelSeriesMouseController.h" +#include "StringUtils.h" SteelSeriesMouseController::SteelSeriesMouseController(hid_device* dev_handle, steelseries_type proto_type, const char* path) { @@ -34,15 +35,12 @@ std::string SteelSeriesMouseController::GetSerialString() wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); - if (ret != 0) + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } steelseries_type SteelSeriesMouseController::GetMouseType() diff --git a/Controllers/SteelSeriesController/SteelSeriesOldApexController/SteelSeriesOldApexController.cpp b/Controllers/SteelSeriesController/SteelSeriesOldApexController/SteelSeriesOldApexController.cpp index 055361da..271fb171 100644 --- a/Controllers/SteelSeriesController/SteelSeriesOldApexController/SteelSeriesOldApexController.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesOldApexController/SteelSeriesOldApexController.cpp @@ -18,6 +18,7 @@ #include #include #include "SteelSeriesOldApexController.h" +#include "StringUtils.h" static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size) { @@ -66,15 +67,12 @@ std::string SteelSeriesOldApexController::GetSerialString() wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); - if (ret != 0) + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } steelseries_type SteelSeriesOldApexController::GetKeyboardType() diff --git a/Controllers/SteelSeriesController/SteelSeriesQCKMatController/SteelSeriesQCKMatController.cpp b/Controllers/SteelSeriesController/SteelSeriesQCKMatController/SteelSeriesQCKMatController.cpp index 30048156..96f0d673 100644 --- a/Controllers/SteelSeriesController/SteelSeriesQCKMatController/SteelSeriesQCKMatController.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesQCKMatController/SteelSeriesQCKMatController.cpp @@ -11,6 +11,7 @@ #include #include "SteelSeriesQCKMatController.h" +#include "StringUtils.h" SteelSeriesQCKMatController::SteelSeriesQCKMatController(hid_device* dev_handle, const char* path) { @@ -43,10 +44,7 @@ std::string SteelSeriesQCKMatController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void SteelSeriesQCKMatController::SetColors(std::vector colors) diff --git a/Controllers/SteelSeriesController/SteelSeriesRivalController/SteelSeriesRivalController.cpp b/Controllers/SteelSeriesController/SteelSeriesRivalController/SteelSeriesRivalController.cpp index eaba9538..6d802832 100644 --- a/Controllers/SteelSeriesController/SteelSeriesRivalController/SteelSeriesRivalController.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesRivalController/SteelSeriesRivalController.cpp @@ -14,6 +14,7 @@ #include #include #include "SteelSeriesRivalController.h" +#include "StringUtils.h" static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size) { @@ -62,15 +63,12 @@ std::string SteelSeriesRivalController::GetSerialString() wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); - if (ret != 0) + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string SteelSeriesRivalController::GetFirmwareVersion() diff --git a/Controllers/SteelSeriesController/SteelSeriesSenseiController/SteelSeriesSenseiController.cpp b/Controllers/SteelSeriesController/SteelSeriesSenseiController/SteelSeriesSenseiController.cpp index 6a2149c9..5bf15bc9 100644 --- a/Controllers/SteelSeriesController/SteelSeriesSenseiController/SteelSeriesSenseiController.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesSenseiController/SteelSeriesSenseiController.cpp @@ -14,6 +14,7 @@ #include #include #include "SteelSeriesSenseiController.h" +#include "StringUtils.h" static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size) { @@ -61,15 +62,13 @@ std::string SteelSeriesSenseiController::GetSerialString() { wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); - if (ret != 0) + + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } steelseries_type SteelSeriesSenseiController::GetMouseType() diff --git a/Controllers/SteelSeriesController/SteelSeriesSiberiaController/SteelSeriesSiberiaController.cpp b/Controllers/SteelSeriesController/SteelSeriesSiberiaController/SteelSeriesSiberiaController.cpp index 97a24f18..d17193d3 100644 --- a/Controllers/SteelSeriesController/SteelSeriesSiberiaController/SteelSeriesSiberiaController.cpp +++ b/Controllers/SteelSeriesController/SteelSeriesSiberiaController/SteelSeriesSiberiaController.cpp @@ -11,6 +11,7 @@ #include #include "SteelSeriesSiberiaController.h" +#include "StringUtils.h" static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size) { @@ -64,15 +65,12 @@ std::string SteelSeriesSiberiaController::GetSerialString() wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); - if (ret != 0) + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void SteelSeriesSiberiaController::SetColor diff --git a/Controllers/TecknetController/TecknetController.cpp b/Controllers/TecknetController/TecknetController.cpp index 207e6790..357ccced 100644 --- a/Controllers/TecknetController/TecknetController.cpp +++ b/Controllers/TecknetController/TecknetController.cpp @@ -9,6 +9,7 @@ | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ +#include "StringUtils.h" #include "TecknetController.h" static unsigned char tecknet_colour_mode_data[][16] = @@ -38,10 +39,6 @@ TecknetController::TecknetController(hid_device* dev_handle, char *_path) 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; current_mode = TECKNET_MODE_DIRECT; @@ -61,7 +58,15 @@ std::string TecknetController::GetDeviceName() std::string TecknetController::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 TecknetController::GetLocation() diff --git a/Controllers/TecknetController/TecknetController.h b/Controllers/TecknetController/TecknetController.h index 7cc8d082..3b8e5b33 100644 --- a/Controllers/TecknetController/TecknetController.h +++ b/Controllers/TecknetController/TecknetController.h @@ -65,7 +65,6 @@ public: private: std::string device_name; - std::string serial; std::string location; hid_device* dev; diff --git a/Controllers/ThermaltakePoseidonZRGBController/ThermaltakePoseidonZRGBController.cpp b/Controllers/ThermaltakePoseidonZRGBController/ThermaltakePoseidonZRGBController.cpp index 29ad8d49..136f2ba9 100644 --- a/Controllers/ThermaltakePoseidonZRGBController/ThermaltakePoseidonZRGBController.cpp +++ b/Controllers/ThermaltakePoseidonZRGBController/ThermaltakePoseidonZRGBController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "ThermaltakePoseidonZRGBController.h" using namespace std::chrono_literals; @@ -49,10 +50,7 @@ std::string PoseidonZRGBController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void PoseidonZRGBController::SetMode(unsigned char mode, unsigned char direction, unsigned char speed) diff --git a/Controllers/ThermaltakeRiingController/ThermaltakeRiingController/ThermaltakeRiingController.cpp b/Controllers/ThermaltakeRiingController/ThermaltakeRiingController/ThermaltakeRiingController.cpp index c0e7efd9..16a886c0 100644 --- a/Controllers/ThermaltakeRiingController/ThermaltakeRiingController/ThermaltakeRiingController.cpp +++ b/Controllers/ThermaltakeRiingController/ThermaltakeRiingController/ThermaltakeRiingController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "ThermaltakeRiingController.h" ThermaltakeRiingController::ThermaltakeRiingController(hid_device* dev_handle, const char* path) @@ -40,10 +41,7 @@ std::string ThermaltakeRiingController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } std::string ThermaltakeRiingController::GetFirmwareVersion() diff --git a/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.cpp b/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.cpp index b3e8655e..70984027 100644 --- a/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.cpp +++ b/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "ThermaltakeRiingQuadController.h" ThermaltakeRiingQuadController::ThermaltakeRiingQuadController(hid_device* dev_handle, const char* path) @@ -27,10 +28,6 @@ ThermaltakeRiingQuadController::ThermaltakeRiingQuadController(hid_device* dev_h wName = std::wstring(tmpName); device_name.append(" ").append(std::string(wName.begin(), wName.end())); - hid_get_serial_number_string(dev, tmpName, HID_MAX_STR); - wName = std::wstring(tmpName); - serial = std::string(wName.begin(), wName.end()); - SendInit(); /*-----------------------------------------------------*\ @@ -87,7 +84,15 @@ std::string ThermaltakeRiingQuadController::GetDeviceLocation() std::string ThermaltakeRiingQuadController::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)); } void ThermaltakeRiingQuadController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors) diff --git a/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.h b/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.h index 1ab99352..0d30c995 100644 --- a/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.h +++ b/Controllers/ThermaltakeRiingController/ThermaltakeRiingQuadController/ThermaltakeRiingQuadController.h @@ -64,7 +64,6 @@ private: unsigned char current_mode; unsigned char current_speed; std::string device_name; - std::string serial; std::string location; uint8_t tt_quad_buffer[THERMALTAKE_QUAD_NUM_CHANNELS][THERMALTAKE_QUAD_PACKET_SIZE]; diff --git a/Controllers/ThingMController/BlinkController.cpp b/Controllers/ThingMController/BlinkController.cpp index 12c0819a..170048d7 100644 --- a/Controllers/ThingMController/BlinkController.cpp +++ b/Controllers/ThingMController/BlinkController.cpp @@ -11,6 +11,7 @@ #include #include "BlinkController.h" +#include "StringUtils.h" BlinkController::BlinkController(hid_device* dev_handle, char *_path) { @@ -27,11 +28,6 @@ BlinkController::BlinkController(hid_device* dev_handle, char *_path) 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()); - } BlinkController::~BlinkController() @@ -49,7 +45,15 @@ std::string BlinkController::GetDeviceName() std::string BlinkController::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 BlinkController::GetLocation() diff --git a/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.cpp b/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.cpp index d8741904..8615d54d 100644 --- a/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.cpp +++ b/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "TrustGXT114Controller.h" TrustGXT114Controller::TrustGXT114Controller(hid_device* dev_handle, const hid_device_info& info) @@ -17,20 +18,6 @@ TrustGXT114Controller::TrustGXT114Controller(hid_device* dev_handle, const hid_d dev = dev_handle; location = info.path; version = ""; - - 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()); - } - } TrustGXT114Controller::~TrustGXT114Controller() @@ -45,7 +32,15 @@ std::string TrustGXT114Controller::GetDeviceLocation() std::string TrustGXT114Controller::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 TrustGXT114Controller::GetFirmwareVersion() diff --git a/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.h b/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.h index ed7c5aaf..07f1ae80 100644 --- a/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.h +++ b/Controllers/TrustController/TrustGXT114Controller/TrustGXT114Controller.h @@ -55,6 +55,5 @@ protected: private: std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.cpp b/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.cpp index 1bf5c9cb..a05ecd28 100644 --- a/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.cpp +++ b/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "TrustGXT180Controller.h" TrustGXT180Controller::TrustGXT180Controller(hid_device* dev_handle, const hid_device_info& info) @@ -17,20 +18,6 @@ TrustGXT180Controller::TrustGXT180Controller(hid_device* dev_handle, const hid_d dev = dev_handle; location = info.path; version = ""; - - 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()); - } - } TrustGXT180Controller::~TrustGXT180Controller() @@ -45,7 +32,15 @@ std::string TrustGXT180Controller::GetDeviceLocation() std::string TrustGXT180Controller::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 TrustGXT180Controller::GetFirmwareVersion() diff --git a/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.h b/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.h index 94f2c943..f32e5b47 100644 --- a/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.h +++ b/Controllers/TrustController/TrustGXT180Controller/TrustGXT180Controller.h @@ -55,6 +55,5 @@ protected: private: std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/ValkyrieKeyboardController/ValkyrieKeyboardController.cpp b/Controllers/ValkyrieKeyboardController/ValkyrieKeyboardController.cpp index fe2a9467..440f1314 100644 --- a/Controllers/ValkyrieKeyboardController/ValkyrieKeyboardController.cpp +++ b/Controllers/ValkyrieKeyboardController/ValkyrieKeyboardController.cpp @@ -11,6 +11,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "ValkyrieKeyboardController.h" ValkyrieKeyboardController::ValkyrieKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid, const int interface) @@ -41,10 +42,7 @@ std::string ValkyrieKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } unsigned short ValkyrieKeyboardController::GetUSBPID() diff --git a/Controllers/ViewSonicController/VS_XG270QG_Controller.cpp b/Controllers/ViewSonicController/VS_XG270QG_Controller.cpp index a62bdd95..f0d89429 100644 --- a/Controllers/ViewSonicController/VS_XG270QG_Controller.cpp +++ b/Controllers/ViewSonicController/VS_XG270QG_Controller.cpp @@ -10,8 +10,9 @@ \*---------------------------------------------------------*/ #include -#include "VS_XG270QG_Controller.h" #include "LogManager.h" +#include "StringUtils.h" +#include "VS_XG270QG_Controller.h" VS_XG270QG_Controller::VS_XG270QG_Controller(hid_device* device, const char* path) { @@ -39,11 +40,7 @@ std::string VS_XG270QG_Controller::GetSerial() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); - return serial; + return(StringUtils::wstring_to_string(serial_string)); } void VS_XG270QG_Controller::SetMode(uint8_t mode, uint8_t r, uint8_t g, uint8_t b) diff --git a/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.cpp b/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.cpp index e84338d8..4e52682a 100644 --- a/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.cpp +++ b/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.cpp @@ -11,9 +11,10 @@ #include #include +#include "LogManager.h" +#include "StringUtils.h" #include "WinbondGamingKeyboardController.h" #include "RGBController_WinbondGamingKeyboard.h" -#include "LogManager.h" #define WINBOND_HID_DATA_LEN 64 @@ -202,22 +203,17 @@ void WinbondGamingKeyboardController::SetVersionLayout() version = "???"; } -std::string WinbondGamingKeyboardController::GetSerialString() const +std::string WinbondGamingKeyboardController::GetSerialString() { - wchar_t serial_wchar[128] = {}; - int ret = hid_get_serial_number_string(dev, serial_wchar, 128); - if(ret == -1) - { - return ""; - } - std::wstring serial_wstring(serial_wchar); - std::string serial_string; - std::transform(serial_wstring.begin(), serial_wstring.end(), std::back_inserter(serial_string), [] (wchar_t i) - { - return (char)i; - }); + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); - return serial_string; + if(ret != 0) + { + return(""); + } + + return(StringUtils::wstring_to_string(serial_string)); } static void setModeImpl(hid_device* dev, bool is_logo, unsigned char effect_mode, unsigned char colors[2][3], diff --git a/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.h b/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.h index 6de637f3..212f06e3 100644 --- a/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.h +++ b/Controllers/WinbondGamingKeyboardController/WinbondGamingKeyboardController.h @@ -26,7 +26,7 @@ class WinbondGamingKeyboardController public: WinbondGamingKeyboardController(hid_device *dev_handle, const hid_device_info &info, const std::string& name); - std::string GetSerialString() const; + std::string GetSerialString(); const char* GetDeviceLocation() const { diff --git a/Controllers/WootingKeyboardController/WootingKeyboardController.cpp b/Controllers/WootingKeyboardController/WootingKeyboardController.cpp index 99322539..ad57c756 100644 --- a/Controllers/WootingKeyboardController/WootingKeyboardController.cpp +++ b/Controllers/WootingKeyboardController/WootingKeyboardController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "WootingKeyboardController.h" WootingKeyboardController::WootingKeyboardController() @@ -44,7 +45,15 @@ std::string WootingKeyboardController::GetDescription() std::string WootingKeyboardController::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)); } uint8_t WootingKeyboardController::GetWootingType() diff --git a/Controllers/WootingKeyboardController/WootingKeyboardController.h b/Controllers/WootingKeyboardController/WootingKeyboardController.h index 43c06141..81f2790e 100644 --- a/Controllers/WootingKeyboardController/WootingKeyboardController.h +++ b/Controllers/WootingKeyboardController/WootingKeyboardController.h @@ -63,7 +63,6 @@ public: std::string vendor; std::string description; std::string location; - std::string serial; uint8_t wooting_type; uint8_t key_code_limit; diff --git a/Controllers/WootingKeyboardController/WootingOneKeyboardController/WootingOneKeyboardController.cpp b/Controllers/WootingKeyboardController/WootingOneKeyboardController/WootingOneKeyboardController.cpp index 414841e8..d8cacc70 100644 --- a/Controllers/WootingKeyboardController/WootingOneKeyboardController/WootingOneKeyboardController.cpp +++ b/Controllers/WootingKeyboardController/WootingOneKeyboardController/WootingOneKeyboardController.cpp @@ -70,10 +70,6 @@ WootingOneKeyboardController::WootingOneKeyboardController(hid_device* dev_handl wName = std::wstring(tmpName); description = 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()); - SendInitialize(); } diff --git a/Controllers/WootingKeyboardController/WootingTwoKeyboardController/WootingTwoKeyboardController.cpp b/Controllers/WootingKeyboardController/WootingTwoKeyboardController/WootingTwoKeyboardController.cpp index 4342e42f..37c32e2d 100644 --- a/Controllers/WootingKeyboardController/WootingTwoKeyboardController/WootingTwoKeyboardController.cpp +++ b/Controllers/WootingKeyboardController/WootingTwoKeyboardController/WootingTwoKeyboardController.cpp @@ -53,10 +53,6 @@ WootingTwoKeyboardController::WootingTwoKeyboardController(hid_device* dev_handl wName = std::wstring(tmpName); description = 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()); - SendInitialize(); } diff --git a/Controllers/WushiController/WushiL50USBController.cpp b/Controllers/WushiController/WushiL50USBController.cpp index 4a945156..cc9cc3d4 100644 --- a/Controllers/WushiController/WushiL50USBController.cpp +++ b/Controllers/WushiController/WushiL50USBController.cpp @@ -8,6 +8,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "WushiL50USBController.h" WushiL50USBController::WushiL50USBController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path) @@ -74,5 +75,13 @@ std::string WushiL50USBController::getLocation() std::string WushiL50USBController::GetSerialString() { - return(serial_number); + wchar_t serial_string[128]; + int ret = wrapper.hid_get_serial_number_string(dev, serial_string, 128); + + if(ret != 0) + { + return(""); + } + + return(StringUtils::wstring_to_string(serial_string)); } diff --git a/Controllers/WushiController/WushiL50USBController.h b/Controllers/WushiController/WushiL50USBController.h index 5adca2fc..55698d1e 100644 --- a/Controllers/WushiController/WushiL50USBController.h +++ b/Controllers/WushiController/WushiL50USBController.h @@ -109,5 +109,4 @@ private: hidapi_wrapper wrapper; hid_device * dev; std::string location; - std::string serial_number; }; diff --git a/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.cpp b/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.cpp index 3e1fe140..065b40e6 100644 --- a/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.cpp +++ b/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.cpp @@ -10,6 +10,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "ZETEdgeAirProController.h" ZETEdgeAirProController::ZETEdgeAirProController(hid_device* dev_handle, const hid_device_info& info) @@ -17,19 +18,6 @@ ZETEdgeAirProController::ZETEdgeAirProController(hid_device* dev_handle, const h dev = dev_handle; location = info.path; version = ""; - - 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()); - } } ZETEdgeAirProController::~ZETEdgeAirProController() @@ -44,7 +32,15 @@ std::string ZETEdgeAirProController::GetDeviceLocation() std::string ZETEdgeAirProController::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 ZETEdgeAirProController::GetFirmwareVersion() diff --git a/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.h b/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.h index 7f25d640..3d6d8031 100644 --- a/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.h +++ b/Controllers/ZETEdgeAirProController/ZETEdgeAirProController.h @@ -52,6 +52,5 @@ protected: private: std::string location; - std::string serial_number; std::string version; }; diff --git a/Controllers/ZETKeyboardController/ZETBladeOpticalController.cpp b/Controllers/ZETKeyboardController/ZETBladeOpticalController.cpp index 17e06593..dfc89059 100644 --- a/Controllers/ZETKeyboardController/ZETBladeOpticalController.cpp +++ b/Controllers/ZETKeyboardController/ZETBladeOpticalController.cpp @@ -13,6 +13,7 @@ \*---------------------------------------------------------*/ #include +#include "StringUtils.h" #include "ZETBladeOpticalController.h" using namespace std::chrono_literals; @@ -49,15 +50,12 @@ std::string ZETBladeOpticalController::GetSerialString() wchar_t serial_string[128]; int ret = hid_get_serial_number_string(dev, serial_string, 128); - if (ret != 0) + if(ret != 0) { return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void ZETBladeOpticalController::PrepareHeader(unsigned char* packet, unsigned char brightness) diff --git a/Controllers/ZalmanZSyncController/ZalmanZSyncController.cpp b/Controllers/ZalmanZSyncController/ZalmanZSyncController.cpp index 18d7d66b..c895626c 100644 --- a/Controllers/ZalmanZSyncController/ZalmanZSyncController.cpp +++ b/Controllers/ZalmanZSyncController/ZalmanZSyncController.cpp @@ -17,6 +17,7 @@ #include #include #include +#include "StringUtils.h" #include "ZalmanZSyncController.h" using namespace std::chrono_literals; @@ -79,10 +80,7 @@ std::string ZalmanZSyncController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); - - return(return_string); + return(StringUtils::wstring_to_string(serial_string)); } void ZalmanZSyncController::SetChannelEffect(unsigned char channel, diff --git a/StringUtils.cpp b/StringUtils.cpp index 71e84c34..6b321fb4 100644 --- a/StringUtils.cpp +++ b/StringUtils.cpp @@ -7,6 +7,8 @@ | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ +#include +#include #include #include "StringUtils.h" @@ -48,6 +50,13 @@ const char* StringUtils::wchar_to_char(const wchar_t* pwchar) return filePathC; } +std::string StringUtils::wstring_to_string(const std::wstring wstring) +{ + std::wstring_convert, wchar_t> converter; + + return(converter.to_bytes(wstring)); +} + const std::string StringUtils::remove_null_terminating_chars(std::string input) { while (!input.empty() && input.back() == 0) diff --git a/StringUtils.h b/StringUtils.h index 64d8a470..4c730590 100644 --- a/StringUtils.h +++ b/StringUtils.h @@ -7,8 +7,7 @@ | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#ifndef STRING_UTILS_H -#define STRING_UTILS_H +#pragma once #include @@ -16,7 +15,6 @@ class StringUtils { public: static const char* wchar_to_char(const wchar_t* pwchar); + static std::string wstring_to_string(const std::wstring wstring); static const std::string remove_null_terminating_chars(std::string input); }; - -#endif // STRING_UTILS_H