Rudimentary rescanning implemented but button for it not added due to SDK conflicts. Stop detection button.
Commit amended by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
be84a60af6
commit
ec77c658f2
5 changed files with 112 additions and 28 deletions
|
|
@ -23,24 +23,13 @@ ResourceManager::ResourceManager()
|
|||
{
|
||||
detection_percent = 100;
|
||||
detection_string = "";
|
||||
detection_is_required = false;
|
||||
DetectDevicesThread = nullptr;
|
||||
}
|
||||
|
||||
ResourceManager::~ResourceManager()
|
||||
{
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
for(RGBController* rgb_controller : rgb_controllers)
|
||||
{
|
||||
delete rgb_controller;
|
||||
}
|
||||
|
||||
for(i2c_smbus_interface* bus : busses)
|
||||
{
|
||||
delete bus;
|
||||
}
|
||||
|
||||
DetectDevicesThread->join();
|
||||
delete DetectDevicesThread;
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
void ResourceManager::RegisterI2CBus(i2c_smbus_interface *bus)
|
||||
|
|
@ -104,19 +93,59 @@ void ResourceManager::DeviceListChanged()
|
|||
|
||||
unsigned int ResourceManager::GetDetectionPercent()
|
||||
{
|
||||
return(detection_percent);
|
||||
return (detection_percent.load());
|
||||
}
|
||||
|
||||
std::string ResourceManager::GetDetectionString()
|
||||
const char *ResourceManager::GetDetectionString()
|
||||
{
|
||||
return(detection_string);
|
||||
return (detection_string);
|
||||
}
|
||||
|
||||
void ResourceManager::Cleanup()
|
||||
{
|
||||
ResourceManager::get()->WaitForDeviceDetection();
|
||||
|
||||
for(RGBController* rgb_controller : rgb_controllers)
|
||||
{
|
||||
delete rgb_controller;
|
||||
}
|
||||
rgb_controllers.clear();
|
||||
|
||||
for(i2c_smbus_interface* bus : busses)
|
||||
{
|
||||
delete bus;
|
||||
}
|
||||
busses.clear();
|
||||
|
||||
if(DetectDevicesThread)
|
||||
{
|
||||
DetectDevicesThread->join();
|
||||
delete DetectDevicesThread;
|
||||
DetectDevicesThread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::DetectDevices()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Do nothing is it is already detecting devices |
|
||||
\*-------------------------------------------------*/
|
||||
if(detection_is_required.load())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If there's anything left from the last time, |
|
||||
| we shall remove it first |
|
||||
\*-------------------------------------------------*/
|
||||
detection_percent = 0;
|
||||
Cleanup();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Start the device detection thread |
|
||||
\*-------------------------------------------------*/
|
||||
detection_is_required = true;
|
||||
DetectDevicesThread = new std::thread(&ResourceManager::DetectDevicesThreadFunction, this);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
|
|
@ -161,7 +190,7 @@ void ResourceManager::DetectDevicesThreadFunction()
|
|||
/*-------------------------------------------------*\
|
||||
| Detect i2c busses |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int i2c_bus_detector_idx = 0; i2c_bus_detector_idx < i2c_bus_detectors.size(); i2c_bus_detector_idx++)
|
||||
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);
|
||||
}
|
||||
|
|
@ -169,9 +198,9 @@ void ResourceManager::DetectDevicesThreadFunction()
|
|||
/*-------------------------------------------------*\
|
||||
| Detect i2c devices |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int i2c_detector_idx = 0; i2c_detector_idx < i2c_device_detectors.size(); i2c_detector_idx++)
|
||||
for(unsigned int i2c_detector_idx = 0; i2c_detector_idx < i2c_device_detectors.size() && detection_is_required.load(); i2c_detector_idx++)
|
||||
{
|
||||
detection_string = i2c_device_detector_strings[i2c_detector_idx];
|
||||
detection_string = i2c_device_detector_strings[i2c_detector_idx].c_str();
|
||||
DeviceListChanged();
|
||||
|
||||
bool this_device_disabled = false;
|
||||
|
|
@ -207,9 +236,9 @@ void ResourceManager::DetectDevicesThreadFunction()
|
|||
/*-------------------------------------------------*\
|
||||
| Detect other devices |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int detector_idx = 0; detector_idx < device_detectors.size(); detector_idx++)
|
||||
for(unsigned int detector_idx = 0; detector_idx < device_detectors.size() && detection_is_required.load(); detector_idx++)
|
||||
{
|
||||
detection_string = device_detector_strings[detector_idx];
|
||||
detection_string = device_detector_strings[detector_idx].c_str();
|
||||
DeviceListChanged();
|
||||
|
||||
bool this_device_disabled = false;
|
||||
|
|
@ -243,10 +272,26 @@ void ResourceManager::DetectDevicesThreadFunction()
|
|||
}
|
||||
|
||||
profile_manager.LoadSizeFromProfile("sizes.ors");
|
||||
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Make sure that when the detection is done, |
|
||||
| progress bar is set to 100% |
|
||||
\*-------------------------------------------------*/
|
||||
|
||||
detection_is_required = false;
|
||||
detection_percent = 100;
|
||||
detection_string = "";
|
||||
|
||||
DetectDeviceMutex.unlock();
|
||||
}
|
||||
|
||||
void ResourceManager::StopDeviceDetection()
|
||||
{
|
||||
detection_is_required = false;
|
||||
detection_percent = 100;
|
||||
detection_string = "Stopping";
|
||||
}
|
||||
|
||||
void ResourceManager::WaitForDeviceDetection()
|
||||
{
|
||||
DetectDeviceMutex.lock();
|
||||
|
|
|
|||
|
|
@ -36,21 +36,26 @@ public:
|
|||
void RegisterDeviceListChangeCallback(ResourceManagerCallback new_callback, void * new_callback_arg);
|
||||
|
||||
unsigned int GetDetectionPercent();
|
||||
std::string GetDetectionString();
|
||||
const char* GetDetectionString();
|
||||
|
||||
void DeviceListChanged();
|
||||
|
||||
void Cleanup();
|
||||
|
||||
void DetectDevices();
|
||||
|
||||
void DetectDevicesThreadFunction();
|
||||
|
||||
void StopDeviceDetection();
|
||||
|
||||
void WaitForDeviceDetection();
|
||||
|
||||
private:
|
||||
static std::unique_ptr<ResourceManager> instance;
|
||||
|
||||
unsigned int detection_percent;
|
||||
std::string detection_string;
|
||||
std::atomic<bool> detection_is_required;
|
||||
std::atomic<unsigned int> detection_percent;
|
||||
const char* detection_string;
|
||||
|
||||
std::vector<i2c_smbus_interface*> busses;
|
||||
std::vector<RGBController*> rgb_controllers;
|
||||
|
|
|
|||
|
|
@ -167,7 +167,8 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
|
|||
UpdateProfileList();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Update the device list |
|
||||
| Update the device list and make sure the |
|
||||
| ProgressBar gets a proper value |
|
||||
\*-----------------------------------------------------*/
|
||||
UpdateDevicesList();
|
||||
}
|
||||
|
|
@ -292,6 +293,11 @@ void OpenRGBDialog2::ClearDevicesList()
|
|||
|
||||
void OpenRGBDialog2::UpdateDevicesList()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Clear on each update |
|
||||
\*-----------------------------------------------------*/
|
||||
ClearDevicesList();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up list of devices |
|
||||
\*-----------------------------------------------------*/
|
||||
|
|
@ -452,7 +458,6 @@ void OpenRGBDialog2::on_QuickWhite()
|
|||
|
||||
void OpenRGBDialog2::on_ClientListUpdated()
|
||||
{
|
||||
ClearDevicesList();
|
||||
UpdateDevicesList();
|
||||
|
||||
ui->DetectionProgressBar->setValue(ResourceManager::get()->GetDetectionPercent());
|
||||
|
|
@ -462,6 +467,7 @@ void OpenRGBDialog2::on_ClientListUpdated()
|
|||
{
|
||||
ui->DetectionProgressBar->setVisible(false);
|
||||
ui->DetectionProgressLabel->setVisible(false);
|
||||
ui->ButtonStopDetection->setVisible(false);
|
||||
|
||||
ui->ButtonToggleDeviceView->setVisible(true);
|
||||
ui->ButtonLoadProfile->setVisible(true);
|
||||
|
|
@ -618,3 +624,23 @@ void Ui::OpenRGBDialog2::on_ButtonToggleDeviceView_clicked()
|
|||
device_view_showing = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDialog2::on_ButtonStopDetection_clicked()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Notify the detection thread that it has to die |
|
||||
\*---------------------------------------------------------*/
|
||||
ResourceManager::get()->StopDeviceDetection();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Pretend we're done already by hiding the progress bar |
|
||||
\*---------------------------------------------------------*/
|
||||
ui->DetectionProgressBar->setVisible(false);
|
||||
ui->DetectionProgressLabel->setVisible(false);
|
||||
ui->ButtonStopDetection->setVisible(false);
|
||||
|
||||
ui->ButtonLoadProfile->setVisible(true);
|
||||
ui->ButtonSaveProfile->setVisible(true);
|
||||
ui->ButtonDeleteProfile->setVisible(true);
|
||||
ui->ProfileBox->setVisible(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ private slots:
|
|||
void on_ButtonLoadProfile_clicked();
|
||||
void on_ButtonDeleteProfile_clicked();
|
||||
void on_ButtonToggleDeviceView_clicked();
|
||||
void on_ButtonStopDetection_clicked();
|
||||
};
|
||||
|
||||
#endif // OPENRGBDIALOG2_H
|
||||
|
|
|
|||
|
|
@ -116,6 +116,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ButtonStopDetection">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue