Adding Elgato Keylight
Code style changes by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
a64894445d
commit
0b9825ca19
14 changed files with 615 additions and 0 deletions
|
|
@ -0,0 +1,110 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Driver for Elgato Key Light |
|
||||
| |
|
||||
| Monks (imtherealestmonkey@gmail.com), 11/03/2021 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "ElgatoKeyLightController.h"
|
||||
#include "json.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
ElgatoKeyLightController::ElgatoKeyLightController(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");
|
||||
}
|
||||
|
||||
ElgatoKeyLightController::~ElgatoKeyLightController()
|
||||
{
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetLocation()
|
||||
{
|
||||
return(location);
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetName()
|
||||
{
|
||||
return("Elgato KeyLight");
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetVersion()
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetManufacturer()
|
||||
{
|
||||
return("Elgato");
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetUniqueID()
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
void ElgatoKeyLightController::SetColor(hsv_t hsv_color)
|
||||
{
|
||||
// Weird elgato color format
|
||||
int k_value = HSVToK(hsv_color.hue);
|
||||
|
||||
port.tcp_client_connect();
|
||||
std::string buf = GetRequest(hsv_color.value, k_value);
|
||||
port.tcp_client_write((char *)buf.c_str(), buf.length() + 1);
|
||||
|
||||
port.tcp_close();
|
||||
}
|
||||
|
||||
std::string ElgatoKeyLightController::GetRequest(int brightness, int temperature)
|
||||
{
|
||||
json command;
|
||||
|
||||
command["numberOfLights"] = 1;
|
||||
|
||||
auto lights = json::array();
|
||||
lights.push_back(json::object({ {"on", 1}, {"temperature", temperature}, {"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 ElgatoKeyLightController::HSVToK(int hue)
|
||||
{
|
||||
int k_value;
|
||||
|
||||
if(hue <= 60 && hue >= 0)
|
||||
{
|
||||
k_value = 2900;
|
||||
}
|
||||
else if(hue >= 61 && hue <= 120)
|
||||
{
|
||||
k_value = 4000;
|
||||
}
|
||||
else if(hue >= 121 && hue <= 180)
|
||||
{
|
||||
k_value = 5000;
|
||||
}
|
||||
else if(hue >= 181 && hue <= 240)
|
||||
{
|
||||
k_value = 6000;
|
||||
}
|
||||
else
|
||||
{
|
||||
k_value = 7000;
|
||||
}
|
||||
|
||||
return k_value;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Definitions for Elgato Key Light |
|
||||
| |
|
||||
| Monks (imtherealestmonkey@gmail.com), 11/11/2021 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "net_port.h"
|
||||
#include "hsv.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#pragma once
|
||||
|
||||
class ElgatoKeyLightController
|
||||
{
|
||||
public:
|
||||
ElgatoKeyLightController(std::string ip);
|
||||
~ElgatoKeyLightController();
|
||||
|
||||
std::string GetLocation();
|
||||
std::string GetName();
|
||||
std::string GetVersion();
|
||||
std::string GetManufacturer();
|
||||
std::string GetUniqueID();
|
||||
|
||||
void SetColor(hsv_t hsv_color);
|
||||
|
||||
private:
|
||||
std::string GetRequest(int brightness, int temperature);
|
||||
int HSVToK(int hue);
|
||||
std::string location;
|
||||
net_port port;
|
||||
};
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#include "Detector.h"
|
||||
#include "ElgatoKeyLightController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_ElgatoKeyLight.h"
|
||||
#include "SettingsManager.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectElgatoKeyLightControllers *
|
||||
* *
|
||||
* Detect Elgato KeyLight devices *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectElgatoKeyLightControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
json elgato_keylight_settings;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get KeyLight settings from settings manager |
|
||||
\*-------------------------------------------------*/
|
||||
elgato_keylight_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ElgatoKeyLightDevices");
|
||||
|
||||
/*----------------------------------------------------------*\
|
||||
| If the Elgato Key Light settings contains devices, process|
|
||||
\*----------------------------------------------------------*/
|
||||
if(elgato_keylight_settings.contains("devices"))
|
||||
{
|
||||
for(unsigned int device_idx = 0; device_idx < elgato_keylight_settings["devices"].size(); device_idx++)
|
||||
{
|
||||
if(elgato_keylight_settings["devices"][device_idx].contains("ip"))
|
||||
{
|
||||
std::string elgato_keylight_ip = elgato_keylight_settings["devices"][device_idx]["ip"];
|
||||
|
||||
ElgatoKeyLightController* controller = new ElgatoKeyLightController(elgato_keylight_ip);
|
||||
RGBController_ElgatoKeyLight* rgb_controller = new RGBController_ElgatoKeyLight(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectElgatoKeyLightControllers() */
|
||||
|
||||
REGISTER_DETECTOR("ElgatoKeyLight", DetectElgatoKeyLightControllers);
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*------------------------------------------------*\
|
||||
| RGBController_ElgatoKeyLight.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for ElgatoKeyLight |
|
||||
| |
|
||||
| Monks (@iamtherealestmonkey) 11/03/2021 |
|
||||
\*------------------------------------------------*/
|
||||
|
||||
#include "RGBController_ElgatoKeyLight.h"
|
||||
#include "hsv.h"
|
||||
|
||||
RGBController_ElgatoKeyLight::RGBController_ElgatoKeyLight(ElgatoKeyLightController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetName();
|
||||
vendor = controller->GetManufacturer();
|
||||
type = DEVICE_TYPE_LIGHT;
|
||||
version = controller->GetVersion();
|
||||
description = "Elgato KeyLight Device";
|
||||
serial = controller->GetUniqueID();
|
||||
location = controller->GetLocation();
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = 0;
|
||||
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Static.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Static);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_ElgatoKeyLight::~RGBController_ElgatoKeyLight()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_ElgatoKeyLight::SetupZones()
|
||||
{
|
||||
zone led_zone;
|
||||
led_zone.name = "Keylight";
|
||||
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 = "Keylight";
|
||||
|
||||
leds.push_back(new_led);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_ElgatoKeyLight::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_ElgatoKeyLight::DeviceUpdateLEDs()
|
||||
{
|
||||
RGBColor rgb_color = colors[0];
|
||||
hsv_t hsv_color;
|
||||
rgb2hsv(rgb_color, &hsv_color);
|
||||
controller->SetColor(hsv_color);
|
||||
}
|
||||
|
||||
void RGBController_ElgatoKeyLight::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_ElgatoKeyLight::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_ElgatoKeyLight::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*--------------------------------------------------*\
|
||||
| RGBController_ElgatoKeyLight.h |
|
||||
| |
|
||||
| Generic RGB Interface for Elgato KeyLight |
|
||||
| |
|
||||
| Monks (imtherealestmonkey@gmail.com) 11/1/2021 |
|
||||
\*--------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "ElgatoKeyLightController.h"
|
||||
|
||||
class RGBController_ElgatoKeyLight : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_ElgatoKeyLight(ElgatoKeyLightController* controller_ptr);
|
||||
~RGBController_ElgatoKeyLight();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
ElgatoKeyLightController* controller;
|
||||
};
|
||||
11
OpenRGB.pro
11
OpenRGB.pro
|
|
@ -208,6 +208,8 @@ HEADERS +=
|
|||
pci_ids/pci_ids.h \
|
||||
qt/DeviceView.h \
|
||||
qt/OpenRGBDialog2.h \
|
||||
qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsEntry.h \
|
||||
qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.h \
|
||||
qt/OpenRGBPluginContainer.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsList.h \
|
||||
|
|
@ -367,6 +369,8 @@ HEADERS +=
|
|||
Controllers/E131Controller/RGBController_E131.h \
|
||||
Controllers/EKController/EKController.h \
|
||||
Controllers/EKController/RGBController_EKController.h \
|
||||
Controllers/ElgatoKeyLightController/ElgatoKeyLightController.h \
|
||||
Controllers/ElgatoKeyLightController/RGBController_ElgatoKeyLight.h \
|
||||
Controllers/ENESMBusController/ENESMBusController.h \
|
||||
Controllers/ENESMBusController/RGBController_ENESMBus.h \
|
||||
Controllers/ENESMBusController/ENESMBusInterface/ENESMBusInterface.h \
|
||||
|
|
@ -703,6 +707,8 @@ SOURCES +=
|
|||
net_port/net_port.cpp \
|
||||
qt/DeviceView.cpp \
|
||||
qt/OpenRGBDialog2.cpp \
|
||||
qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsEntry.cpp \
|
||||
qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.cpp \
|
||||
qt/OpenRGBPluginContainer.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsList.cpp \
|
||||
|
|
@ -894,6 +900,9 @@ SOURCES +=
|
|||
Controllers/EKController/EKControllerDetect.cpp \
|
||||
Controllers/EKController/EKController.cpp \
|
||||
Controllers/EKController/RGBController_EKController.cpp \
|
||||
Controllers/ElgatoKeyLightController/ElgatoKeyLightController.cpp \
|
||||
Controllers/ElgatoKeyLightController/ElgatoKeyLightControllerDetect.cpp \
|
||||
Controllers/ElgatoKeyLightController/RGBController_ElgatoKeyLight.cpp \
|
||||
Controllers/ENESMBusController/ENESMBusController.cpp \
|
||||
Controllers/ENESMBusController/ENESMBusControllerDetect.cpp \
|
||||
Controllers/ENESMBusController/RGBController_ENESMBus.cpp \
|
||||
|
|
@ -1262,6 +1271,8 @@ FORMS +=
|
|||
qt/OpenRGBDevicePage.ui \
|
||||
qt/OpenRGBDialog.ui \
|
||||
qt/OpenRGBDialog2.ui \
|
||||
qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsEntry.ui \
|
||||
qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.ui \
|
||||
qt/OpenRGBPluginContainer.ui \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.ui \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.ui \
|
||||
|
|
|
|||
|
|
@ -472,6 +472,11 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
|
|||
\*-----------------------------------------------------*/
|
||||
AddNanoleafSettingsPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the ElgatoKeyLight settings page |
|
||||
\*-----------------------------------------------------*/
|
||||
AddElgatoKeyLightSettingsPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the SMBus Tools page if enabled |
|
||||
\*-----------------------------------------------------*/
|
||||
|
|
@ -936,6 +941,34 @@ void OpenRGBDialog2::AddNanoleafSettingsPage()
|
|||
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel);
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddElgatoKeyLightSettingsPage()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the Settings page |
|
||||
\*-----------------------------------------------------*/
|
||||
ElgatoKeyLightSettingsPage = new OpenRGBElgatoKeyLightSettingsPage();
|
||||
|
||||
ui->SettingsTabBar->addTab(ElgatoKeyLightSettingsPage, "");
|
||||
|
||||
QString SettingsLabelString;
|
||||
|
||||
if(OpenRGBThemeManager::IsDarkTheme())
|
||||
{
|
||||
SettingsLabelString = "light_dark.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsLabelString = "light.png";
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the tab label |
|
||||
\*-----------------------------------------------------*/
|
||||
TabLabel* SettingsTabLabel = new TabLabel(SettingsLabelString, "Elgato KeyLight Devices");
|
||||
|
||||
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel);
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddPlugin(OpenRGBPluginEntry* plugin)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "OpenRGBSupportedDevicesPage.h"
|
||||
#include "OpenRGBSettingsPage.h"
|
||||
#include "OpenRGBE131SettingsPage/OpenRGBE131SettingsPage.h"
|
||||
#include "OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.h"
|
||||
#include "OpenRGBLIFXSettingsPage/OpenRGBLIFXSettingsPage.h"
|
||||
#include "OpenRGBPhilipsHueSettingsPage/OpenRGBPhilipsHueSettingsPage.h"
|
||||
#include "OpenRGBPhilipsWizSettingsPage/OpenRGBPhilipsWizSettingsPage.h"
|
||||
|
|
@ -79,6 +80,7 @@ private:
|
|||
OpenRGBSupportedDevicesPage *SupportedPage;
|
||||
OpenRGBSettingsPage *SettingsPage;
|
||||
OpenRGBE131SettingsPage *E131SettingsPage;
|
||||
OpenRGBElgatoKeyLightSettingsPage *ElgatoKeyLightSettingsPage;
|
||||
OpenRGBLIFXSettingsPage *LIFXSettingsPage;
|
||||
OpenRGBPhilipsHueSettingsPage *PhilipsHueSettingsPage;
|
||||
OpenRGBPhilipsWizSettingsPage *PhilipsWizSettingsPage;
|
||||
|
|
@ -105,6 +107,7 @@ private:
|
|||
void AddSupportedDevicesPage();
|
||||
void AddSettingsPage();
|
||||
void AddE131SettingsPage();
|
||||
void AddElgatoKeyLightSettingsPage();
|
||||
void AddLIFXSettingsPage();
|
||||
void AddPhilipsHueSettingsPage();
|
||||
void AddPhilipsWizSettingsPage();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
#include "OpenRGBElgatoKeyLightSettingsEntry.h"
|
||||
#include "ui_OpenRGBElgatoKeyLightSettingsEntry.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBElgatoKeyLightSettingsEntry::OpenRGBElgatoKeyLightSettingsEntry(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::OpenRGBElgatoKeyLightSettingsEntryUi)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
OpenRGBElgatoKeyLightSettingsEntry::~OpenRGBElgatoKeyLightSettingsEntry()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef OPENRGBELGATOKEYLIGHTSETTINGSENTRY_H
|
||||
#define OPENRGBELGATOKEYLIGHTSETTINGSENTRY_H
|
||||
|
||||
#include "ui_OpenRGBElgatoKeyLightSettingsEntry.h"
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBElgatoKeyLightSettingsEntry;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBElgatoKeyLightSettingsEntry : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBElgatoKeyLightSettingsEntry(QWidget *parent = nullptr);
|
||||
~OpenRGBElgatoKeyLightSettingsEntry();
|
||||
Ui::OpenRGBElgatoKeyLightSettingsEntryUi *ui;
|
||||
};
|
||||
|
||||
#endif // OPENRGBELGATOKEYLIGHTSETTINGSENTRY_H
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBElgatoKeyLightSettingsEntryUi</class>
|
||||
<widget class="QDialog" name="OpenRGBElgatoKeyLightSettingsEntryUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>225</width>
|
||||
<height>85</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="0" rowspan="2" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>IP:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLineEdit" name="IPEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
#include "OpenRGBElgatoKeyLightSettingsPage.h"
|
||||
#include "ui_OpenRGBElgatoKeyLightSettingsPage.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBElgatoKeyLightSettingsPage::OpenRGBElgatoKeyLightSettingsPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBElgatoKeyLightSettingsPageUi)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
json elgato_keylight_settings;
|
||||
|
||||
elgato_keylight_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ElgatoKeyLightDevices");
|
||||
|
||||
/*---------------------------------------------------------------*\
|
||||
| If the Elgato Key Light settings contains devices, process |
|
||||
\*---------------------------------------------------------------*/
|
||||
if(elgato_keylight_settings.contains("devices"))
|
||||
{
|
||||
for(unsigned int device_idx = 0; device_idx < elgato_keylight_settings["devices"].size(); device_idx++)
|
||||
{
|
||||
OpenRGBElgatoKeyLightSettingsEntry* entry = new OpenRGBElgatoKeyLightSettingsEntry;
|
||||
|
||||
if(elgato_keylight_settings["devices"][device_idx].contains("ip"))
|
||||
{
|
||||
entry->ui->IPEdit->setText(QString::fromStdString(elgato_keylight_settings["devices"][device_idx]["ip"]));
|
||||
}
|
||||
|
||||
entries.push_back(entry);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem;
|
||||
|
||||
item->setSizeHint(entry->sizeHint());
|
||||
|
||||
ui->ElgatoKeyLightDeviceList->addItem(item);
|
||||
ui->ElgatoKeyLightDeviceList->setItemWidget(item, entry);
|
||||
ui->ElgatoKeyLightDeviceList->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OpenRGBElgatoKeyLightSettingsPage::~OpenRGBElgatoKeyLightSettingsPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Ui::OpenRGBElgatoKeyLightSettingsPage::on_AddElgatoKeyLightDeviceButton_clicked()
|
||||
{
|
||||
OpenRGBElgatoKeyLightSettingsEntry* entry = new OpenRGBElgatoKeyLightSettingsEntry;
|
||||
entries.push_back(entry);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem;
|
||||
|
||||
item->setSizeHint(entry->sizeHint());
|
||||
|
||||
ui->ElgatoKeyLightDeviceList->addItem(item);
|
||||
ui->ElgatoKeyLightDeviceList->setItemWidget(item, entry);
|
||||
ui->ElgatoKeyLightDeviceList->show();
|
||||
}
|
||||
|
||||
void Ui::OpenRGBElgatoKeyLightSettingsPage::on_RemoveElgatoKeyLightDeviceButton_clicked()
|
||||
{
|
||||
int cur_row = ui->ElgatoKeyLightDeviceList->currentRow();
|
||||
|
||||
if(cur_row < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem* item = ui->ElgatoKeyLightDeviceList->takeItem(cur_row);
|
||||
|
||||
ui->ElgatoKeyLightDeviceList->removeItemWidget(item);
|
||||
delete item;
|
||||
|
||||
delete entries[cur_row];
|
||||
entries.erase(entries.begin() + cur_row);
|
||||
}
|
||||
|
||||
void Ui::OpenRGBElgatoKeyLightSettingsPage::on_SaveElgatoKeyLightConfigurationButton_clicked()
|
||||
{
|
||||
json elgato_keylight_settings;
|
||||
|
||||
elgato_keylight_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ElgatoKeyLightDevices");
|
||||
|
||||
elgato_keylight_settings["devices"].clear();
|
||||
|
||||
for(unsigned int device_idx = 0; device_idx < entries.size(); device_idx++)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Required parameters |
|
||||
\*-------------------------------------------------*/
|
||||
elgato_keylight_settings["devices"][device_idx]["ip"] = entries[device_idx]->ui->IPEdit->text().toStdString();
|
||||
}
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("ElgatoKeyLightDevices", elgato_keylight_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef OPENRGBELGATOKEYLIGHTSETTINGSPAGE_H
|
||||
#define OPENRGBELGATOKEYLIGHTSETTINGSPAGE_H
|
||||
|
||||
#include "ui_OpenRGBElgatoKeyLightSettingsPage.h"
|
||||
#include <QWidget>
|
||||
|
||||
#include "OpenRGBElgatoKeyLightSettingsEntry.h"
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBElgatoKeyLightSettingsPage;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBElgatoKeyLightSettingsPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBElgatoKeyLightSettingsPage(QWidget *parent = nullptr);
|
||||
~OpenRGBElgatoKeyLightSettingsPage();
|
||||
|
||||
private slots:
|
||||
void on_AddElgatoKeyLightDeviceButton_clicked();
|
||||
|
||||
void on_RemoveElgatoKeyLightDeviceButton_clicked();
|
||||
|
||||
void on_SaveElgatoKeyLightConfigurationButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBElgatoKeyLightSettingsPageUi *ui;
|
||||
std::vector<OpenRGBElgatoKeyLightSettingsEntry*> entries;
|
||||
|
||||
};
|
||||
|
||||
#endif // OPENRGBELGATOKEYLIGHTSETTINGSPAGE_H
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBElgatoKeyLightSettingsPageUi</class>
|
||||
<widget class="QWidget" name="OpenRGBElgatoKeyLightSettingsPageUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QListWidget" name="ElgatoKeyLightDeviceList"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="AddElgatoKeyLightDeviceButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="RemoveElgatoKeyLightDeviceButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="SaveElgatoKeyLightConfigurationButton">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Add table
Add a link
Reference in a new issue