mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-11-27 02:44:06 -05:00
Initial DMX controller
This commit is contained in:
1 parent
8b4b2bacbc
commit
5c5ceff4dd
12 files changed
+865
No files matched your search
@@ -0,0 +1,136 @@
|
||||
#include "Detector.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_DMX.h"
|
||||
#include "SettingsManager.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectDMXControllers *
|
||||
* *
|
||||
* Detect devices supported by the DMX driver *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectDMXControllers()
|
||||
{
|
||||
json dmx_settings;
|
||||
|
||||
std::vector<std::vector<DMXDevice>> device_lists;
|
||||
DMXDevice dev;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get DMX settings from settings manager |
|
||||
\*-------------------------------------------------*/
|
||||
dmx_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("DMXDevices");
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the DMX settings contains devices, process |
|
||||
\*-------------------------------------------------*/
|
||||
if(dmx_settings.contains("devices"))
|
||||
{
|
||||
for(unsigned int device_idx = 0; device_idx < dmx_settings["devices"].size(); device_idx++)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Clear DMX device data |
|
||||
\*-------------------------------------------------*/
|
||||
dev.name = "";
|
||||
dev.keepalive_time = 0;
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("name"))
|
||||
{
|
||||
dev.name = dmx_settings["devices"][device_idx]["name"];
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("keepalive_time"))
|
||||
{
|
||||
dev.keepalive_time = dmx_settings["devices"][device_idx]["keepalive_time"];
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("red_channel"))
|
||||
{
|
||||
dev.red_channel = dmx_settings["devices"][device_idx]["red_channel"];
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("green_channel"))
|
||||
{
|
||||
dev.green_channel = dmx_settings["devices"][device_idx]["green_channel"];
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("blue_channel"))
|
||||
{
|
||||
dev.blue_channel = dmx_settings["devices"][device_idx]["blue_channel"];
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("brightness_channel"))
|
||||
{
|
||||
dev.brightness_channel = dmx_settings["devices"][device_idx]["brightness_channel"];
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Determine whether to create a new list or add this device |
|
||||
| to an existing list. A device is added to an existing |
|
||||
| list if both devices share one or more universes for the |
|
||||
| same output destination |
|
||||
\*---------------------------------------------------------*/
|
||||
bool device_added_to_existing_list = false;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Track grouping for all controllers. |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++)
|
||||
{
|
||||
for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Check if the port used by this new device is the same as |
|
||||
| in the existing device. If so, add the new device to the |
|
||||
| existing list. |
|
||||
\*---------------------------------------------------------*/
|
||||
if(1)
|
||||
{
|
||||
device_lists[list_idx].push_back(dev);
|
||||
device_added_to_existing_list = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(device_added_to_existing_list)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| If the device did not overlap with existing devices, |
|
||||
| create a new list for it |
|
||||
\*---------------------------------------------------------*/
|
||||
if(!device_added_to_existing_list)
|
||||
{
|
||||
std::vector<DMXDevice> new_list;
|
||||
|
||||
new_list.push_back(dev);
|
||||
|
||||
device_lists.push_back(new_list);
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++)
|
||||
{
|
||||
RGBController_DMX* rgb_controller;
|
||||
rgb_controller = new RGBController_DMX(device_lists[list_idx]);
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
} /* DetectDMXControllers() */
|
||||
|
||||
REGISTER_DETECTOR("DMX", DetectDMXControllers);
|
||||
@@ -0,0 +1,239 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_DMX.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for OpenAuraSDK |
|
||||
| DMX interface |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 4/30/2023 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_DMX.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "LogManager.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name DMX Devices
|
||||
@category LEDStrip
|
||||
@type Serial
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectDMXControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_DMX::RGBController_DMX(std::vector<DMXDevice> device_list)
|
||||
{
|
||||
devices = device_list;
|
||||
|
||||
name = "DMX Device Group";
|
||||
type = DEVICE_TYPE_LEDSTRIP;
|
||||
description = "DMX Device";
|
||||
location = "DMX";
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| If this controller only represents a |
|
||||
| single device, use the device name for the|
|
||||
| controller name |
|
||||
\*-----------------------------------------*/
|
||||
if(devices.size() == 1)
|
||||
{
|
||||
name = devices[0].name;
|
||||
}
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Open OpenDMX FTDI |
|
||||
\*-----------------------------------------*/
|
||||
ftdi_device_list* devlist;
|
||||
ftdi = ftdi_new();
|
||||
//ftdi_usb_open(ftdi, 0x0403, 0x6001);
|
||||
LOG_WARNING("ftdi_set_interface %d", ftdi_set_interface(ftdi, INTERFACE_ANY));
|
||||
LOG_WARNING("ftdi_usb_find_all %d", ftdi_usb_find_all(ftdi, &devlist, 0, 0));
|
||||
LOG_WARNING("ftdi_usb_open_dev %d", ftdi_usb_open_dev(ftdi, devlist[0].dev));
|
||||
ftdi_list_free(&devlist);
|
||||
LOG_WARNING("ftdi_set_baudrate %d", ftdi_set_baudrate(ftdi, 250000));
|
||||
LOG_WARNING("ftdi_set_line_property2 %d", ftdi_set_line_property2(ftdi, BITS_8, STOP_BIT_2, NONE, BREAK_ON));
|
||||
LOG_WARNING("ftdi_usb_purge_buffers %d", ftdi_usb_purge_buffers(ftdi));
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Set up modes |
|
||||
\*-----------------------------------------*/
|
||||
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 = 255;
|
||||
Direct.brightness_min = 0;
|
||||
Direct.brightness_max = 255;
|
||||
modes.push_back(Direct);
|
||||
|
||||
keepalive_delay = 0ms;
|
||||
|
||||
SetupZones();
|
||||
|
||||
for (std::size_t device_idx = 0; device_idx < devices.size(); device_idx++)
|
||||
{
|
||||
/*-----------------------------------------*\
|
||||
| Update keepalive delay |
|
||||
\*-----------------------------------------*/
|
||||
if(devices[device_idx].keepalive_time > 0)
|
||||
{
|
||||
if(keepalive_delay.count() == 0 || keepalive_delay.count() > devices[device_idx].keepalive_time)
|
||||
{
|
||||
keepalive_delay = std::chrono::milliseconds(devices[device_idx].keepalive_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(keepalive_delay.count() > 0)
|
||||
{
|
||||
keepalive_thread_run = 1;
|
||||
keepalive_thread = new std::thread(&RGBController_DMX::KeepaliveThreadFunction, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
keepalive_thread_run = 0;
|
||||
keepalive_thread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RGBController_DMX::~RGBController_DMX()
|
||||
{
|
||||
if(keepalive_thread != nullptr)
|
||||
{
|
||||
keepalive_thread_run = 0;
|
||||
keepalive_thread->join();
|
||||
delete keepalive_thread;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Delete the matrix map |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
|
||||
{
|
||||
if(zones[zone_index].matrix_map != NULL)
|
||||
{
|
||||
if(zones[zone_index].matrix_map->map != NULL)
|
||||
{
|
||||
delete zones[zone_index].matrix_map->map;
|
||||
}
|
||||
|
||||
delete zones[zone_index].matrix_map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_DMX::SetupZones()
|
||||
{
|
||||
/*-----------------------------------------*\
|
||||
| Add Zones |
|
||||
\*-----------------------------------------*/
|
||||
for(std::size_t zone_idx = 0; zone_idx < devices.size(); zone_idx++)
|
||||
{
|
||||
zone led_zone;
|
||||
led_zone.name = devices[zone_idx].name;
|
||||
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);
|
||||
}
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Add LEDs |
|
||||
\*-----------------------------------------*/
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
for(std::size_t led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
|
||||
new_led.name = zones[zone_idx].name + " LED ";
|
||||
new_led.name.append(std::to_string(led_idx));
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_DMX::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_DMX::DeviceUpdateLEDs()
|
||||
{
|
||||
int color_idx = 0;
|
||||
|
||||
last_update_time = std::chrono::steady_clock::now();
|
||||
|
||||
unsigned char dmx_data[512];
|
||||
const unsigned char startcode = 0;
|
||||
|
||||
memset(dmx_data, 0, sizeof(dmx_data));
|
||||
|
||||
for(unsigned int device_idx = 0; device_idx < devices.size(); device_idx++)
|
||||
{
|
||||
if(devices[device_idx].brightness_channel > 0)
|
||||
{
|
||||
dmx_data[devices[device_idx].brightness_channel - 1] = modes[0].brightness;
|
||||
}
|
||||
|
||||
if(devices[device_idx].red_channel > 0)
|
||||
{
|
||||
dmx_data[devices[device_idx].red_channel - 1] = RGBGetRValue(colors[device_idx]);
|
||||
}
|
||||
|
||||
if(devices[device_idx].green_channel > 0)
|
||||
{
|
||||
dmx_data[devices[device_idx].green_channel - 1] = RGBGetGValue(colors[device_idx]);
|
||||
}
|
||||
|
||||
if(devices[device_idx].blue_channel > 0)
|
||||
{
|
||||
dmx_data[devices[device_idx].blue_channel - 1] = RGBGetBValue(colors[device_idx]);
|
||||
}
|
||||
}
|
||||
|
||||
ftdi_set_line_property2(ftdi, BITS_8, STOP_BIT_2, NONE, BREAK_ON);
|
||||
ftdi_set_line_property2(ftdi, BITS_8, STOP_BIT_2, NONE, BREAK_OFF);
|
||||
ftdi_write_data(ftdi, &startcode, 1);
|
||||
ftdi_write_data(ftdi, (const unsigned char*)dmx_data, sizeof(dmx_data));
|
||||
}
|
||||
|
||||
void RGBController_DMX::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_DMX::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_DMX::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_DMX::KeepaliveThreadFunction()
|
||||
{
|
||||
while(keepalive_thread_run.load())
|
||||
{
|
||||
if((std::chrono::steady_clock::now() - last_update_time) > ( keepalive_delay * 0.95f ) )
|
||||
{
|
||||
UpdateLEDs();
|
||||
}
|
||||
std::this_thread::sleep_for(keepalive_delay / 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_DMX.h |
|
||||
| |
|
||||
| Generic RGB Interface for OpenAuraSDK |
|
||||
| DMX interface |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 4/30/2023 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "serial_port.h"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <libftdi1/ftdi.h>
|
||||
|
||||
struct DMXDevice
|
||||
{
|
||||
std::string name;
|
||||
unsigned int keepalive_time;
|
||||
unsigned int red_channel;
|
||||
unsigned int green_channel;
|
||||
unsigned int blue_channel;
|
||||
unsigned int brightness_channel;
|
||||
};
|
||||
|
||||
class RGBController_DMX : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_DMX(std::vector<DMXDevice> device_list);
|
||||
~RGBController_DMX();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
void KeepaliveThreadFunction();
|
||||
|
||||
private:
|
||||
std::vector<DMXDevice> devices;
|
||||
ftdi_context * ftdi;
|
||||
std::thread * keepalive_thread;
|
||||
std::atomic<bool> keepalive_thread_run;
|
||||
std::chrono::milliseconds keepalive_delay;
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
|
||||
};
|
||||
+11
@@ -108,6 +108,7 @@ INCLUDEPATH +=
|
||||
Controllers/CryorigH7QuadLumiController/ \
|
||||
Controllers/DasKeyboardController/ \
|
||||
Controllers/DebugController/ \
|
||||
Controllers/DMXController/ \
|
||||
Controllers/DuckyKeyboardController/ \
|
||||
Controllers/DygmaRaiseController/ \
|
||||
Controllers/E131Controller/ \
|
||||
@@ -240,6 +241,8 @@ HEADERS +=
|
||||
qt/OpenRGBSystemInfoPage.h \
|
||||
qt/OpenRGBThemeManager.h \
|
||||
qt/OpenRGBZoneResizeDialog.h \
|
||||
qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.h \
|
||||
qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.h \
|
||||
qt/OpenRGBE131SettingsPage/OpenRGBE131SettingsEntry.h \
|
||||
qt/OpenRGBE131SettingsPage/OpenRGBE131SettingsPage.h \
|
||||
qt/OpenRGBLIFXSettingsPage/OpenRGBLIFXSettingsEntry.h \
|
||||
@@ -393,6 +396,7 @@ HEADERS +=
|
||||
Controllers/DarkProject/RGBController_DarkProjectKeyboard.h \
|
||||
Controllers/DasKeyboardController/DasKeyboardController.h \
|
||||
Controllers/DasKeyboardController/RGBController_DasKeyboard.h \
|
||||
Controllers/DMXController/RGBController_DMX.h \
|
||||
Controllers/DuckyKeyboardController/DuckyKeyboardController.h \
|
||||
Controllers/DuckyKeyboardController/RGBController_DuckyKeyboard.h \
|
||||
Controllers/DygmaRaiseController/DygmaRaiseController.h \
|
||||
@@ -799,6 +803,8 @@ SOURCES +=
|
||||
qt/QTooltipedSlider.cpp \
|
||||
qt/TabLabel.cpp \
|
||||
qt/hsv.cpp \
|
||||
qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.cpp \
|
||||
qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.cpp \
|
||||
qt/OpenRGBE131SettingsPage/OpenRGBE131SettingsEntry.cpp \
|
||||
qt/OpenRGBE131SettingsPage/OpenRGBE131SettingsPage.cpp \
|
||||
qt/OpenRGBLIFXSettingsPage/OpenRGBLIFXSettingsEntry.cpp \
|
||||
@@ -981,6 +987,8 @@ SOURCES +=
|
||||
Controllers/DasKeyboardController/DasKeyboardController.cpp \
|
||||
Controllers/DasKeyboardController/DasKeyboardControllerDetect.cpp \
|
||||
Controllers/DasKeyboardController/RGBController_DasKeyboard.cpp \
|
||||
Controllers/DMXController/DMXControllerDetect.cpp \
|
||||
Controllers/DMXController/RGBController_DMX.cpp \
|
||||
Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp \
|
||||
Controllers/DuckyKeyboardController/DuckyKeyboardControllerDetect.cpp \
|
||||
Controllers/DuckyKeyboardController/RGBController_DuckyKeyboard.cpp \
|
||||
@@ -1426,6 +1434,8 @@ FORMS +=
|
||||
qt/OpenRGBSupportedDevicesPage.ui \
|
||||
qt/OpenRGBSystemInfoPage.ui \
|
||||
qt/OpenRGBZoneResizeDialog.ui \
|
||||
qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.ui \
|
||||
qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.ui \
|
||||
qt/OpenRGBE131SettingsPage/OpenRGBE131SettingsEntry.ui \
|
||||
qt/OpenRGBE131SettingsPage/OpenRGBE131SettingsPage.ui \
|
||||
qt/OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsEntry.ui \
|
||||
@@ -1701,6 +1711,7 @@ contains(QMAKE_PLATFORM, linux) {
|
||||
-lmbedtls \
|
||||
-lmbedcrypto \
|
||||
-ldl \
|
||||
-lftdi1 \
|
||||
|
||||
COMPILER_VERSION = $$system($$QMAKE_CXX " -dumpversion")
|
||||
if (!versionAtLeast(COMPILER_VERSION, "9")) {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "OpenRGBDMXSettingsEntry.h"
|
||||
#include "ui_OpenRGBDMXSettingsEntry.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBDMXSettingsEntry::OpenRGBDMXSettingsEntry(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBDMXSettingsEntryUi)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
OpenRGBDMXSettingsEntry::~OpenRGBDMXSettingsEntry()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OpenRGBDMXSettingsEntry::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDMXSettingsEntry::on_TypeComboBox_currentIndexChanged(int index)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef OPENRGBDMXSETTINGSENTRY_H
|
||||
#define OPENRGBDMXSETTINGSENTRY_H
|
||||
|
||||
#include "ui_OpenRGBDMXSettingsEntry.h"
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBDMXSettingsEntry;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBDMXSettingsEntry : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBDMXSettingsEntry(QWidget *parent = nullptr);
|
||||
~OpenRGBDMXSettingsEntry();
|
||||
Ui::OpenRGBDMXSettingsEntryUi *ui;
|
||||
|
||||
private slots:
|
||||
void changeEvent(QEvent *event);
|
||||
void on_TypeComboBox_currentIndexChanged(int index);
|
||||
};
|
||||
|
||||
#endif // OPENRGBDMXSETTINGSENTRY_H
|
||||
@@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBDMXSettingsEntryUi</class>
|
||||
<widget class="QWidget" name="OpenRGBDMXSettingsEntryUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>531</width>
|
||||
<height>199</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>E131 settings entry</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="3" column="5">
|
||||
<widget class="QLineEdit" name="GreenEdit"/>
|
||||
</item>
|
||||
<item row="4" column="5">
|
||||
<widget class="QLineEdit" name="BrightnessEdit"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="RedLabel">
|
||||
<property name="text">
|
||||
<string>Red Channel:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="4">
|
||||
<widget class="QLabel" name="BrightnessLabel">
|
||||
<property name="text">
|
||||
<string>Brightness Channel:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QLineEdit" name="BlueEdit"/>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="NameEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="NameLabel">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="4">
|
||||
<widget class="QLabel" name="GreenLabel">
|
||||
<property name="text">
|
||||
<string>Green Channel:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Blue Channel:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QLineEdit" name="RedEdit"/>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QLabel" name="KeepaliveTimeLabel">
|
||||
<property name="text">
|
||||
<string>Keepalive Time:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
<widget class="QLineEdit" name="KeepaliveTimeEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>NameEdit</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,154 @@
|
||||
#include "OpenRGBDMXSettingsPage.h"
|
||||
#include "ui_OpenRGBDMXSettingsPage.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBDMXSettingsPage::OpenRGBDMXSettingsPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBDMXSettingsPageUi)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
json dmx_settings;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get DMX settings from settings manager |
|
||||
\*-------------------------------------------------*/
|
||||
dmx_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("DMXDevices");
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the DMX settings contains devices, process |
|
||||
\*-------------------------------------------------*/
|
||||
if(dmx_settings.contains("devices"))
|
||||
{
|
||||
for(unsigned int device_idx = 0; device_idx < dmx_settings["devices"].size(); device_idx++)
|
||||
{
|
||||
OpenRGBDMXSettingsEntry* entry = new OpenRGBDMXSettingsEntry;
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("name"))
|
||||
{
|
||||
entry->ui->NameEdit->setText(QString::fromStdString(dmx_settings["devices"][device_idx]["name"]));
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("red_channel"))
|
||||
{
|
||||
entry->ui->RedEdit->setText(QString::number((int)dmx_settings["devices"][device_idx]["red_channel"]));
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("green_channel"))
|
||||
{
|
||||
entry->ui->GreenEdit->setText(QString::number((int)dmx_settings["devices"][device_idx]["green_channel"]));
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("blue_channel"))
|
||||
{
|
||||
entry->ui->BlueEdit->setText(QString::number((int)dmx_settings["devices"][device_idx]["blue_channel"]));
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("brightness_channel"))
|
||||
{
|
||||
entry->ui->BrightnessEdit->setText(QString::number((int)dmx_settings["devices"][device_idx]["brightness_channel"]));
|
||||
}
|
||||
|
||||
if(dmx_settings["devices"][device_idx].contains("keepalive_time"))
|
||||
{
|
||||
entry->ui->KeepaliveTimeEdit->setText(QString::number((int)dmx_settings["devices"][device_idx]["keepalive_time"]));
|
||||
}
|
||||
|
||||
entries.push_back(entry);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem;
|
||||
|
||||
item->setSizeHint(entry->sizeHint());
|
||||
|
||||
ui->DMXDeviceList->addItem(item);
|
||||
ui->DMXDeviceList->setItemWidget(item, entry);
|
||||
ui->DMXDeviceList->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OpenRGBDMXSettingsPage::~OpenRGBDMXSettingsPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OpenRGBDMXSettingsPage::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDMXSettingsPage::on_AddDMXDeviceButton_clicked()
|
||||
{
|
||||
OpenRGBDMXSettingsEntry* entry = new OpenRGBDMXSettingsEntry;
|
||||
entries.push_back(entry);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem;
|
||||
|
||||
item->setSizeHint(entry->sizeHint());
|
||||
|
||||
ui->DMXDeviceList->addItem(item);
|
||||
ui->DMXDeviceList->setItemWidget(item, entry);
|
||||
ui->DMXDeviceList->show();
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDMXSettingsPage::on_RemoveDMXDeviceButton_clicked()
|
||||
{
|
||||
int cur_row = ui->DMXDeviceList->currentRow();
|
||||
|
||||
if(cur_row < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem* item = ui->DMXDeviceList->takeItem(cur_row);
|
||||
|
||||
ui->DMXDeviceList->removeItemWidget(item);
|
||||
delete item;
|
||||
|
||||
delete entries[cur_row];
|
||||
entries.erase(entries.begin() + cur_row);
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDMXSettingsPage::on_SaveDMXConfigurationButton_clicked()
|
||||
{
|
||||
json dmx_settings;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Get DMX settings from settings manager |
|
||||
\*-------------------------------------------------*/
|
||||
dmx_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("DMXDevices");
|
||||
|
||||
dmx_settings["devices"].clear();
|
||||
|
||||
for(unsigned int device_idx = 0; device_idx < entries.size(); device_idx++)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Required parameters |
|
||||
\*-------------------------------------------------*/
|
||||
dmx_settings["devices"][device_idx]["name"] = entries[device_idx]->ui->NameEdit->text().toStdString();
|
||||
dmx_settings["devices"][device_idx]["red_channel"] = entries[device_idx]->ui->RedEdit->text().toUInt();
|
||||
dmx_settings["devices"][device_idx]["green_channel"] = entries[device_idx]->ui->GreenEdit->text().toUInt();
|
||||
dmx_settings["devices"][device_idx]["blue_channel"] = entries[device_idx]->ui->BlueEdit->text().toUInt();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Optional parameters |
|
||||
\*-------------------------------------------------*/
|
||||
if(entries[device_idx]->ui->BrightnessEdit->text() != "")
|
||||
{
|
||||
dmx_settings["devices"][device_idx]["brightness_channel"] = entries[device_idx]->ui->BrightnessEdit->text().toUInt();
|
||||
}
|
||||
|
||||
if(entries[device_idx]->ui->KeepaliveTimeEdit->text() != "")
|
||||
{
|
||||
dmx_settings["devices"][device_idx]["keepalive_time"] = entries[device_idx]->ui->KeepaliveTimeEdit->text().toUInt();
|
||||
}
|
||||
}
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("DMXDevices", dmx_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef OPENRGBDMXSETTINGSPAGE_H
|
||||
#define OPENRGBDMXSETTINGSPAGE_H
|
||||
|
||||
#include "ui_OpenRGBDMXSettingsPage.h"
|
||||
#include <QWidget>
|
||||
|
||||
#include "OpenRGBDMXSettingsEntry.h"
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBDMXSettingsPage;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBDMXSettingsPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBDMXSettingsPage(QWidget *parent = nullptr);
|
||||
~OpenRGBDMXSettingsPage();
|
||||
|
||||
private slots:
|
||||
void changeEvent(QEvent *event);
|
||||
void on_AddDMXDeviceButton_clicked();
|
||||
|
||||
void on_RemoveDMXDeviceButton_clicked();
|
||||
|
||||
void on_SaveDMXConfigurationButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBDMXSettingsPageUi* ui;
|
||||
std::vector<OpenRGBDMXSettingsEntry*> entries;
|
||||
|
||||
};
|
||||
|
||||
#endif // OPENRGBDMXSETTINGSPAGE_H
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBDMXSettingsPageUi</class>
|
||||
<widget class="QWidget" name="OpenRGBDMXSettingsPageUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>E131 settings page</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="AddDMXDeviceButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="RemoveDMXDeviceButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="SaveDMXConfigurationButton">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QListWidget" name="DMXDeviceList">
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -432,6 +432,11 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
|
||||
\*-----------------------------------------------------*/
|
||||
AddPluginsPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the DMX settings page |
|
||||
\*-----------------------------------------------------*/
|
||||
AddDMXSettingsPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the E1.31 settings page |
|
||||
\*-----------------------------------------------------*/
|
||||
@@ -757,6 +762,34 @@ void OpenRGBDialog2::AddSettingsPage()
|
||||
connect(this, SIGNAL(ProfileListChanged()), SettingsPage, SLOT(UpdateProfiles()));
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddDMXSettingsPage()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the Settings page |
|
||||
\*-----------------------------------------------------*/
|
||||
DMXSettingsPage = new OpenRGBDMXSettingsPage();
|
||||
|
||||
ui->SettingsTabBar->addTab(DMXSettingsPage, "");
|
||||
|
||||
QString SettingsLabelString;
|
||||
|
||||
if(OpenRGBThemeManager::IsDarkTheme())
|
||||
{
|
||||
SettingsLabelString = "serial_dark.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsLabelString = "serial.png";
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the tab label |
|
||||
\*-----------------------------------------------------*/
|
||||
TabLabel* SettingsTabLabel = new TabLabel(SettingsLabelString, tr("DMX Devices"), (char *)"DMX Devices", (char *)context);
|
||||
|
||||
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel);
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddE131SettingsPage()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "OpenRGBSystemInfoPage.h"
|
||||
#include "OpenRGBSupportedDevicesPage.h"
|
||||
#include "OpenRGBSettingsPage.h"
|
||||
#include "OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.h"
|
||||
#include "OpenRGBE131SettingsPage/OpenRGBE131SettingsPage.h"
|
||||
#include "OpenRGBElgatoKeyLightSettingsPage/OpenRGBElgatoKeyLightSettingsPage.h"
|
||||
#include "OpenRGBKasaSmartSettingsPage/OpenRGBKasaSmartSettingsPage.h"
|
||||
@@ -84,6 +85,7 @@ private:
|
||||
OpenRGBSoftwareInfoPage *SoftInfoPage;
|
||||
OpenRGBSupportedDevicesPage *SupportedPage;
|
||||
OpenRGBSettingsPage *SettingsPage;
|
||||
OpenRGBDMXSettingsPage *DMXSettingsPage;
|
||||
OpenRGBE131SettingsPage *E131SettingsPage;
|
||||
OpenRGBElgatoKeyLightSettingsPage *ElgatoKeyLightSettingsPage;
|
||||
OpenRGBKasaSmartSettingsPage *KasaSmartSettingsPage;
|
||||
@@ -112,6 +114,7 @@ private:
|
||||
void AddSoftwareInfoPage();
|
||||
void AddSupportedDevicesPage();
|
||||
void AddSettingsPage();
|
||||
void AddDMXSettingsPage();
|
||||
void AddE131SettingsPage();
|
||||
void AddElgatoKeyLightSettingsPage();
|
||||
void AddKasaSmartSettingsPage();
|
||||
|
||||
Reference in new issue
Block a user