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,159 @@
/*---------------------------------------------------------*\
| ElgatoLightStripController.cpp |
| |
| Driver for Elgato Light Strip |
| |
| Monks (@iamtherealestmonkey) 03 Nov 2021 |
| DomePlaysHD 14 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <sstream>
#include <thread>
#include <vector>
#include "ElgatoLightStripController.h"
#include <nlohmann/json.hpp>
#include "LogManager.h"
using json = nlohmann::json;
using namespace std::chrono_literals;
ElgatoLightStripController::ElgatoLightStripController(std::string ip)
{
/*-----------------------------------------------------------------*\
| Fill in location string with device's IP address |
\*-----------------------------------------------------------------*/
location = "IP: " + ip;
/*-----------------------------------------------------------------*\
| Open a TCP client sending to the device's IP, port 9123 |
\*-----------------------------------------------------------------*/
port.tcp_client(ip.c_str(), "9123");
/*-----------------------------------------------------------*\
| Handle responses received from the Elgato LightStrip device |
\*-----------------------------------------------------------*/
port.tcp_client_connect();
std::string buf = "GET /elgato/accessory-info HTTP/1.1\r\nContent-Type: application/json\r\nConnection: close\r\n\r\n";
port.tcp_client_write((char *)buf.c_str(), (int)buf.length() + 1);
char recv_buf[1024];
int size = port.tcp_listen(recv_buf, sizeof(recv_buf));
port.tcp_close();
if(size > 0)
{
/*-----------------------------------------------------------*\
| Get response body |
\*-----------------------------------------------------------*/
std::istringstream recv_stream(recv_buf);
std::vector<std::string> recv_list;
std::string current_line;
while(std::getline(recv_stream, current_line, '\n'))
{
recv_list.push_back(current_line);
}
std::string result = recv_list[5];
json elgato_lightstrip_data = json::parse(result);
firmware_version = elgato_lightstrip_data["firmwareVersion"];
serialnumber = elgato_lightstrip_data["serialNumber"];
displayname = elgato_lightstrip_data["displayName"];
LOG_DEBUG("[ElgatoLightStrip] [%s]", result.data());
}
}
ElgatoLightStripController::~ElgatoLightStripController()
{
}
std::string ElgatoLightStripController::GetLocation()
{
return(location);
}
std::string ElgatoLightStripController::GetName()
{
return(displayname);
}
std::string ElgatoLightStripController::GetVersion()
{
return(firmware_version);
}
std::string ElgatoLightStripController::GetManufacturer()
{
return("Elgato");
}
std::string ElgatoLightStripController::GetUniqueID()
{
return(serialnumber);
}
void ElgatoLightStripController::SetColor(hsv_t hsv_color)
{
if(hsv_color.hue > 360)
{
hsv_color.hue = 360;
}
if(hsv_color.saturation > 100)
{
hsv_color.saturation = 100;
}
/*-------------------------------------------------*\
| Delay to prevent it from getting stuck on effects |
\*-------------------------------------------------*/
std::this_thread::sleep_for(std::chrono::milliseconds(150));
port.tcp_client_connect();
std::string buf = GetRequest(hsv_color.hue, hsv_color.saturation, GetBrightness());
port.tcp_client_write((char *)buf.c_str(), (int)buf.length() + 1);
port.tcp_close();
}
std::string ElgatoLightStripController::GetRequest(int hue, int saturation, int brightness)
{
json command;
command["numberOfLights"] = 1;
json lights = json::array();
lights.push_back(json::object({ {"on", 1}, {"hue", hue}, {"saturation", saturation}, {"brightness", brightness}}));
command["lights"] = lights;
std::string command_str = command.dump();
std::string buf = "PUT /elgato/lights HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: " +
std::to_string(command_str.length()) +
"\r\nConnection: close\r\n\r\n" + command_str + "\r\n\r\n";
return(buf);
}
int ElgatoLightStripController::GetBrightness()
{
if(device_brightness > 100 || device_brightness < 0)
{
device_brightness = 100;
}
return device_brightness;
}
void ElgatoLightStripController::SetBrightness(int brightness)
{
if(brightness > 100 || device_brightness < 0)
{
brightness = 100;
}
device_brightness = brightness;
}
@@ -0,0 +1,43 @@
/*---------------------------------------------------------*\
| ElgatoLightStripController.h |
| |
| Driver for Elgato Light Strip |
| |
| Monks (@iamtherealestmonkey) 03 Nov 2021 |
| DomePlaysHD 12 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <string>
#include "net_port.h"
#include "hsv.h"
class ElgatoLightStripController
{
public:
ElgatoLightStripController(std::string ip);
~ElgatoLightStripController();
std::string GetLocation();
std::string GetName();
std::string GetVersion();
std::string GetManufacturer();
std::string GetUniqueID();
void SetColor(hsv_t hsv_color);
int GetBrightness();
void SetBrightness(int brightness);
private:
std::string GetRequest(int hue, int saturation, int brightness);
std::string location;
std::string firmware_version;
std::string serialnumber;
std::string displayname;
net_port port;
int device_brightness;
};
@@ -0,0 +1,50 @@
/*---------------------------------------------------------*\
| ElgatoLightStripControllerDetect.cpp |
| |
| Detector for Elgato Light Strip |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "Detector.h"
#include "ElgatoLightStripController.h"
#include "RGBController_ElgatoLightStrip.h"
#include "SettingsManager.h"
/******************************************************************************************\
* *
* Detect Elgato LightStrip devices *
* *
\******************************************************************************************/
void DetectElgatoLightStripControllers()
{
json elgato_lightstrip_settings;
/*-------------------------------------------------*\
| Get LightStrip settings from settings manager |
\*-------------------------------------------------*/
elgato_lightstrip_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ElgatoLightStripDevices");
/*------------------------------------------------------------*\
| If the Elgato Light Strip settings contains devices, process |
\*------------------------------------------------------------*/
if(elgato_lightstrip_settings.contains("devices"))
{
for(unsigned int device_idx = 0; device_idx < elgato_lightstrip_settings["devices"].size(); device_idx++)
{
if(elgato_lightstrip_settings["devices"][device_idx].contains("ip"))
{
std::string elgato_lightstrip_ip = elgato_lightstrip_settings["devices"][device_idx]["ip"];
ElgatoLightStripController* controller = new ElgatoLightStripController(elgato_lightstrip_ip);
RGBController_ElgatoLightStrip* rgb_controller = new RGBController_ElgatoLightStrip(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
}
}
REGISTER_DETECTOR("Elgato Light Strip", DetectElgatoLightStripControllers);
@@ -0,0 +1,93 @@
/*---------------------------------------------------------*\
| RGBController_ElgatoLightStrip.cpp |
| |
| RGBController for Elgato Light Strip |
| |
| Monks (@iamtherealestmonkey) 03 Nov 2021 |
| DomePlaysHD 12 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "RGBController_ElgatoLightStrip.h"
#include "hsv.h"
RGBController_ElgatoLightStrip::RGBController_ElgatoLightStrip(ElgatoLightStripController* controller_ptr)
{
controller = controller_ptr;
name = controller->GetName();
vendor = controller->GetManufacturer();
type = DEVICE_TYPE_LEDSTRIP;
version = controller->GetVersion();
description = "Elgato LightStrip Device";
serial = controller->GetUniqueID();
location = controller->GetLocation();
mode Direct;
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_min = 0;
Direct.brightness_max = 100;
Direct.brightness = 100;
modes.push_back(Direct);
SetupZones();
}
RGBController_ElgatoLightStrip::~RGBController_ElgatoLightStrip()
{
delete controller;
}
void RGBController_ElgatoLightStrip::SetupZones()
{
zone led_zone;
led_zone.name = "Lightstrip";
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 = "Lightstrip";
leds.push_back(new_led);
SetupColors();
}
void RGBController_ElgatoLightStrip::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_ElgatoLightStrip::DeviceUpdateLEDs()
{
RGBColor rgb_color = colors[0];
hsv_t hsv_color;
rgb2hsv(rgb_color, &hsv_color);
controller->SetColor(hsv_color);
controller->SetBrightness((unsigned char)modes[(unsigned int)active_mode].brightness);
}
void RGBController_ElgatoLightStrip::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_ElgatoLightStrip::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_ElgatoLightStrip::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}
@@ -0,0 +1,36 @@
/*---------------------------------------------------------*\
| RGBController_ElgatoLightStrip.h |
| |
| RGBController for Elgato Light Strip |
| |
| Monks (@iamtherealestmonkey) 01 Nov 2021 |
| DomePlaysHD 12 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "ElgatoLightStripController.h"
class RGBController_ElgatoLightStrip : public RGBController
{
public:
RGBController_ElgatoLightStrip(ElgatoLightStripController* controller_ptr);
~RGBController_ElgatoLightStrip();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
ElgatoLightStripController* controller;
};