From 43de81819b770ba987a8d175007cbe5f61d32432 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 30 Jul 2024 00:02:59 -0500 Subject: [PATCH] Fix wstring to string conversion warnings in BlinkController.cpp --- .../ThingMController/BlinkController.cpp | 44 +++++++++---------- .../ThingMController/BlinkController.h | 2 + 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Controllers/ThingMController/BlinkController.cpp b/Controllers/ThingMController/BlinkController.cpp index 170048d7..119fb159 100644 --- a/Controllers/ThingMController/BlinkController.cpp +++ b/Controllers/ThingMController/BlinkController.cpp @@ -18,16 +18,16 @@ BlinkController::BlinkController(hid_device* dev_handle, char *_path) dev = dev_handle; location = _path; - const int szTemp = 256; - wchar_t tmpName[szTemp]; + /*---------------------------------------------------------*\ + | Get device name from HID manufacturer and product strings | + \*---------------------------------------------------------*/ + wchar_t name_string[HID_MAX_STR]; - hid_get_manufacturer_string(dev, tmpName, szTemp); - std::wstring wName = std::wstring(tmpName); - device_name = std::string(wName.begin(), wName.end()); + hid_get_manufacturer_string(dev, name_string, HID_MAX_STR); + device_name = StringUtils::wstring_to_string(name_string); - hid_get_product_string(dev, tmpName, szTemp); - wName = std::wstring(tmpName); - device_name.append(" ").append(std::string(wName.begin(), wName.end())); + hid_get_product_string(dev, name_string, HID_MAX_STR); + device_name.append(" ").append(StringUtils::wstring_to_string(name_string)); } BlinkController::~BlinkController() @@ -64,22 +64,22 @@ std::string BlinkController::GetLocation() void BlinkController::SendUpdate(unsigned char led, unsigned char red, unsigned char green, unsigned char blue, unsigned int speed) { - unsigned char buffer[BLINK_PACKET_SIZE] = { 0x00 }; - memset(buffer, 0x00, BLINK_PACKET_SIZE); + unsigned char buffer[BLINK_PACKET_SIZE] = { 0x00 }; + memset(buffer, 0x00, BLINK_PACKET_SIZE); - buffer[0x00] = 0x01; - buffer[0x01] = 0x63; - buffer[0x02] = red; - buffer[0x03] = green; - buffer[0x04] = blue; + buffer[0x00] = 0x01; + buffer[0x01] = 0x63; + buffer[0x02] = red; + buffer[0x03] = green; + buffer[0x04] = blue; - if(speed > 0) - { - buffer[0x05] = (speed & 0xff00) >> 8; - buffer[0x06] = speed & 0x00ff; - } + if(speed > 0) + { + buffer[0x05] = (speed & 0xff00) >> 8; + buffer[0x06] = speed & 0x00ff; + } - buffer[0x07] = led; + buffer[0x07] = led; - hid_send_feature_report(dev, buffer, BLINK_PACKET_SIZE); + hid_send_feature_report(dev, buffer, BLINK_PACKET_SIZE); } diff --git a/Controllers/ThingMController/BlinkController.h b/Controllers/ThingMController/BlinkController.h index a650966c..cdbbf724 100644 --- a/Controllers/ThingMController/BlinkController.h +++ b/Controllers/ThingMController/BlinkController.h @@ -21,6 +21,8 @@ #define BLINK_MODE_DIRECT 1 #define BLINK_MODE_FADE 2 +#define HID_MAX_STR 255 + class BlinkController { public: