diff --git a/Controllers/PhilipsWizController/PhilipsWizController.cpp b/Controllers/PhilipsWizController/PhilipsWizController.cpp index babfe55d7..34a462f15 100644 --- a/Controllers/PhilipsWizController/PhilipsWizController.cpp +++ b/Controllers/PhilipsWizController/PhilipsWizController.cpp @@ -17,6 +17,14 @@ PhilipsWizController::PhilipsWizController(std::string ip) \*-----------------------------------------------------------------*/ location = "IP: " + ip; + /*-----------------------------------------------------------------*\ + | Set a few sane default values | + \*-----------------------------------------------------------------*/ + red = 0; + green = 0; + blue = 0; + brightness = 100; + /*-----------------------------------------------------------------*\ | Open a UDP client sending to the device's IP, port 38899 | \*-----------------------------------------------------------------*/ @@ -67,19 +75,45 @@ std::string PhilipsWizController::GetUniqueID() } void PhilipsWizController::SetColor(unsigned char red, unsigned char green, unsigned char blue) +{ + this->red = red; + this->green = green; + this->blue = blue; + + SendSetPilot(); +} + +void PhilipsWizController::SetBrightness(unsigned char brightness) +{ + this->brightness = brightness; + + SendSetPilot(); +} + +void PhilipsWizController::SendSetPilot() { json command; /*-----------------------------------------------------------------*\ - | Fill in the setPilot command with RGB information. | + | Fill in the setPilot command with RGB and brightness information. | | The bulb will not respond to 0, 0, 0, so if all channels are zero,| | set the state to off. Otherwise, set it to on. | \*-----------------------------------------------------------------*/ - command["method"] = "setPilot"; - command["params"]["r"] = red; - command["params"]["g"] = green; - command["params"]["b"] = blue; - command["params"]["state"] = !((red == 0) && (green == 0) && (blue == 0)); + command["method"] = "setPilot"; + command["params"]["r"] = red; + command["params"]["g"] = green; + command["params"]["b"] = blue; + command["params"]["dimming"] = brightness; + command["params"]["state"] = !((red == 0) && (green == 0) && (blue == 0)); + + /*-----------------------------------------------------------------*\ + | The official Wiz app also sends a warm white level with its | + | custom colours. Until we can figure out a way to account for it | + | correctly, set the cool white level to the average of RGB to | + | improve its apparent brightness. | + \*-----------------------------------------------------------------*/ + command["params"]["c"] = (red + green + blue) / 3; +// command["params"]["w"] = 0; /*-----------------------------------------------------------------*\ | Convert the JSON object to a string and write it | diff --git a/Controllers/PhilipsWizController/PhilipsWizController.h b/Controllers/PhilipsWizController/PhilipsWizController.h index 0653c901e..27c2c8d87 100644 --- a/Controllers/PhilipsWizController/PhilipsWizController.h +++ b/Controllers/PhilipsWizController/PhilipsWizController.h @@ -25,6 +25,7 @@ public: std::string GetManufacturer(); std::string GetUniqueID(); + void SetBrightness(unsigned char brightness); void SetColor(unsigned char red, unsigned char green, unsigned char blue); void ReceiveThreadFunction(); @@ -38,4 +39,11 @@ private: net_port port; std::thread* ReceiveThread; std::atomic ReceiveThreadRun; + + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char brightness; + + void SendSetPilot(); }; diff --git a/Controllers/PhilipsWizController/RGBController_PhilipsWiz.cpp b/Controllers/PhilipsWizController/RGBController_PhilipsWiz.cpp index 0b342edd2..d75fbb2d9 100644 --- a/Controllers/PhilipsWizController/RGBController_PhilipsWiz.cpp +++ b/Controllers/PhilipsWizController/RGBController_PhilipsWiz.cpp @@ -32,10 +32,13 @@ RGBController_PhilipsWiz::RGBController_PhilipsWiz(PhilipsWizController* control location = controller->GetLocation(); mode Direct; - Direct.name = "Direct"; - Direct.value = 0; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; - Direct.color_mode = MODE_COLORS_PER_LED; + Direct.name = "Direct"; + Direct.value = 0; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Direct.color_mode = MODE_COLORS_PER_LED; + Direct.brightness = 100; + Direct.brightness_min = 10; + Direct.brightness_max = 100; modes.push_back(Direct); SetupZones(); @@ -93,5 +96,12 @@ void RGBController_PhilipsWiz::UpdateSingleLED(int /*led*/) void RGBController_PhilipsWiz::DeviceUpdateMode() { - + if(modes[active_mode].flags & MODE_FLAG_HAS_BRIGHTNESS) + { + controller->SetBrightness(modes[active_mode].brightness); + } + else + { + controller->SetBrightness(100); + } }