mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2025-12-23 23:37:48 -05:00
UI: add a dialog that shows local hardware IDs
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "ProfileManager.h"
|
||||
#include "LogManager.h"
|
||||
#include "filesystem.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <codecvt>
|
||||
@@ -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 = "";
|
||||
|
||||
40
StringUtils.cpp
Normal file
40
StringUtils.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "StringUtils.h"
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
10
StringUtils.h
Normal file
10
StringUtils.h
Normal file
@@ -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
|
||||
123
qt/OpenRGBHardwareIDsDialog.cpp
Normal file
123
qt/OpenRGBHardwareIDsDialog.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
#include "OpenRGBHardwareIDsDialog.h"
|
||||
#include "ui_OpenRGBHardwareIDsDialog.h"
|
||||
#include <hidapi/hidapi.h>
|
||||
#include "ResourceManager.h"
|
||||
#include "StringUtils.h"
|
||||
#include <QString>
|
||||
#include <QClipboard>
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <libusb.h>
|
||||
#else
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#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<i2c_smbus_interface*> 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"));
|
||||
}
|
||||
31
qt/OpenRGBHardwareIDsDialog.h
Normal file
31
qt/OpenRGBHardwareIDsDialog.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef OPENRGBHARDWAREIDSDIALOG_H
|
||||
#define OPENRGBHARDWAREIDSDIALOG_H
|
||||
|
||||
#include "ui_OpenRGBHardwareIDsDialog.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
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
|
||||
31
qt/OpenRGBHardwareIDsDialog.ui
Normal file
31
qt/OpenRGBHardwareIDsDialog.ui
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBHardwareIDsDialogUi</class>
|
||||
<widget class="QWidget" name="OpenRGBHardwareIDsDialogUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>425</width>
|
||||
<height>273</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListWidget" name="HardwareIdsList"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="CopyToClipboardButton">
|
||||
<property name="text">
|
||||
<string>Copy to clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -47,6 +47,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="GetHardwareIDsButton">
|
||||
<property name="text">
|
||||
<string>Get hardware IDs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user