diff --git a/ResourceManager.cpp b/ResourceManager.cpp index e7648d76..dcc8de23 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -130,6 +130,12 @@ void ResourceManager::RegisterDeviceListChangeCallback(DeviceListChangeCallback DeviceListChangeCallbackArgs.push_back(new_callback_arg); } +void ResourceManager::RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback, void * new_callback_arg) +{ + I2CBusListChangeCallbacks.push_back(new_callback); + I2CBusListChangeCallbackArgs.push_back(new_callback_arg); +} + void ResourceManager::RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void *new_callback_arg) { DetectionProgressCallbacks.push_back(new_callback); @@ -209,6 +215,21 @@ void ResourceManager::DetectionProgressChanged() DetectionProgressMutex.unlock(); } +void ResourceManager::I2CBusListChanged() +{ + I2CBusListChangeMutex.lock(); + + /*-------------------------------------------------*\ + | Detection progress has changed, call the callbacks| + \*-------------------------------------------------*/ + for(unsigned int callback_idx = 0; callback_idx < I2CBusListChangeCallbacks.size(); callback_idx++) + { + I2CBusListChangeCallbacks[callback_idx](I2CBusListChangeCallbackArgs[callback_idx]); + } + + I2CBusListChangeMutex.unlock(); +} + std::string ResourceManager::GetConfigurationDirectory() { std::string config_dir = ""; @@ -439,6 +460,7 @@ void ResourceManager::DetectDevicesThreadFunction() for(unsigned int i2c_bus_detector_idx = 0; i2c_bus_detector_idx < i2c_bus_detectors.size() && detection_is_required.load(); i2c_bus_detector_idx++) { i2c_bus_detectors[i2c_bus_detector_idx](busses); + I2CBusListChanged(); } /*-------------------------------------------------*\ diff --git a/ResourceManager.h b/ResourceManager.h index b474535a..976ac42b 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -48,6 +48,7 @@ typedef struct typedef void (*DeviceListChangeCallback)(void *); typedef void (*DetectionProgressCallback)(void *); +typedef void (*I2CBusListChangeCallback)(void *); class ResourceManager { @@ -77,6 +78,7 @@ public: void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg); void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void * new_callback_arg); + void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback, void * new_callback_arg); unsigned int GetDetectionPercent(); const char* GetDetectionString(); @@ -93,6 +95,7 @@ public: void DeviceListChanged(); void DetectionProgressChanged(); + void I2CBusListChanged(); void Cleanup(); @@ -171,6 +174,13 @@ private: | Detection Progress Callback | \*-------------------------------------------------------------------------------------*/ std::mutex DetectionProgressMutex; - std::vector DetectionProgressCallbacks; + std::vector DetectionProgressCallbacks; std::vector DetectionProgressCallbackArgs; + + /*-------------------------------------------------------------------------------------*\ + | I2C/SMBus Adapter List Changed Callback | + \*-------------------------------------------------------------------------------------*/ + std::mutex I2CBusListChangeMutex; + std::vector I2CBusListChangeCallbacks; + std::vector I2CBusListChangeCallbackArgs; }; diff --git a/qt/OpenRGBSystemInfoPage.cpp b/qt/OpenRGBSystemInfoPage.cpp index b7c9b233..32fe00e0 100644 --- a/qt/OpenRGBSystemInfoPage.cpp +++ b/qt/OpenRGBSystemInfoPage.cpp @@ -1,8 +1,16 @@ #include "OpenRGBSystemInfoPage.h" +#include "ResourceManager.h" #include "i2c_tools.h" using namespace Ui; +static void UpdateBusListCallback(void * this_ptr) +{ + OpenRGBSystemInfoPage * this_obj = (OpenRGBSystemInfoPage *)this_ptr; + + QMetaObject::invokeMethod(this_obj, "UpdateBusList", Qt::QueuedConnection); +} + OpenRGBSystemInfoPage::OpenRGBSystemInfoPage(std::vector& bus, QWidget *parent) : QFrame(parent), ui(new Ui::OpenRGBSystemInfoPageUi), @@ -18,16 +26,14 @@ OpenRGBSystemInfoPage::OpenRGBSystemInfoPage(std::vector& ui->SMBusDataText->setFont(MonoFont); /*-----------------------------------------------------*\ - | Fill in the combo boxes with device information | + | Register I2C bus list change callback | \*-----------------------------------------------------*/ - ui->SMBusAdaptersBox->clear(); + ResourceManager::get()->RegisterI2CBusListChangeCallback(UpdateBusListCallback, this); - for (std::size_t i = 0; i < busses.size(); i++) - { - ui->SMBusAdaptersBox->addItem(busses[i]->device_name); - } - - ui->SMBusAdaptersBox->setCurrentIndex(0); + /*-----------------------------------------------------*\ + | Update the bus list | + \*-----------------------------------------------------*/ + UpdateBusList(); ui->SMBusDetectionModeBox->addItem("Auto"); ui->SMBusDetectionModeBox->addItem("Quick"); @@ -41,6 +47,21 @@ OpenRGBSystemInfoPage::~OpenRGBSystemInfoPage() delete ui; } +void Ui::OpenRGBSystemInfoPage::UpdateBusList() +{ + /*-----------------------------------------------------*\ + | Fill in the combo boxes with device information | + \*-----------------------------------------------------*/ + ui->SMBusAdaptersBox->clear(); + + for (std::size_t i = 0; i < busses.size(); i++) + { + ui->SMBusAdaptersBox->addItem(busses[i]->device_name); + } + + ui->SMBusAdaptersBox->setCurrentIndex(0); +} + void Ui::OpenRGBSystemInfoPage::on_DetectButton_clicked() { int current_index = ui->SMBusAdaptersBox->currentIndex(); diff --git a/qt/OpenRGBSystemInfoPage.h b/qt/OpenRGBSystemInfoPage.h index a3494679..bc6255cd 100644 --- a/qt/OpenRGBSystemInfoPage.h +++ b/qt/OpenRGBSystemInfoPage.h @@ -17,6 +17,9 @@ public: explicit OpenRGBSystemInfoPage(std::vector& bus, QWidget *parent = nullptr); ~OpenRGBSystemInfoPage(); +public slots: + void UpdateBusList(); + private slots: void on_DetectButton_clicked();