diff --git a/OpenRGB.pro b/OpenRGB.pro index 5ee163b3..c1ec2e88 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -219,6 +219,7 @@ HEADERS += qt/OpenRGBDialog2.h \ qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsEntry.h \ qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.h \ + qt/OpenRGBHardwareIDsDialog.h \ qt/OpenRGBKasaSmartSettingsPage/OpenRGBKasaSmartSettingsEntry.h \ qt/OpenRGBKasaSmartSettingsPage/OpenRGBKasaSmartSettingsPage.h \ qt/OpenRGBPluginContainer.h \ @@ -255,6 +256,7 @@ HEADERS += qt/TabLabel.h \ serial_port/find_usb_serial_port.h \ serial_port/serial_port.h \ + StringUtils.h \ super_io/super_io.h \ AutoStart/AutoStart.h \ Controllers/A4TechController/BloodyMouseController.h \ @@ -755,6 +757,7 @@ SOURCES += qt/OpenRGBDialog2.cpp \ qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsEntry.cpp \ qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.cpp \ + qt/OpenRGBHardwareIDsDialog.cpp \ qt/OpenRGBKasaSmartSettingsPage/OpenRGBKasaSmartSettingsEntry.cpp \ qt/OpenRGBKasaSmartSettingsPage/OpenRGBKasaSmartSettingsPage.cpp \ qt/OpenRGBPluginContainer.cpp \ @@ -791,6 +794,7 @@ SOURCES += qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.cpp \ qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsPage.cpp \ serial_port/serial_port.cpp \ + StringUtils.cpp \ super_io/super_io.cpp \ AutoStart/AutoStart.cpp \ Controllers/A4TechController/A4Tech_Detector.cpp \ @@ -1367,6 +1371,7 @@ FORMS += qt/OpenRGBDevicePage.ui \ qt/OpenRGBDialog.ui \ qt/OpenRGBDialog2.ui \ + qt/OpenRGBHardwareIDsDialog.ui \ qt/OpenRGBPluginContainer.ui \ qt/OpenRGBProfileSaveDialog.ui \ qt/OpenRGBServerInfoPage.ui \ diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 4a437198..8a42d205 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -13,6 +13,7 @@ #include "ProfileManager.h" #include "LogManager.h" #include "filesystem.h" +#include "StringUtils.h" #ifdef _WIN32 #include @@ -807,44 +808,6 @@ void ResourceManager::DisableDetection() detection_enabled = false; } -const char* wchar_to_char(const wchar_t* pwchar) -{ - if (pwchar == nullptr) - { - return ""; - } - // get the number of characters in the string. - int currentCharIndex = 0; - char currentChar = pwchar[currentCharIndex]; - - while (currentChar != '\0') - { - currentCharIndex++; - currentChar = pwchar[currentCharIndex]; - } - - const int charCount = currentCharIndex + 1; - - // allocate a new block of memory size char (1 byte) instead of wide char (2 bytes) - char* filePathC = (char*)malloc(sizeof(char) * charCount); - - for (int i = 0; i < charCount; i++) - { - // convert to char (1 byte) - char character = pwchar[i]; - - *filePathC = character; - - filePathC += sizeof(char); - - } - filePathC += '\0'; - - filePathC -= (sizeof(char) * charCount); - - return filePathC; -} - void ResourceManager::DetectDevicesThreadFunction() { DetectDeviceMutex.lock(); @@ -1131,8 +1094,8 @@ void ResourceManager::DetectDevicesThreadFunction() { if(LogManager::get()->getLoglevel() >= LL_DEBUG) { - const char* manu_name = wchar_to_char(current_hid_device->manufacturer_string); - const char* prod_name = wchar_to_char(current_hid_device->product_string); + const char* manu_name = StringUtils::wchar_to_char(current_hid_device->manufacturer_string); + const char* prod_name = StringUtils::wchar_to_char(current_hid_device->product_string); LOG_DEBUG("[%04X:%04X U=%04X P=0x%04X I=%d] %-25s - %s", current_hid_device->vendor_id, current_hid_device->product_id, current_hid_device->usage, current_hid_device->usage_page, current_hid_device->interface_number, manu_name, prod_name); } detection_string = ""; @@ -1299,8 +1262,8 @@ void ResourceManager::DetectDevicesThreadFunction() { if(LogManager::get()->getLoglevel() >= LL_DEBUG) { - const char* manu_name = wchar_to_char(current_hid_device->manufacturer_string); - const char* prod_name = wchar_to_char(current_hid_device->product_string); + const char* manu_name = StringUtils::wchar_to_char(current_hid_device->manufacturer_string); + const char* prod_name = StringUtils::wchar_to_char(current_hid_device->product_string); LOG_DEBUG("[%04X:%04X U=%04X P=0x%04X I=%d] %-25s - %s", current_hid_device->vendor_id, current_hid_device->product_id, current_hid_device->usage, current_hid_device->usage_page, current_hid_device->interface_number, manu_name, prod_name); } detection_string = ""; diff --git a/StringUtils.cpp b/StringUtils.cpp new file mode 100644 index 00000000..614679c1 --- /dev/null +++ b/StringUtils.cpp @@ -0,0 +1,40 @@ +#include "StringUtils.h" +#include + +const char* StringUtils::wchar_to_char(const wchar_t* pwchar) +{ + if (pwchar == nullptr) + { + return ""; + } + // get the number of characters in the string. + int currentCharIndex = 0; + char currentChar = pwchar[currentCharIndex]; + + while (currentChar != '\0') + { + currentCharIndex++; + currentChar = pwchar[currentCharIndex]; + } + + const int charCount = currentCharIndex + 1; + + // allocate a new block of memory size char (1 byte) instead of wide char (2 bytes) + char* filePathC = (char*)malloc(sizeof(char) * charCount); + + for (int i = 0; i < charCount; i++) + { + // convert to char (1 byte) + char character = pwchar[i]; + + *filePathC = character; + + filePathC += sizeof(char); + + } + filePathC += '\0'; + + filePathC -= (sizeof(char) * charCount); + + return filePathC; +} diff --git a/StringUtils.h b/StringUtils.h new file mode 100644 index 00000000..7b52f46b --- /dev/null +++ b/StringUtils.h @@ -0,0 +1,10 @@ +#ifndef STRING_UTILS_H +#define STRING_UTILS_H + +class StringUtils +{ +public: + static const char* wchar_to_char(const wchar_t* pwchar); +}; + +#endif // STRING_UTILS_H diff --git a/qt/OpenRGBHardwareIDsDialog.cpp b/qt/OpenRGBHardwareIDsDialog.cpp new file mode 100644 index 00000000..1fca7241 --- /dev/null +++ b/qt/OpenRGBHardwareIDsDialog.cpp @@ -0,0 +1,123 @@ +#include "OpenRGBHardwareIDsDialog.h" +#include "ui_OpenRGBHardwareIDsDialog.h" +#include +#include "ResourceManager.h" +#include "StringUtils.h" +#include +#include + +#ifdef __FreeBSD__ +#include +#else +#include +#endif + +Ui::OpenRGBHardwareIDsDialog::OpenRGBHardwareIDsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::OpenRGBHardwareIDsDialogUi) +{ + ui->setupUi(this); +} + +Ui::OpenRGBHardwareIDsDialog::~OpenRGBHardwareIDsDialog() +{ + delete ui; +} + +int Ui::OpenRGBHardwareIDsDialog::show() +{ + /*---------------------------------------------------------*\ + | Add i2c busses infos | + \*---------------------------------------------------------*/ + std::vector i2CBusses = ResourceManager::get()->GetI2CBusses(); + + strings.push_back("i2c busses"); + + for(i2c_smbus_interface* bus : i2CBusses) + { + char line[512]; + sprintf(line, "%04X:%04X %04X:%04X - %s", bus->pci_vendor, bus->pci_device, bus->pci_subsystem_vendor, bus->pci_subsystem_device, bus->device_name); + strings.push_back(line); + } + + /*---------------------------------------------------------*\ + | Add HID devices infos | + \*---------------------------------------------------------*/ + hid_device_info* hid_devices = NULL; + hid_devices = hid_enumerate(0,0); + + hid_device_info* current_hid_device; + current_hid_device = hid_devices; + + strings.push_back("HID devices"); + + while(current_hid_device) + { + const char* manu_name = StringUtils::wchar_to_char(current_hid_device->manufacturer_string); + const char* prod_name = StringUtils::wchar_to_char(current_hid_device->product_string); + + char line[512]; + + sprintf(line, "[%04X:%04X U=%04X P=0x%04X I=%d] %s - %s", current_hid_device->vendor_id, current_hid_device->product_id, current_hid_device->usage, current_hid_device->usage_page, current_hid_device->interface_number, manu_name, prod_name); + + strings.push_back(line); + current_hid_device = current_hid_device->next; + } + + /*---------------------------------------------------------*\ + | Add LibUSB devices infos | + \*---------------------------------------------------------*/ + libusb_device** devices = nullptr; + + strings.push_back("LibUSB devices"); + + int ret; + + ret = libusb_init(NULL); + + if(ret < 0) + { + return 0; + } + + ret = libusb_get_device_list(NULL, &devices); + + if(ret < 0) + { + return 0; + } + + int deviceCount = ret; + + for(int i = 0; i < deviceCount; i++) + { + libusb_device* device = devices[i]; + libusb_device_descriptor descriptor; + + ret = libusb_get_device_descriptor(device, &descriptor); + + if(ret < 0) + { + continue; + } + + char line[512]; + sprintf(line, "%04X:%04X", descriptor.idVendor, descriptor.idProduct); + strings.push_back(line); + } + + if(devices != nullptr) + { + libusb_free_device_list(devices, 1); + } + + ui->HardwareIdsList->addItems(strings); + + return this->exec(); +} + +void Ui::OpenRGBHardwareIDsDialog::on_CopyToClipboardButton_clicked() +{ + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setText(strings.join("\n")); +} diff --git a/qt/OpenRGBHardwareIDsDialog.h b/qt/OpenRGBHardwareIDsDialog.h new file mode 100644 index 00000000..e4a50071 --- /dev/null +++ b/qt/OpenRGBHardwareIDsDialog.h @@ -0,0 +1,31 @@ +#ifndef OPENRGBHARDWAREIDSDIALOG_H +#define OPENRGBHARDWAREIDSDIALOG_H + +#include "ui_OpenRGBHardwareIDsDialog.h" + +#include + +namespace Ui +{ + class OpenRGBHardwareIDsDialog; +} + +class Ui::OpenRGBHardwareIDsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit OpenRGBHardwareIDsDialog(QWidget *parent = nullptr); + ~OpenRGBHardwareIDsDialog(); + + int show(); + +private slots: + void on_CopyToClipboardButton_clicked(); + +private: + Ui::OpenRGBHardwareIDsDialogUi *ui; + QStringList strings; +}; + +#endif // OPENRGBHARDWAREIDSDIALOG_H diff --git a/qt/OpenRGBHardwareIDsDialog.ui b/qt/OpenRGBHardwareIDsDialog.ui new file mode 100644 index 00000000..ccde288a --- /dev/null +++ b/qt/OpenRGBHardwareIDsDialog.ui @@ -0,0 +1,31 @@ + + + OpenRGBHardwareIDsDialogUi + + + + 0 + 0 + 425 + 273 + + + + Form + + + + + + + + + Copy to clipboard + + + + + + + + diff --git a/qt/OpenRGBSupportedDevicesPage.cpp b/qt/OpenRGBSupportedDevicesPage.cpp index 1f5c6da7..9156a160 100644 --- a/qt/OpenRGBSupportedDevicesPage.cpp +++ b/qt/OpenRGBSupportedDevicesPage.cpp @@ -1,6 +1,7 @@ #include "OpenRGBSupportedDevicesPage.h" #include "ui_OpenRGBSupportedDevicesPage.h" #include "ResourceManager.h" +#include "OpenRGBHardwareIDsDialog.h" using namespace Ui; @@ -52,6 +53,12 @@ void OpenRGBSupportedDevicesPage::on_SaveButton_clicked() detectorTableModel->applySettings(); } +void OpenRGBSupportedDevicesPage::on_GetHardwareIDsButton_clicked() +{ + OpenRGBHardwareIDsDialog dialog(this); + dialog.show(); +} + void OpenRGBSupportedDevicesPage::on_Filter_textChanged(const QString &arg1) { #ifdef _QT6 diff --git a/qt/OpenRGBSupportedDevicesPage.h b/qt/OpenRGBSupportedDevicesPage.h index cee65032..8480a487 100644 --- a/qt/OpenRGBSupportedDevicesPage.h +++ b/qt/OpenRGBSupportedDevicesPage.h @@ -23,6 +23,7 @@ public: private slots: void changeEvent(QEvent *event); void on_SaveButton_clicked(); + void on_GetHardwareIDsButton_clicked(); void on_Filter_textChanged(const QString &arg1); diff --git a/qt/OpenRGBSupportedDevicesPage.ui b/qt/OpenRGBSupportedDevicesPage.ui index 52e4fa27..aaf686a6 100644 --- a/qt/OpenRGBSupportedDevicesPage.ui +++ b/qt/OpenRGBSupportedDevicesPage.ui @@ -47,6 +47,13 @@ + + + + Get hardware IDs + + +