Files
OpenRGB/Controllers/PhilipsHueController/RGBController_PhilipsHueEntertainment.cpp
Adam Honse 38f016f2a8 RGBController API Overhaul
* Reorganize and clean up RGBController API functions
    * Add functions to get protected RGBController member values
    * Make NetworkClient, ProfileManager, and ResourceManager friend classes so they can access protected members
    * Protected previously-public RGBController members
        * Information strings (name, vendor, description, version, serial location)
        * Device type
        * Active mode
        * Flags
        * LEDs vector
        * LED alternate names vector
        * Modes vector
        * Colors vector
        * Zones vector
    * Add CONTROLLER_FLAG_HIDDEN to allow plugins to hide controllers from control GUI
    * Add update reason codes to RGBController update callback and signal updates on more RGBController events
    * Add loop zone types and segmented zone type
    * Add matrix map field to segments
2025-12-30 14:09:08 -06:00

150 lines
5.0 KiB
C++

/*---------------------------------------------------------*\
| 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::DeviceUpdateLEDs()
{
last_update_time = std::chrono::steady_clock::now();
if(active_mode == 0)
{
controller->SetColor(&colors[0]);
}
}
void RGBController_PhilipsHueEntertainment::DeviceUpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_PhilipsHueEntertainment::DeviceUpdateSingleLED(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]->GetActiveMode() == 0)
{
rgb_controllers[controller_idx]->SetActiveMode(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);
}
}