Add Disconnected mode to Philips Hue Entertainment controller, which allows for disconnecting and reconnecting Entertainment Mode without restarting OpenRGB

This commit is contained in:
Adam Honse
2021-09-21 10:18:38 -05:00
parent f59b637852
commit 9a0faba2f4
3 changed files with 73 additions and 27 deletions

View File

@@ -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;
}
}

View File

@@ -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;
};

View File

@@ -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()