diff --git a/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.cpp b/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.cpp index 34bfa627..a2ae194c 100644 --- a/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.cpp +++ b/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.cpp @@ -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; + } +} \ No newline at end of file diff --git a/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.h b/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.h index 8bbef2c4..f6d95819 100644 --- a/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.h +++ b/Controllers/PhilipsHueController/PhilipsHueEntertainmentController.h @@ -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; }; diff --git a/Controllers/PhilipsHueController/RGBController_PhilipsHueEntertainment.cpp b/Controllers/PhilipsHueController/RGBController_PhilipsHueEntertainment.cpp index bf72d748..d0cf53d2 100644 --- a/Controllers/PhilipsHueController/RGBController_PhilipsHueEntertainment.cpp +++ b/Controllers/PhilipsHueController/RGBController_PhilipsHueEntertainment.cpp @@ -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()