diff --git a/OpenAuraSDK.cpp b/OpenAuraSDK.cpp index 282f1f63..5865f43e 100644 --- a/OpenAuraSDK.cpp +++ b/OpenAuraSDK.cpp @@ -319,84 +319,6 @@ void DetectI2CBusses() #endif /* WIN32 */ - -/******************************************************************************************\ -* * -* DetectI2C * -* * -* Prints a list of all detected I2C addresses on the given bus * -* * -* bus - pointer to i2c_smbus_interface to scan * -* mode - one of AUTO, QUICK, READ, FUNC - method of access * -* * -* Code adapted from i2cdetect.c from i2c-tools Linux package * -* * -\******************************************************************************************/ - -#define MODE_AUTO 0 -#define MODE_QUICK 1 -#define MODE_READ 2 -#define MODE_FUNC 3 - -std::string DetectI2C(i2c_smbus_interface * bus, int mode) -{ - int i, j; - int res; - int slave_addr; - char line[128]; - std::string text; - - sprintf(line, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n"); - text.append(line); - - for (i = 0; i < 128; i += 16) - { - sprintf(line, "%02x: ", i); - text.append(line); - - for (j = 0; j < 16; j++) - { - /* Set slave address */ - slave_addr = i + j; - - /* Probe this address */ - switch (mode) - { - case MODE_QUICK: - res = bus->i2c_smbus_write_quick(slave_addr, I2C_SMBUS_WRITE); - break; - case MODE_READ: - res = bus->i2c_smbus_read_byte(slave_addr); - break; - default: - if ((i + j >= 0x30 && i + j <= 0x37) - || (i + j >= 0x50 && i + j <= 0x5F)) - res = bus->i2c_smbus_read_byte(slave_addr); - else - res = bus->i2c_smbus_write_quick(slave_addr, I2C_SMBUS_WRITE); - break; - } - - if (res < 0) - { - sprintf(line, "-- "); - text.append(line); - } - else - { - sprintf(line, "%02x ", i + j); - text.append(line); - } - } - sprintf(line, "\r\n"); - text.append(line); - } - - return text; - -} /* DetectI2C() */ - - /******************************************************************************************\ * * * DumpAuraRegisters * diff --git a/OpenRGB.pro b/OpenRGB.pro index 2628971e..857ee37a 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -7,6 +7,7 @@ TEMPLATE = app INCLUDEPATH += \ i2c_smbus/ \ + i2c_tools/ \ net_port/ \ serial_port/ \ Controllers/AuraController/ \ @@ -22,13 +23,15 @@ INCLUDEPATH += \ SOURCES += \ main.cpp \ OpenAuraSDK.cpp \ - qt/OpenRGBDeviceInfoPage.cpp \ - qt/OpenRGBDevicePage.cpp \ + qt/OpenRGBDeviceInfoPage.cpp \ + qt/OpenRGBDevicePage.cpp \ qt/OpenRGBDialog.cpp \ i2c_smbus/i2c_smbus.cpp \ + i2c_tools/i2c_tools.cpp \ net_port/net_port.cpp \ - qt/OpenRGBDialog2.cpp \ - qt/hsv.cpp \ + qt/OpenRGBDialog2.cpp \ + qt/OpenRGBSystemInfoPage.cpp \ + qt/hsv.cpp \ serial_port/serial_port.cpp \ Controllers/AuraController/AuraController.cpp \ Controllers/AuraController/AuraControllerDetect.cpp \ @@ -53,13 +56,15 @@ SOURCES += \ RGBController/RGBController_RGBFusion.cpp HEADERS += \ - Controllers/RGBFusionController/RGBFusionController.h \ - qt/OpenRGBDeviceInfoPage.h \ - qt/OpenRGBDevicePage.h \ + Controllers/RGBFusionController/RGBFusionController.h \ + qt/OpenRGBDeviceInfoPage.h \ + qt/OpenRGBDevicePage.h \ qt/OpenRGBDialog.h \ i2c_smbus/i2c_smbus.h \ + i2c_tools/i2c_tools.h \ net_port/net_port.h \ - qt/OpenRGBDialog2.h \ + qt/OpenRGBDialog2.h \ + qt/OpenRGBSystemInfoPage.h \ serial_port/serial_port.h \ Controllers/AuraController/AuraController.h \ Controllers/CorsairController/CorsairController.h \ @@ -82,7 +87,8 @@ FORMS += \ qt/OpenRGBDeviceInfoPage.ui \ qt/OpenRGBDevicePage.ui \ qt/OpenRGBDialog.ui \ - qt/OpenRGBDialog2.ui + qt/OpenRGBDialog2.ui \ + qt/OpenRGBSystemInfoPage.ui #----------------------------------------------- # Windows specific project configuration diff --git a/i2c_tools/i2c_tools.cpp b/i2c_tools/i2c_tools.cpp new file mode 100644 index 00000000..b1b9e8ba --- /dev/null +++ b/i2c_tools/i2c_tools.cpp @@ -0,0 +1,72 @@ +#include "i2c_tools.h" + +/******************************************************************************************\ +* * +* i2c_detect * +* * +* Prints a list of all detected I2C addresses on the given bus * +* * +* bus - pointer to i2c_smbus_interface to scan * +* mode - one of AUTO, QUICK, READ, FUNC - method of access * +* * +* Code adapted from i2cdetect.c from i2c-tools Linux package * +* * +\******************************************************************************************/ + +std::string i2c_detect(i2c_smbus_interface * bus, int mode) +{ + int i, j; + int res; + int slave_addr; + char line[128]; + std::string text; + + sprintf(line, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n"); + text.append(line); + + for (i = 0; i < 128; i += 16) + { + sprintf(line, "%02x: ", i); + text.append(line); + + for (j = 0; j < 16; j++) + { + /* Set slave address */ + slave_addr = i + j; + + /* Probe this address */ + switch (mode) + { + case MODE_QUICK: + res = bus->i2c_smbus_write_quick(slave_addr, I2C_SMBUS_WRITE); + break; + case MODE_READ: + res = bus->i2c_smbus_read_byte(slave_addr); + break; + default: + if ((i + j >= 0x30 && i + j <= 0x37) + || (i + j >= 0x50 && i + j <= 0x5F)) + res = bus->i2c_smbus_read_byte(slave_addr); + else + res = bus->i2c_smbus_write_quick(slave_addr, I2C_SMBUS_WRITE); + break; + } + + if (res < 0) + { + sprintf(line, "-- "); + text.append(line); + } + else + { + sprintf(line, "%02x ", i + j); + text.append(line); + } + } + sprintf(line, "\r\n"); + text.append(line); + } + + return text; + +} /* i2c_detect() */ diff --git a/i2c_tools/i2c_tools.h b/i2c_tools/i2c_tools.h new file mode 100644 index 00000000..a992fa65 --- /dev/null +++ b/i2c_tools/i2c_tools.h @@ -0,0 +1,9 @@ +#include +#include "i2c_smbus.h" + +#define MODE_AUTO 0 +#define MODE_QUICK 1 +#define MODE_READ 2 +#define MODE_FUNC 3 + +std::string i2c_detect(i2c_smbus_interface * bus, int mode); diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 5a322fde..d38771b6 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -1,6 +1,7 @@ #include "OpenRGBDialog2.h" #include "OpenRGBDevicePage.h" #include "OpenRGBDeviceInfoPage.h" +#include "OpenRGBSystemInfoPage.h" #include "OpenAuraSDK.h" #include #include @@ -117,6 +118,25 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vec InformationTabBar->setTabButton(dev_idx, QTabBar::LeftSide, NewTabLabel); } + + OpenRGBSystemInfoPage *SysInfoPage = new OpenRGBSystemInfoPage(bus); + ui->InformationTabBar->addTab(SysInfoPage, ""); + + /*-----------------------------------------------------*\ + | Use Qt's HTML capabilities to display both icon and | + | text in the tab label. Choose icon based on device | + | type and append device name string. | + \*-----------------------------------------------------*/ + QString SystemLabelString = "
System
"; + + QLabel *SystemTabLabel = new QLabel(); + SystemTabLabel->setText(SystemLabelString); + SystemTabLabel->setIndent(20); + SystemTabLabel->setGeometry(0, 0, 200, 20); + + InformationTabBar->setTabButton(control.size(), QTabBar::LeftSide, SystemTabLabel); } OpenRGBDialog2::~OpenRGBDialog2() diff --git a/qt/OpenRGBSystemInfoPage.cpp b/qt/OpenRGBSystemInfoPage.cpp new file mode 100644 index 00000000..597aa7dc --- /dev/null +++ b/qt/OpenRGBSystemInfoPage.cpp @@ -0,0 +1,36 @@ +#include "OpenRGBSystemInfoPage.h" +#include "i2c_tools.h" + +using namespace Ui; + +OpenRGBSystemInfoPage::OpenRGBSystemInfoPage(std::vector& bus, QWidget *parent) : + QFrame(parent), + busses(bus), + ui(new Ui::OpenRGBSystemInfoPageUi) +{ + ui->setupUi(this); + + /*-----------------------------------------------------*\ + | Fill in the combo boxes with device information | + \*-----------------------------------------------------*/ + ui->SMBusAdaptersBox->clear(); + + for (int i = 0; i < busses.size(); i++) + { + ui->SMBusAdaptersBox->addItem(busses[i]->device_name); + } + + ui->SMBusAdaptersBox->setCurrentIndex(0); +} + +OpenRGBSystemInfoPage::~OpenRGBSystemInfoPage() +{ + delete ui; +} + +void Ui::OpenRGBSystemInfoPage::on_DetectButton_clicked() +{ + i2c_smbus_interface* bus = busses[ui->SMBusAdaptersBox->currentIndex()]; + + ui->SMBusDataText->setPlainText(i2c_detect(bus, MODE_QUICK).c_str()); +} diff --git a/qt/OpenRGBSystemInfoPage.h b/qt/OpenRGBSystemInfoPage.h new file mode 100644 index 00000000..d624861d --- /dev/null +++ b/qt/OpenRGBSystemInfoPage.h @@ -0,0 +1,28 @@ +#ifndef OPENRGBSYSTEMINFOPAGE_H +#define OPENRGBSYSTEMINFOPAGE_H + +#include +#include "ui_OpenRGBSystemInfoPage.h" +#include "i2c_smbus.h" + +namespace Ui { +class OpenRGBSystemInfoPage; +} + +class Ui::OpenRGBSystemInfoPage : public QFrame +{ + Q_OBJECT + +public: + explicit OpenRGBSystemInfoPage(std::vector& bus, QWidget *parent = nullptr); + ~OpenRGBSystemInfoPage(); + +private slots: + void on_DetectButton_clicked(); + +private: + Ui::OpenRGBSystemInfoPageUi *ui; + std::vector& busses; +}; + +#endif // OPENRGBSYSTEMINFOPAGE_H diff --git a/qt/OpenRGBSystemInfoPage.ui b/qt/OpenRGBSystemInfoPage.ui new file mode 100644 index 00000000..80ce84ba --- /dev/null +++ b/qt/OpenRGBSystemInfoPage.ui @@ -0,0 +1,65 @@ + + + OpenRGBSystemInfoPageUi + + + + 0 + 0 + 500 + 300 + + + + Frame + + + + + 20 + 10 + 100 + 22 + + + + SMBus Adapters: + + + + + + 120 + 10 + 200 + 22 + + + + + + + 50 + 60 + 400 + 200 + + + + + + + 370 + 10 + 80 + 22 + + + + Detect Devices + + + + + +