Fix I2C tools by adding I2C bus list change callback to resource manager

This commit is contained in:
Adam Honse 2020-12-02 00:08:15 -06:00
parent ddfcd1caf9
commit 3345fe6562
4 changed files with 65 additions and 9 deletions

View file

@ -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();
}
/*-------------------------------------------------*\

View file

@ -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<DeviceListChangeCallback> DetectionProgressCallbacks;
std::vector<DetectionProgressCallback> DetectionProgressCallbacks;
std::vector<void *> DetectionProgressCallbackArgs;
/*-------------------------------------------------------------------------------------*\
| I2C/SMBus Adapter List Changed Callback |
\*-------------------------------------------------------------------------------------*/
std::mutex I2CBusListChangeMutex;
std::vector<I2CBusListChangeCallback> I2CBusListChangeCallbacks;
std::vector<void *> I2CBusListChangeCallbackArgs;
};

View file

@ -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<i2c_smbus_interface *>& bus, QWidget *parent) :
QFrame(parent),
ui(new Ui::OpenRGBSystemInfoPageUi),
@ -18,16 +26,14 @@ OpenRGBSystemInfoPage::OpenRGBSystemInfoPage(std::vector<i2c_smbus_interface *>&
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();

View file

@ -17,6 +17,9 @@ public:
explicit OpenRGBSystemInfoPage(std::vector<i2c_smbus_interface *>& bus, QWidget *parent = nullptr);
~OpenRGBSystemInfoPage();
public slots:
void UpdateBusList();
private slots:
void on_DetectButton_clicked();