Adds a better white calculation to philips wiz devices

This commit is contained in:
Abdullah Abid Ansari 2024-08-04 23:59:45 +00:00 committed by Adam Honse
parent bd689ee6d7
commit 6140849e28
6 changed files with 74 additions and 28 deletions

View file

@ -15,7 +15,7 @@
using json = nlohmann::json;
using namespace std::chrono_literals;
PhilipsWizController::PhilipsWizController(std::string ip, bool use_cool, bool use_warm)
PhilipsWizController::PhilipsWizController(std::string ip, bool use_cool, bool use_warm, std::string selected_white_strategy)
{
/*-----------------------------------------------------------------*\
| Fill in location string with device's IP address |
@ -27,6 +27,7 @@ PhilipsWizController::PhilipsWizController(std::string ip, bool use_cool, bool u
\*-----------------------------------------------------------------*/
use_cool_white = use_cool;
use_warm_white = use_warm;
white_strategy = selected_white_strategy;
/*-----------------------------------------------------------------*\
| Open a UDP client sending to the device's IP, port 38899 |
@ -85,7 +86,51 @@ std::string PhilipsWizController::GetUniqueID()
void PhilipsWizController::SetColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char brightness)
{
json command;
unsigned char white;
/*-----------------------------------------------------------------*\
| 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 white level based on selected strategy. |
\*-----------------------------------------------------------------*/
if(white_strategy == "Average")
{
white = (red + green + blue) / 3;
}
else if(white_strategy == "Minimum")
{
white = std::min(std::min(red, green), blue);
if(use_cool_white || use_warm_white)
{
red = red - white;
green = green - white;
blue = blue - white;
}
}
else
{
white = 0;
}
if(use_cool_white)
{
command["params"]["c"] = white;
}
else
{
command["params"]["c"] = 0;
}
if(use_warm_white)
{
command["params"]["w"] = white;
}
else
{
command["params"]["w"] = 0;
}
/*-----------------------------------------------------------------*\
| 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,|
@ -97,31 +142,7 @@ void PhilipsWizController::SetColor(unsigned char red, unsigned char green, unsi
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. |
\*-----------------------------------------------------------------*/
if(use_warm_white)
{
command["params"]["w"] = (red + green + blue) / 3;
}
else
{
command["params"]["w"] = 0;
}
if(use_cool_white)
{
command["params"]["c"] = (red + green + blue) / 3;
}
else
{
command["params"]["c"] = 0;
}
command["params"]["state"] = !((red == 0) && (green == 0) && (blue == 0) && (white == 0));
/*-----------------------------------------------------------------*\
| Convert the JSON object to a string and write it |

View file

@ -60,7 +60,7 @@ enum
class PhilipsWizController
{
public:
PhilipsWizController(std::string ip, bool use_cool, bool use_warm);
PhilipsWizController(std::string ip, bool use_cool, bool use_warm, std::string selected_white_strategy);
~PhilipsWizController();
std::string GetLocation();
@ -88,6 +88,7 @@ private:
bool use_cool_white;
bool use_warm_white;
std::string white_strategy;
void SendSetPilot();
};

View file

@ -58,8 +58,13 @@ void DetectPhilipsWizControllers()
{
wiz_warm = wiz_settings["devices"][device_idx]["use_warm_white"];
}
std::string wiz_white_strategy = "Average";
if(wiz_settings["devices"][device_idx].contains("selected_white_strategy"))
{
wiz_white_strategy = wiz_settings["devices"][device_idx]["selected_white_strategy"];
}
PhilipsWizController* controller = new PhilipsWizController(wiz_ip, wiz_cool, wiz_warm);
PhilipsWizController* controller = new PhilipsWizController(wiz_ip, wiz_cool, wiz_warm, wiz_white_strategy);
RGBController_PhilipsWiz* rgb_controller = new RGBController_PhilipsWiz(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);

View file

@ -17,6 +17,9 @@ OpenRGBPhilipsWizSettingsEntry::OpenRGBPhilipsWizSettingsEntry(QWidget *parent)
ui(new Ui::OpenRGBPhilipsWizSettingsEntryUi)
{
ui->setupUi(this);
ui->WhiteStrategyComboBox->addItem(tr("Average"));
ui->WhiteStrategyComboBox->addItem(tr("Minimum"));
}
OpenRGBPhilipsWizSettingsEntry::~OpenRGBPhilipsWizSettingsEntry()

View file

@ -50,6 +50,16 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="WhiteStrategyComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="WhiteStrategyLabel">
<property name="text">
<string>White Strategy:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View file

@ -51,6 +51,11 @@ OpenRGBPhilipsWizSettingsPage::OpenRGBPhilipsWizSettingsPage(QWidget *parent) :
entry->ui->UseWarmWhiteCheckBox->setChecked(wiz_settings["devices"][device_idx]["use_warm_white"]);
}
if(wiz_settings["devices"][device_idx].contains("selected_white_strategy"))
{
entry->ui->WhiteStrategyComboBox->setCurrentText(QString::fromStdString(wiz_settings["devices"][device_idx]["selected_white_strategy"]));
}
entries.push_back(entry);
QListWidgetItem* item = new QListWidgetItem;
@ -128,6 +133,7 @@ void Ui::OpenRGBPhilipsWizSettingsPage::on_SavePhilipsWizConfigurationButton_cli
wiz_settings["devices"][device_idx]["ip"] = entries[device_idx]->ui->IPEdit->text().toStdString();
wiz_settings["devices"][device_idx]["use_cool_white"] = entries[device_idx]->ui->UseCoolWhiteCheckBox->isChecked();
wiz_settings["devices"][device_idx]["use_warm_white"] = entries[device_idx]->ui->UseWarmWhiteCheckBox->isChecked();
wiz_settings["devices"][device_idx]["selected_white_strategy"] = entries[device_idx]->ui->WhiteStrategyComboBox->currentText().toStdString();
}
ResourceManager::get()->GetSettingsManager()->SetSettings("PhilipsWizDevices", wiz_settings);