mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-04-04 06:11:07 -04:00
Add Disconnected mode to Philips Hue Entertainment controller, which allows for disconnecting and reconnecting Entertainment Mode without restarting OpenRGB
This commit is contained in:
@@ -13,24 +13,12 @@ PhilipsHueEntertainmentController::PhilipsHueEntertainmentController(hueplusplus
|
||||
\*-------------------------------------------------*/
|
||||
location = "IP: " + bridge.getBridgeIP();
|
||||
num_leds = group.getLightIds().size();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create Entertainment Mode from bridge and group |
|
||||
\*-------------------------------------------------*/
|
||||
entertainment = new hueplusplus::EntertainmentMode(bridge, group);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Connect Hue Entertainment Mode |
|
||||
\*-------------------------------------------------*/
|
||||
entertainment->connect();
|
||||
connected = false;
|
||||
}
|
||||
|
||||
PhilipsHueEntertainmentController::~PhilipsHueEntertainmentController()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Disconnect Hue Entertainment Mode |
|
||||
\*-------------------------------------------------*/
|
||||
entertainment->disconnect();
|
||||
|
||||
}
|
||||
|
||||
std::string PhilipsHueEntertainmentController::GetLocation()
|
||||
@@ -65,18 +53,52 @@ unsigned int PhilipsHueEntertainmentController::GetNumLEDs()
|
||||
|
||||
void PhilipsHueEntertainmentController::SetColor(RGBColor* colors)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Fill in Entertainment Mode light data |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int light_idx = 0; light_idx < num_leds; light_idx++)
|
||||
if(connected)
|
||||
{
|
||||
RGBColor color = colors[light_idx];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char green = RGBGetGValue(color);
|
||||
unsigned char blue = RGBGetBValue(color);
|
||||
/*-------------------------------------------------*\
|
||||
| Fill in Entertainment Mode light data |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int light_idx = 0; light_idx < num_leds; light_idx++)
|
||||
{
|
||||
RGBColor color = colors[light_idx];
|
||||
unsigned char red = RGBGetRValue(color);
|
||||
unsigned char green = RGBGetGValue(color);
|
||||
unsigned char blue = RGBGetBValue(color);
|
||||
|
||||
entertainment->setColorRGB(light_idx, red, green, blue);
|
||||
entertainment->setColorRGB(light_idx, red, green, blue);
|
||||
}
|
||||
|
||||
entertainment->update();
|
||||
}
|
||||
|
||||
entertainment->update();
|
||||
}
|
||||
|
||||
void PhilipsHueEntertainmentController::Connect()
|
||||
{
|
||||
if(!connected)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Create Entertainment Mode from bridge and group |
|
||||
\*-------------------------------------------------*/
|
||||
entertainment = new hueplusplus::EntertainmentMode(bridge, group);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Connect Hue Entertainment Mode |
|
||||
\*-------------------------------------------------*/
|
||||
entertainment->connect();
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
|
||||
void PhilipsHueEntertainmentController::Disconnect()
|
||||
{
|
||||
if(connected)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Disconnect Hue Entertainment Mode |
|
||||
\*-------------------------------------------------*/
|
||||
entertainment->disconnect();
|
||||
connected = false;
|
||||
|
||||
delete entertainment;
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ public:
|
||||
|
||||
void SetColor(RGBColor* colors);
|
||||
|
||||
void Connect();
|
||||
void Disconnect();
|
||||
|
||||
private:
|
||||
hueplusplus::Bridge& bridge;
|
||||
hueplusplus::Group group;
|
||||
@@ -39,4 +42,5 @@ private:
|
||||
|
||||
std::string location;
|
||||
unsigned int num_leds;
|
||||
bool connected;
|
||||
};
|
||||
|
||||
@@ -29,8 +29,18 @@ RGBController_PhilipsHueEntertainment::RGBController_PhilipsHueEntertainment(Phi
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Disconnected;
|
||||
Disconnected.name = "Disconnected";
|
||||
Disconnected.value = 1;
|
||||
Disconnected.flags = 0;
|
||||
Disconnected.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Disconnected);
|
||||
|
||||
SetupZones();
|
||||
|
||||
active_mode = 0;
|
||||
light->Connect();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| The Philips Hue Entertainment Mode requires a packet |
|
||||
| within 10 seconds of sending the lighting change in |
|
||||
@@ -74,7 +84,10 @@ void RGBController_PhilipsHueEntertainment::DeviceUpdateLEDs()
|
||||
{
|
||||
last_update_time = std::chrono::steady_clock::now();
|
||||
|
||||
light->SetColor(&colors[0]);
|
||||
if(active_mode == 0)
|
||||
{
|
||||
light->SetColor(&colors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_PhilipsHueEntertainment::UpdateZoneLEDs(int /*zone*/)
|
||||
@@ -94,7 +107,14 @@ void RGBController_PhilipsHueEntertainment::SetCustomMode()
|
||||
|
||||
void RGBController_PhilipsHueEntertainment::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
if(active_mode == 0)
|
||||
{
|
||||
light->Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
light->Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_PhilipsHueEntertainment::KeepaliveThreadFunction()
|
||||
|
||||
Reference in New Issue
Block a user