Move Profile Manager to Resource Manager and rework size loading so that sizes are updated upon redetection

This commit is contained in:
Adam Honse 2020-10-08 17:07:39 -05:00
parent e767b3db90
commit e52619dbab
5 changed files with 62 additions and 13 deletions

View file

@ -44,6 +44,12 @@ ResourceManager::ResourceManager()
| Initialize Server Instance |
\*-------------------------------------------------------------------------*/
server = new NetworkServer(rgb_controllers_hw);
/*-------------------------------------------------------------------------*\
| Load sizes list from file |
\*-------------------------------------------------------------------------*/
profile_manager = new ProfileManager(rgb_controllers);
rgb_controllers_sizes = profile_manager->LoadProfileToList("sizes.ors");
}
ResourceManager::~ResourceManager()
@ -184,6 +190,11 @@ std::vector<NetworkClient*>& ResourceManager::GetClients()
return(clients);
}
ProfileManager* ResourceManager::GetProfileManager()
{
return(profile_manager);
}
unsigned int ResourceManager::GetDetectionPercent()
{
return (detection_percent.load());
@ -275,8 +286,17 @@ void ResourceManager::DetectDevices()
void ResourceManager::DetectDevicesThreadFunction()
{
DetectDeviceMutex.lock();
unsigned int prev_count = 0;
float percent = 0.0f;
unsigned int prev_count = 0;
float percent = 0.0f;
std::vector<bool> size_used;
size_used.resize(rgb_controllers_sizes.size());
for(unsigned int size_idx = 0; size_idx < size_used.size(); size_idx++)
{
size_used[size_idx] = false;
}
std::vector<std::string> disabled_devices_list;
@ -297,8 +317,6 @@ void ResourceManager::DetectDevicesThreadFunction()
infile.close();
ProfileManager profile_manager(rgb_controllers);
/*-------------------------------------------------*\
| Start at 0% detection progress |
\*-------------------------------------------------*/
@ -341,6 +359,14 @@ void ResourceManager::DetectDevicesThreadFunction()
\*-------------------------------------------------*/
if(rgb_controllers_hw.size() != prev_count)
{
/*-------------------------------------------------*\
| First, load sizes for the new controllers |
\*-------------------------------------------------*/
for(unsigned int controller_size_idx = prev_count - 1; controller_size_idx < rgb_controllers_hw.size(); controller_size_idx++)
{
profile_manager->LoadDeviceFromListWithOptions(rgb_controllers_sizes, size_used, rgb_controllers_hw[controller_size_idx], true, false);
}
DeviceListChanged();
}
prev_count = rgb_controllers_hw.size();
@ -379,6 +405,14 @@ void ResourceManager::DetectDevicesThreadFunction()
\*-------------------------------------------------*/
if(rgb_controllers_hw.size() != prev_count)
{
/*-------------------------------------------------*\
| First, load sizes for the new controllers |
\*-------------------------------------------------*/
for(unsigned int controller_size_idx = prev_count - 1; controller_size_idx < rgb_controllers_hw.size(); controller_size_idx++)
{
profile_manager->LoadDeviceFromListWithOptions(rgb_controllers_sizes, size_used, rgb_controllers_hw[controller_size_idx], true, false);
}
DeviceListChanged();
}
prev_count = rgb_controllers_hw.size();
@ -388,8 +422,6 @@ void ResourceManager::DetectDevicesThreadFunction()
detection_percent = percent * 100.0f;
}
profile_manager.LoadSizeFromProfile("sizes.ors");
/*-------------------------------------------------*\
| Make sure that when the detection is done, |
| progress bar is set to 100% |

View file

@ -20,6 +20,7 @@
#include "i2c_smbus.h"
#include "NetworkClient.h"
#include "NetworkServer.h"
#include "ProfileManager.h"
#include "RGBController.h"
typedef std::function<void(std::vector<i2c_smbus_interface*>&)> I2CBusDetectorFunction;
@ -56,6 +57,8 @@ public:
std::vector<NetworkClient*>& GetClients();
NetworkServer* GetServer();
ProfileManager* GetProfileManager();
void DeviceListChanged();
void DetectionProgressChanged();
@ -72,6 +75,11 @@ public:
private:
static std::unique_ptr<ResourceManager> instance;
/*-------------------------------------------------------------------------------------*\
| Profile Manager |
\*-------------------------------------------------------------------------------------*/
ProfileManager* profile_manager;
/*-------------------------------------------------------------------------------------*\
| I2C/SMBus Interfaces |
\*-------------------------------------------------------------------------------------*/
@ -80,6 +88,7 @@ private:
/*-------------------------------------------------------------------------------------*\
| RGBControllers |
\*-------------------------------------------------------------------------------------*/
std::vector<RGBController*> rgb_controllers_sizes;
std::vector<RGBController*> rgb_controllers_hw;
std::vector<RGBController*> rgb_controllers;

View file

@ -146,8 +146,6 @@ int main(int argc, char* argv[])
std::vector<i2c_smbus_interface*> &busses = ResourceManager::get()->GetI2CBusses();
std::vector<RGBController*> &rgb_controllers = ResourceManager::get()->GetRGBControllers();
ProfileManager profile_manager(rgb_controllers);
if(!AttemptLocalConnection(rgb_controllers))
{
@ -160,7 +158,7 @@ int main(int argc, char* argv[])
unsigned int ret_flags = RET_FLAG_START_GUI;
if(argc > 1)
{
ret_flags = cli_main(argc, argv, rgb_controllers, &profile_manager);
ret_flags = cli_main(argc, argv, rgb_controllers, ResourceManager::get()->GetProfileManager());
}
/*---------------------------------------------------------*\
@ -173,7 +171,7 @@ int main(int argc, char* argv[])
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication a(argc, argv);
Ui::OpenRGBDialog2 dlg(busses, rgb_controllers, &profile_manager);
Ui::OpenRGBDialog2 dlg(busses, rgb_controllers);
if(ret_flags & RET_FLAG_I2C_TOOLS)
{

View file

@ -76,7 +76,7 @@ static void UpdateDetectionProgressCallback(void * this_ptr)
QMetaObject::invokeMethod(this_obj, "onDetectionProgressUpdated", Qt::QueuedConnection);
}
OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager* manager, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), profile_manager(manager), ui(new OpenRGBDialog2Ui)
OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), ui(new OpenRGBDialog2Ui)
{
ui->setupUi(this);
@ -487,6 +487,8 @@ void OpenRGBDialog2::UpdateDevicesList()
void OpenRGBDialog2::UpdateProfileList()
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
/*-----------------------------------------------------*\
@ -594,6 +596,8 @@ void OpenRGBDialog2::on_SetAllDevices(unsigned char red, unsigned char green, un
void OpenRGBDialog2::on_SaveSizeProfile()
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
/*---------------------------------------------------------*\
@ -617,6 +621,8 @@ void OpenRGBDialog2::on_ShowHide()
void Ui::OpenRGBDialog2::on_ProfileSelected()
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
/*---------------------------------------------------------*\
@ -640,6 +646,7 @@ void Ui::OpenRGBDialog2::on_ProfileSelected()
void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked()
{
OpenRGBProfileSaveDialog dialog;
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
@ -665,6 +672,8 @@ void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked()
void Ui::OpenRGBDialog2::on_ButtonLoadProfile_clicked()
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
/*---------------------------------------------------------*\
@ -687,6 +696,8 @@ void Ui::OpenRGBDialog2::on_ButtonLoadProfile_clicked()
void Ui::OpenRGBDialog2::on_ButtonDeleteProfile_clicked()
{
ProfileManager* profile_manager = ResourceManager::get()->GetProfileManager();
if(profile_manager != NULL)
{
/*---------------------------------------------------------*\

View file

@ -29,7 +29,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow
Q_OBJECT
public:
explicit OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager* manager, QWidget *parent = 0);
explicit OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, QWidget *parent = 0);
~OpenRGBDialog2();
void AddClient(NetworkClient* new_client);
@ -42,7 +42,6 @@ public:
protected:
std::vector<i2c_smbus_interface *>& busses;
std::vector<RGBController *>& controllers;
ProfileManager* profile_manager;
private:
/*-------------------------------------*\