Publish LumaOps source

This commit is contained in:
LumaOps release export
2026-09-03 01:18:36 +02:00
commit 7f1c0e5f71
2363 changed files with 501543 additions and 0 deletions
@@ -0,0 +1,87 @@
/*---------------------------------------------------------*\
| PhilipsHueController.cpp |
| |
| Driver for Philips Hue |
| |
| Adam Honse (calcprogrammer1@gmail.com) 15 Sep 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "PhilipsHueController.h"
#include "LogManager.h"
PhilipsHueController::PhilipsHueController(hueplusplus::Light light_ptr, std::string bridge_ip):light(light_ptr)
{
dark = false;
location = "IP: " + bridge_ip;
}
PhilipsHueController::~PhilipsHueController()
{
}
std::string PhilipsHueController::GetLocation()
{
return(location);
}
std::string PhilipsHueController::GetName()
{
return(light.getModelId());
}
std::string PhilipsHueController::GetVersion()
{
return(light.getSwVersion());
}
std::string PhilipsHueController::GetManufacturer()
{
return(light.getManufacturername());
}
std::string PhilipsHueController::GetUniqueID()
{
return(light.getUId());
}
void PhilipsHueController::SetColor(unsigned char red, unsigned char green, unsigned char blue)
{
hueplusplus::RGB rgb;
rgb.r = red;
rgb.g = green;
rgb.b = blue;
if((red == 0) && (green == 0) && (blue == 0))
{
if(!dark)
{
try
{
light.setColorRGB(rgb, 0);
}
catch(const std::exception& e)
{
LOG_ERROR("[PhilipsHueController] An error occured while setting the colors: %s", e.what());
}
}
dark = true;
}
else
{
dark = false;
try
{
light.setColorRGB(rgb, 0);
}
catch(std::exception& e)
{
LOG_ERROR("[PhilipsHueController] An error occured while setting the colors: %s", e.what());
}
}
}
@@ -0,0 +1,36 @@
/*---------------------------------------------------------*\
| PhilipsHueController.h |
| |
| Driver for Philips Hue |
| |
| Adam Honse (calcprogrammer1@gmail.com) 15 Sep 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <string>
#include <vector>
#include "HueDeviceTypes.h"
class PhilipsHueController
{
public:
PhilipsHueController(hueplusplus::Light light_ptr, std::string bridge_ip);
~PhilipsHueController();
std::string GetLocation();
std::string GetName();
std::string GetVersion();
std::string GetManufacturer();
std::string GetUniqueID();
void SetColor(unsigned char red, unsigned char green, unsigned char blue);
private:
hueplusplus::Light light;
std::string location;
bool dark;
};
@@ -0,0 +1,244 @@
/*---------------------------------------------------------*\
| PhilipsHueControllerDetect.cpp |
| |
| Detector for Philips Hue |
| |
| Adam Honse (calcprogrammer1@gmail.com) 15 Sep 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "Bridge.h"
#include "HueDeviceTypes.h"
#ifdef _WIN32
#include "WinHttpHandler.h"
#else
#include "LinHttpHandler.h"
#endif
#include "Detector.h"
#include "LogManager.h"
#include "PhilipsHueController.h"
#include "PhilipsHueEntertainmentController.h"
#include "RGBController_PhilipsHue.h"
#include "RGBController_PhilipsHueEntertainment.h"
#include "PhilipsHueSettingsHandler.h"
/******************************************************************************************\
* *
* DetectPhilipsHueControllers *
* *
* Detect Philips Hue lighting devices with RGB control *
* *
\******************************************************************************************/
void DetectPhilipsHueControllers()
{
PhilipsHueSettingsHandler hue_settings;
/*-------------------------------------------------*\
| Create an HTTP handler |
\*-------------------------------------------------*/
#ifdef _WIN32
using SystemHttpHandler = hueplusplus::WinHttpHandler;
#else
using SystemHttpHandler = hueplusplus::LinHttpHandler;
#endif
/*-------------------------------------------------*\
| Create a finder and find bridges |
\*-------------------------------------------------*/
static hueplusplus::BridgeFinder finder(std::make_shared<SystemHttpHandler>());
std::vector<hueplusplus::BridgeFinder::BridgeIdentification> bridges;// = finder.findBridges();
/*-------------------------------------------------*\
| If no bridges were detected, manually add bridge |
| IP and MAC (need to get these from file) |
\*-------------------------------------------------*/
if(hue_settings.GetBridgeCount() > 0)
{
hueplusplus::BridgeFinder::BridgeIdentification ident;
ident.ip = hue_settings.GetBridgeIP(0);
ident.mac = hue_settings.GetBridgeMAC(0);
bridges.push_back(ident);
}
/*-------------------------------------------------*\
| If no bridges were found, return, otherwise |
| connect to the first bridge |
\*-------------------------------------------------*/
if(bridges.empty())
{
return;
}
else
{
/*-------------------------------------------------*\
| Check if a saved username exists |
\*-------------------------------------------------*/
if(hue_settings.GetBridgeCount() > 0)
{
/*-------------------------------------------------*\
| Add the username if it exists |
\*-------------------------------------------------*/
if(hue_settings.BridgeHasUsername(0))
{
finder.addUsername(bridges[0].mac, hue_settings.GetBridgeUsername(0));
}
/*-------------------------------------------------*\
| Add the client key if it exists |
\*-------------------------------------------------*/
if(hue_settings.BridgeHasClientKey(0))
{
finder.addClientKey(bridges[0].mac, hue_settings.GetBridgeClientKey(0));
}
}
/*-------------------------------------------------*\
| If username was added, this should connect right |
| away. If not, the user will have to push the |
| connect button on the bridge. |
\*-------------------------------------------------*/
try
{
static hueplusplus::Bridge bridge = finder.getBridge(bridges[0]);
bridge.refresh();
/*-------------------------------------------------*\
| Check to see if we need to save the settings |
| Settings need to be saved if either username or |
| client key either do not exist or have changed |
\*-------------------------------------------------*/
bool save_settings = false;
bool use_entertainment = false;
bool auto_connect = false;
if(hue_settings.GetBridgeCount() > 0)
{
if(hue_settings.BridgeHasUsername(0))
{
if(hue_settings.GetBridgeUsername(0) != bridge.getUsername())
{
save_settings = true;
}
}
else
{
save_settings = true;
}
if(hue_settings.BridgeHasClientKey(0))
{
if(hue_settings.GetBridgeClientKey(0) != bridge.getClientKey())
{
use_entertainment = true;
save_settings = true;
}
}
else
{
save_settings = true;
}
}
/*-------------------------------------------------*\
| Save the settings if needed |
\*-------------------------------------------------*/
if(save_settings)
{
hue_settings.SetBridgeUsername(0, bridge.getUsername());
hue_settings.SetBridgeClientKey(0, bridge.getClientKey());
hue_settings.SetBridgeUseEntertainment(0, use_entertainment);
hue_settings.SetBridgeAutoconnect(0, auto_connect);
hue_settings.SaveSettings();
}
/*-------------------------------------------------*\
| Get entertainment mode settings |
\*-------------------------------------------------*/
use_entertainment = hue_settings.GetBridgeUseEntertainment(0);
auto_connect = hue_settings.GetBridgeAutoconnect(0);
/*-------------------------------------------------*\
| Get all groups from the bridge |
\*-------------------------------------------------*/
if(use_entertainment)
{
std::vector<hueplusplus::Group> groups = bridge.groups().getAll();
if(groups.size() > 0)
{
/*-------------------------------------------------*\
| Loop through all available groups and check to |
| see if any are Entertainment groups |
\*-------------------------------------------------*/
for(unsigned int group_idx = 0; group_idx < groups.size(); group_idx++)
{
if(groups[group_idx].getType() == "Entertainment")
{
PhilipsHueEntertainmentController* controller = new PhilipsHueEntertainmentController(bridge, groups[group_idx]);
RGBController_PhilipsHueEntertainment* rgb_controller = new RGBController_PhilipsHueEntertainment(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
/*-------------------------------------------------*\
| Loop through RGB Controllers to find the first |
| Entertainment group and Set it to "Connect", |
| as only one Stream can be open at a time. |
\*-------------------------------------------------*/
if(auto_connect)
{
for(unsigned int controller_idx = 0; controller_idx < ResourceManager::get()->GetRGBControllers().size(); controller_idx++)
{
if(ResourceManager::get()->GetRGBControllers()[controller_idx]->GetDescription() == "Philips Hue Entertainment Mode Device")
{
ResourceManager::get()->GetRGBControllers()[controller_idx]->SetMode(0);
break;
}
}
}
}
}
/*-------------------------------------------------*\
| Get all lights from the bridge |
\*-------------------------------------------------*/
else
{
std::vector<hueplusplus::Light> lights = bridge.lights().getAll();
if(lights.size() > 0)
{
/*-------------------------------------------------*\
| Loop through all available lights and add those |
| that have color (RGB) control capability |
\*-------------------------------------------------*/
for(unsigned int light_idx = 0; light_idx < lights.size(); light_idx++)
{
if(lights[light_idx].hasColorControl())
{
PhilipsHueController* controller = new PhilipsHueController(lights[light_idx], bridge.getBridgeIP());
RGBController_PhilipsHue* rgb_controller = new RGBController_PhilipsHue(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
}
}
}
catch(const std::exception &e)
{
LOG_INFO("Exception occurred in Philips Hue detection: %s", e.what());
}
}
} /* DetectPhilipsHueControllers() */
REGISTER_DETECTOR("Philips Hue", DetectPhilipsHueControllers);
@@ -0,0 +1,110 @@
/*---------------------------------------------------------*\
| PhilipsHueEntertainmentController.cpp |
| |
| Detector for Philips Hue Entertainment Mode |
| |
| Adam Honse (calcprogrammer1@gmail.com) 06 Nov 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "RGBController.h"
#include "PhilipsHueEntertainmentController.h"
PhilipsHueEntertainmentController::PhilipsHueEntertainmentController(hueplusplus::Bridge& bridge_ptr, hueplusplus::Group group_ptr):bridge(bridge_ptr),group(group_ptr)
{
/*-------------------------------------------------*\
| Fill in location string with bridge IP |
\*-------------------------------------------------*/
location = "IP: " + bridge.getBridgeIP();
num_leds = (unsigned int)group.getLightIds().size();
connected = false;
}
PhilipsHueEntertainmentController::~PhilipsHueEntertainmentController()
{
}
std::string PhilipsHueEntertainmentController::GetLocation()
{
return(location);
}
std::string PhilipsHueEntertainmentController::GetName()
{
return(group.getName());
}
std::string PhilipsHueEntertainmentController::GetVersion()
{
return("");
}
std::string PhilipsHueEntertainmentController::GetManufacturer()
{
return("");
}
std::string PhilipsHueEntertainmentController::GetUniqueID()
{
return("");
}
unsigned int PhilipsHueEntertainmentController::GetNumLEDs()
{
return(num_leds);
}
void PhilipsHueEntertainmentController::SetColor(RGBColor* colors)
{
if(connected)
{
/*-------------------------------------------------*\
| 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->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;
}
}
@@ -0,0 +1,50 @@
/*---------------------------------------------------------*\
| PhilipsHueEntertainmentController.h |
| |
| Detector for Philips Hue Entertainment Mode |
| |
| Adam Honse (calcprogrammer1@gmail.com) 06 Nov 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <string>
#include <vector>
#include "Bridge.h"
#include "EntertainmentMode.h"
#include "Group.h"
#include "RGBController.h"
#define HUE_ENTERTAINMENT_HEADER_SIZE 16
#define HUE_ENTERTAINMENT_LIGHT_SIZE 9
class PhilipsHueEntertainmentController
{
public:
PhilipsHueEntertainmentController(hueplusplus::Bridge& bridge_ptr, hueplusplus::Group group_ptr);
~PhilipsHueEntertainmentController();
std::string GetLocation();
std::string GetName();
std::string GetVersion();
std::string GetManufacturer();
std::string GetUniqueID();
unsigned int GetNumLEDs();
void SetColor(RGBColor* colors);
void Connect();
void Disconnect();
private:
hueplusplus::Bridge& bridge;
hueplusplus::Group group;
hueplusplus::EntertainmentMode* entertainment;
std::string location;
unsigned int num_leds;
bool connected;
};
@@ -0,0 +1,151 @@
#include "PhilipsHueSettingsHandler.h"
#include "ResourceManager.h"
#include "SettingsManager.h"
#define HUE_SETTINGS ((hue_settings_type *)hue_settings)->hue_settings
typedef struct
{
json hue_settings;
} hue_settings_type;
PhilipsHueSettingsHandler::PhilipsHueSettingsHandler()
{
/*-------------------------------------------------*\
| Create an object to hold the hue settings json |
| This cannot be a class member as json must not |
| be included in the header file, so it is held as |
| a void pointer instead. |
\*-------------------------------------------------*/
hue_settings = (void *)(new hue_settings_type);
/*-------------------------------------------------*\
| Get Philips Hue settings from settings manager |
\*-------------------------------------------------*/
HUE_SETTINGS = ResourceManager::get()->GetSettingsManager()->GetSettings("PhilipsHueDevices");
}
PhilipsHueSettingsHandler::~PhilipsHueSettingsHandler()
{
delete (hue_settings_type *)hue_settings;
}
std::size_t PhilipsHueSettingsHandler::GetBridgeCount()
{
if(HUE_SETTINGS.contains("bridges"))
{
return(HUE_SETTINGS["bridges"].size());
}
else
{
return(0);
}
}
std::string PhilipsHueSettingsHandler::GetBridgeIP(unsigned int bridge_idx)
{
if(HUE_SETTINGS["bridges"][bridge_idx].contains("ip"))
{
return(HUE_SETTINGS["bridges"][bridge_idx]["ip"]);
}
else
{
return("");
}
}
std::string PhilipsHueSettingsHandler::GetBridgeMAC(unsigned int bridge_idx)
{
if(HUE_SETTINGS["bridges"][bridge_idx].contains("mac"))
{
return(HUE_SETTINGS["bridges"][bridge_idx]["mac"]);
}
else
{
return("");
}
}
std::string PhilipsHueSettingsHandler::GetBridgeUsername(unsigned int bridge_idx)
{
if(HUE_SETTINGS["bridges"][bridge_idx].contains("username"))
{
return(HUE_SETTINGS["bridges"][bridge_idx]["username"]);
}
else
{
return("");
}
}
std::string PhilipsHueSettingsHandler::GetBridgeClientKey(unsigned int bridge_idx)
{
if(HUE_SETTINGS["bridges"][bridge_idx].contains("clientkey"))
{
return(HUE_SETTINGS["bridges"][bridge_idx]["clientkey"]);
}
else
{
return("");
}
}
bool PhilipsHueSettingsHandler::GetBridgeAutoconnect(unsigned int bridge_idx)
{
if(HUE_SETTINGS["bridges"][bridge_idx].contains("autoconnect"))
{
return(HUE_SETTINGS["bridges"][bridge_idx]["autoconnect"]);
}
else
{
return(false);
}
}
bool PhilipsHueSettingsHandler::GetBridgeUseEntertainment(unsigned int bridge_idx)
{
if(HUE_SETTINGS["bridges"][bridge_idx].contains("entertainment"))
{
return(HUE_SETTINGS["bridges"][bridge_idx]["entertainment"]);
}
else
{
return(false);
}
}
bool PhilipsHueSettingsHandler::BridgeHasUsername(unsigned int bridge_idx)
{
return(HUE_SETTINGS["bridges"][bridge_idx].contains("username"));
}
bool PhilipsHueSettingsHandler::BridgeHasClientKey(unsigned int bridge_idx)
{
return(HUE_SETTINGS["bridges"][bridge_idx].contains("clientkey"));
}
void PhilipsHueSettingsHandler::SetBridgeUsername(unsigned int bridge_idx, std::string username)
{
HUE_SETTINGS["bridges"][bridge_idx]["username"] = username;
}
void PhilipsHueSettingsHandler::SetBridgeClientKey(unsigned int bridge_idx, std::string clientkey)
{
HUE_SETTINGS["bridges"][bridge_idx]["clientkey"] = clientkey;
}
void PhilipsHueSettingsHandler::SetBridgeAutoconnect(unsigned int bridge_idx, bool auto_connect)
{
HUE_SETTINGS["bridges"][bridge_idx]["autoconnect"] = auto_connect;
}
void PhilipsHueSettingsHandler::SetBridgeUseEntertainment(unsigned int bridge_idx, bool use_entertainment)
{
HUE_SETTINGS["bridges"][bridge_idx]["entertainment"] = use_entertainment;
}
void PhilipsHueSettingsHandler::SaveSettings()
{
ResourceManager::get()->GetSettingsManager()->SetSettings("PhilipsHueDevices", HUE_SETTINGS);
ResourceManager::get()->GetSettingsManager()->SaveSettings();
}
@@ -0,0 +1,47 @@
/*---------------------------------------------------------*\
| PhilipsHueSettingsHandler.h |
| |
| Settings Handler for Philips Hue |
| Due to conflict in jsoh.hpp library, hueplusplus and |
| SettingsManager should not be included in the same file |
| so handle settings in a separate class. |
| |
| Adam Honse (calcprogrammer1@gmail.com) 17 Jan 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <cstddef>
#include <string>
class PhilipsHueSettingsHandler
{
public:
PhilipsHueSettingsHandler();
~PhilipsHueSettingsHandler();
std::size_t GetBridgeCount();
std::string GetBridgeIP(unsigned int bridge_idx);
std::string GetBridgeMAC(unsigned int bridge_idx);
std::string GetBridgeUsername(unsigned int bridge_idx);
std::string GetBridgeClientKey(unsigned int bridge_idx);
bool GetBridgeAutoconnect(unsigned int bridge_idx);
bool GetBridgeUseEntertainment(unsigned int bridge_idx);
bool BridgeHasUsername(unsigned int bridge_idx);
bool BridgeHasClientKey(unsigned int bridge_idx);
void SetBridgeUsername(unsigned int bridge_idx, std::string username);
void SetBridgeClientKey(unsigned int bridge_idx, std::string clientkey);
void SetBridgeAutoconnect(unsigned int bridge_ip, bool auto_connect);
void SetBridgeUseEntertainment(unsigned int bridge_idx, bool use_entertainment);
void SaveSettings();
private:
void * hue_settings;
};
@@ -0,0 +1,94 @@
/*---------------------------------------------------------*\
| RGBController_PhilipsHue.cpp |
| |
| RGBController for Philips Hue |
| |
| Adam Honse (calcprogrammer1@gmail.com) 15 Sep 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "RGBController_PhilipsHue.h"
/**------------------------------------------------------------------*\
@name Philips Hue
@category Light
@type Network
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectPhilipsHueControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_PhilipsHue::RGBController_PhilipsHue(PhilipsHueController* controller_ptr)
{
controller = controller_ptr;
name = controller->GetManufacturer() + " " + controller->GetName();
type = DEVICE_TYPE_LIGHT;
version = controller->GetVersion();
description = "Philips Hue Device";
serial = controller->GetUniqueID();
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;
modes.push_back(Direct);
SetupZones();
}
void RGBController_PhilipsHue::SetupZones()
{
zone led_zone;
led_zone.name = "RGB Light";
led_zone.type = ZONE_TYPE_SINGLE;
led_zone.leds_min = 1;
led_zone.leds_max = 1;
led_zone.leds_count = 1;
led_zone.matrix_map = NULL;
zones.push_back(led_zone);
led new_led;
new_led.name = "RGB Light";
leds.push_back(new_led);
SetupColors();
}
void RGBController_PhilipsHue::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_PhilipsHue::DeviceUpdateLEDs()
{
unsigned char red = RGBGetRValue(colors[0]);
unsigned char grn = RGBGetGValue(colors[0]);
unsigned char blu = RGBGetBValue(colors[0]);
controller->SetColor(red, grn, blu);
}
void RGBController_PhilipsHue::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_PhilipsHue::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_PhilipsHue::DeviceUpdateMode()
{
}
@@ -0,0 +1,33 @@
/*---------------------------------------------------------*\
| RGBController_PhilipsHue.h |
| |
| RGBController for Philips Hue |
| |
| Adam Honse (calcprogrammer1@gmail.com) 15 Sep 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "PhilipsHueController.h"
class RGBController_PhilipsHue : public RGBController
{
public:
RGBController_PhilipsHue(PhilipsHueController* controller_ptr);
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
PhilipsHueController* controller;
};
@@ -0,0 +1,156 @@
/*---------------------------------------------------------*\
| RGBController_PhilipsHueEntertainment.cpp |
| |
| RGBController for Philips Hue Entertainment Mode |
| |
| Adam Honse (calcprogrammer1@gmail.com) 07 Nov 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "RGBController_PhilipsHueEntertainment.h"
#include "ResourceManager.h"
using namespace std::chrono_literals;
/**------------------------------------------------------------------*\
@name Philips Hue Entertainment
@category Light
@type Network
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectPhilipsHueControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_PhilipsHueEntertainment::RGBController_PhilipsHueEntertainment(PhilipsHueEntertainmentController* controller_ptr)
{
controller = controller_ptr;
name = controller->GetManufacturer() + " " + controller->GetName();
type = DEVICE_TYPE_LIGHT;
version = controller->GetVersion();
description = "Philips Hue Entertainment Mode Device";
serial = controller->GetUniqueID();
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;
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();
/*-----------------------------------------------------------------------------------------------------*\
| The Philips Hue Entertainment Mode only supports one stream at a time. So we must start Disconnected. |
| https://developers.meethue.com/develop/hue-entertainment/philips-hue-entertainment-api/ |
\*-----------------------------------------------------------------------------------------------------*/
active_mode = 1;
/*-----------------------------------------------------*\
| The Philips Hue Entertainment Mode requires a packet |
| within 10 seconds of sending the lighting change in |
| order to not exit entertainment mode. Start a thread |
| to continuously send a packet every 5s |
\*-----------------------------------------------------*/
KeepaliveThreadRunning = true;
KeepaliveThread = new std::thread(&RGBController_PhilipsHueEntertainment::KeepaliveThreadFunction, this);
}
void RGBController_PhilipsHueEntertainment::SetupZones()
{
zone led_zone;
led_zone.name = "RGB Light";
led_zone.type = ZONE_TYPE_SINGLE;
led_zone.leds_min = controller->GetNumLEDs();
led_zone.leds_max = controller->GetNumLEDs();
led_zone.leds_count = controller->GetNumLEDs();
led_zone.matrix_map = NULL;
zones.push_back(led_zone);
for(unsigned int led_idx = 0; led_idx < controller->GetNumLEDs(); led_idx++)
{
led new_led;
new_led.name = "RGB Light";
leds.push_back(new_led);
}
SetupColors();
}
void RGBController_PhilipsHueEntertainment::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_PhilipsHueEntertainment::DeviceUpdateLEDs()
{
last_update_time = std::chrono::steady_clock::now();
if(active_mode == 0)
{
controller->SetColor(&colors[0]);
}
}
void RGBController_PhilipsHueEntertainment::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_PhilipsHueEntertainment::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_PhilipsHueEntertainment::DeviceUpdateMode()
{
if(active_mode == 0)
{
std::vector<RGBController*> rgb_controllers = ResourceManager::get()->GetRGBControllers();
for(unsigned int controller_idx = 0; controller_idx < rgb_controllers.size(); controller_idx++)
{
if(rgb_controllers[controller_idx] != this && rgb_controllers[controller_idx]->GetDescription() == "Philips Hue Entertainment Mode Device" && rgb_controllers[controller_idx]->active_mode == 0)
{
rgb_controllers[controller_idx]->SetMode(1);
}
}
controller->Connect();
}
else
{
controller->Disconnect();
}
}
void RGBController_PhilipsHueEntertainment::KeepaliveThreadFunction()
{
while(KeepaliveThreadRunning)
{
if(active_mode == 0)
{
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::seconds(5))
{
UpdateLEDs();
}
}
std::this_thread::sleep_for(1s);
}
}
@@ -0,0 +1,42 @@
/*---------------------------------------------------------*\
| RGBController_PhilipsHueEntertainment.h |
| |
| RGBController for Philips Hue Entertainment Mode |
| |
| Adam Honse (calcprogrammer1@gmail.com) 07 Nov 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <atomic>
#include <thread>
#include "RGBController.h"
#include "PhilipsHueEntertainmentController.h"
class RGBController_PhilipsHueEntertainment : public RGBController
{
public:
RGBController_PhilipsHueEntertainment(PhilipsHueEntertainmentController* controller_ptr);
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
void KeepaliveThreadFunction();
private:
PhilipsHueEntertainmentController* controller;
std::atomic<bool> KeepaliveThreadRunning;
std::thread* KeepaliveThread;
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
};