mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-03-06 15:18:51 -05:00
Move HID detector calls to RunHIDDetector/RunHIDWrappedDetector functions and return controller list from detector functions
This commit is contained in:
@@ -22,42 +22,35 @@
|
||||
#include "LogManager.h"
|
||||
#include "PhilipsHueController.h"
|
||||
#include "PhilipsHueEntertainmentController.h"
|
||||
#include "PhilipsHueSettingsHandler.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "RGBController_PhilipsHue.h"
|
||||
#include "RGBController_PhilipsHueEntertainment.h"
|
||||
#include "PhilipsHueSettingsHandler.h"
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectPhilipsHueControllers *
|
||||
* *
|
||||
* Detect Philips Hue lighting devices with RGB control *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectPhilipsHueControllers()
|
||||
DetectedControllers DetectPhilipsHueControllers()
|
||||
{
|
||||
PhilipsHueSettingsHandler hue_settings;
|
||||
DetectedControllers detected_controllers;
|
||||
PhilipsHueSettingsHandler hue_settings;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create an HTTP handler |
|
||||
\*-------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Create an HTTP handler |
|
||||
\*-----------------------------------------------------*/
|
||||
#ifdef _WIN32
|
||||
using SystemHttpHandler = hueplusplus::WinHttpHandler;
|
||||
#else
|
||||
using SystemHttpHandler = hueplusplus::LinHttpHandler;
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create a finder and find bridges |
|
||||
\*-------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| Create a finder and find bridges |
|
||||
\*-----------------------------------------------------*/
|
||||
static hueplusplus::BridgeFinder finder(std::make_shared<SystemHttpHandler>());
|
||||
std::vector<hueplusplus::BridgeFinder::BridgeIdentification> bridges;// = finder.findBridges();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If no bridges were detected, manually add bridge |
|
||||
| IP and MAC (need to get these from file) |
|
||||
\*-------------------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| If no bridges were detected, manually add bridge IP |
|
||||
| and MAC (need to get these from file) |
|
||||
\*-----------------------------------------------------*/
|
||||
if(hue_settings.GetBridgeCount() > 0)
|
||||
{
|
||||
hueplusplus::BridgeFinder::BridgeIdentification ident;
|
||||
@@ -68,32 +61,27 @@ void DetectPhilipsHueControllers()
|
||||
bridges.push_back(ident);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If no bridges were found, return, otherwise |
|
||||
| connect to the first bridge |
|
||||
\*-------------------------------------------------*/
|
||||
if(bridges.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
/*-----------------------------------------------------*\
|
||||
| If bridges were found, connect to the first bridge |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!bridges.empty())
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Check if a saved username exists |
|
||||
\*-------------------------------------------------*/
|
||||
if(hue_settings.GetBridgeCount() > 0)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Add the username if it exists |
|
||||
\*-------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Add the username if it exists |
|
||||
\*---------------------------------------------*/
|
||||
if(hue_settings.BridgeHasUsername(0))
|
||||
{
|
||||
finder.addUsername(bridges[0].mac, hue_settings.GetBridgeUsername(0));
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Add the client key if it exists |
|
||||
\*-------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Add the client key if it exists |
|
||||
\*---------------------------------------------*/
|
||||
if(hue_settings.BridgeHasClientKey(0))
|
||||
{
|
||||
finder.addClientKey(bridges[0].mac, hue_settings.GetBridgeClientKey(0));
|
||||
@@ -111,11 +99,12 @@ void DetectPhilipsHueControllers()
|
||||
|
||||
bridge.refresh();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Check to see if we need to save the settings |
|
||||
| Settings need to be saved if either username or |
|
||||
| client key either do not exist or have changed |
|
||||
\*-------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Check to see if we need to save the settings |
|
||||
| Settings need to be saved if either username |
|
||||
| or client key either do not exist or have |
|
||||
| changed |
|
||||
\*---------------------------------------------*/
|
||||
bool save_settings = false;
|
||||
bool use_entertainment = false;
|
||||
bool auto_connect = false;
|
||||
@@ -148,9 +137,9 @@ void DetectPhilipsHueControllers()
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Save the settings if needed |
|
||||
\*-------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Save the settings if needed |
|
||||
\*---------------------------------------------*/
|
||||
if(save_settings)
|
||||
{
|
||||
hue_settings.SetBridgeUsername(0, bridge.getUsername());
|
||||
@@ -160,25 +149,26 @@ void DetectPhilipsHueControllers()
|
||||
hue_settings.SaveSettings();
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get entertainment mode settings |
|
||||
\*-------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Get entertainment mode settings |
|
||||
\*---------------------------------------------*/
|
||||
use_entertainment = hue_settings.GetBridgeUseEntertainment(0);
|
||||
auto_connect = hue_settings.GetBridgeAutoconnect(0);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get all groups from the bridge |
|
||||
\*-------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Get all groups from the bridge |
|
||||
\*---------------------------------------------*/
|
||||
if(use_entertainment)
|
||||
{
|
||||
std::vector<hueplusplus::Group> groups = bridge.groups().getAll();
|
||||
|
||||
if(groups.size() > 0)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Loop through all available groups and check to |
|
||||
| see if any are Entertainment groups |
|
||||
\*-------------------------------------------------*/
|
||||
/*-------------------------------------*\
|
||||
| Loop through all available groups and |
|
||||
| check to see if any are Entertainment |
|
||||
| groups |
|
||||
\*-------------------------------------*/
|
||||
for(unsigned int group_idx = 0; group_idx < groups.size(); group_idx++)
|
||||
{
|
||||
if(groups[group_idx].getType() == "Entertainment")
|
||||
@@ -186,42 +176,45 @@ void DetectPhilipsHueControllers()
|
||||
PhilipsHueEntertainmentController* controller = new PhilipsHueEntertainmentController(bridge, groups[group_idx]);
|
||||
RGBController_PhilipsHueEntertainment* rgb_controller = new RGBController_PhilipsHueEntertainment(controller);
|
||||
|
||||
DetectionManager::get()->RegisterRGBController(rgb_controller);
|
||||
detected_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Loop through RGB Controllers to find the first |
|
||||
| Entertainment group and Set it to "Connect", |
|
||||
| as only one Stream can be open at a time. |
|
||||
\*-------------------------------------------------*/
|
||||
if(auto_connect)
|
||||
{
|
||||
for(unsigned int controller_idx = 0; controller_idx < ResourceManager::get()->GetRGBControllers().size(); controller_idx++)
|
||||
{
|
||||
if(ResourceManager::get()->GetRGBControllers()[controller_idx]->GetDescription() == "Philips Hue Entertainment Mode Device")
|
||||
{
|
||||
ResourceManager::get()->GetRGBControllers()[controller_idx]->SetActiveMode(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-------------------------------------*\
|
||||
| Loop through RGB Controllers to find |
|
||||
| the first Entertainment group and Set |
|
||||
| it to "Connect", as only one Stream |
|
||||
| can be open at a time. |
|
||||
| TODO: investigate this and rework |
|
||||
\*-------------------------------------*/
|
||||
//f(auto_connect)
|
||||
//
|
||||
// for(unsigned int controller_idx = 0; controller_idx < ResourceManager::get()->GetRGBControllers().size(); controller_idx++)
|
||||
// {
|
||||
// if(ResourceManager::get()->GetRGBControllers()[controller_idx]->GetDescription() == "Philips Hue Entertainment Mode Device")
|
||||
// {
|
||||
// ResourceManager::get()->GetRGBControllers()[controller_idx]->SetActiveMode(0);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get all lights from the bridge |
|
||||
\*-------------------------------------------------*/
|
||||
/*---------------------------------------------*\
|
||||
| Get all lights from the bridge |
|
||||
\*---------------------------------------------*/
|
||||
else
|
||||
{
|
||||
std::vector<hueplusplus::Light> lights = bridge.lights().getAll();
|
||||
|
||||
if(lights.size() > 0)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Loop through all available lights and add those |
|
||||
| that have color (RGB) control capability |
|
||||
\*-------------------------------------------------*/
|
||||
/*-------------------------------------*\
|
||||
| Loop through all available lights and |
|
||||
| add those that have color (RGB) |
|
||||
| control capability |
|
||||
\*-------------------------------------*/
|
||||
for(unsigned int light_idx = 0; light_idx < lights.size(); light_idx++)
|
||||
{
|
||||
if(lights[light_idx].hasColorControl())
|
||||
@@ -229,7 +222,7 @@ void DetectPhilipsHueControllers()
|
||||
PhilipsHueController* controller = new PhilipsHueController(lights[light_idx], bridge.getBridgeIP());
|
||||
RGBController_PhilipsHue* rgb_controller = new RGBController_PhilipsHue(controller);
|
||||
|
||||
DetectionManager::get()->RegisterRGBController(rgb_controller);
|
||||
detected_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,6 +233,8 @@ void DetectPhilipsHueControllers()
|
||||
LOG_INFO("Exception occurred in Philips Hue detection: %s", e.what());
|
||||
}
|
||||
}
|
||||
} /* DetectPhilipsHueControllers() */
|
||||
|
||||
return(detected_controllers);
|
||||
}
|
||||
|
||||
REGISTER_DETECTOR("Philips Hue", DetectPhilipsHueControllers);
|
||||
|
||||
Reference in New Issue
Block a user