Add brightness control for Philips Wiz Lights

This commit is contained in:
Kevin Kuriakose
2023-05-03 11:45:29 +05:30
committed by Adam Honse
parent 85f5cf7140
commit 02b962b2b5
3 changed files with 63 additions and 11 deletions

View File

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

View File

@@ -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<bool> ReceiveThreadRun;
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char brightness;
void SendSetPilot();
};

View File

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