diff --git a/Controllers/DMXController/DMXControllerDetect.cpp b/Controllers/DMXController/DMXControllerDetect.cpp new file mode 100644 index 000000000..d2d5c575a --- /dev/null +++ b/Controllers/DMXController/DMXControllerDetect.cpp @@ -0,0 +1,136 @@ +#include "Detector.h" +#include "RGBController.h" +#include "RGBController_DMX.h" +#include "SettingsManager.h" +#include +#include +#include + +#include +#include +#include +#include +#include + +/******************************************************************************************\ +* * +* DetectDMXControllers * +* * +* Detect devices supported by the DMX driver * +* * +\******************************************************************************************/ + +void DetectDMXControllers() +{ + json dmx_settings; + + std::vector> 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 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); diff --git a/Controllers/DMXController/RGBController_DMX.cpp b/Controllers/DMXController/RGBController_DMX.cpp new file mode 100644 index 000000000..1fa379c6e --- /dev/null +++ b/Controllers/DMXController/RGBController_DMX.cpp @@ -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 + +#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 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); + } +} diff --git a/Controllers/DMXController/RGBController_DMX.h b/Controllers/DMXController/RGBController_DMX.h new file mode 100644 index 000000000..c3a452ee4 --- /dev/null +++ b/Controllers/DMXController/RGBController_DMX.h @@ -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 +#include +#include + +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 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 devices; + ftdi_context * ftdi; + std::thread * keepalive_thread; + std::atomic keepalive_thread_run; + std::chrono::milliseconds keepalive_delay; + std::chrono::time_point last_update_time; +}; diff --git a/OpenRGB.pro b/OpenRGB.pro index 92360e677..590039969 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -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")) { diff --git a/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.cpp b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.cpp new file mode 100644 index 000000000..5ab8ad5ed --- /dev/null +++ b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.cpp @@ -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) +{ + +} diff --git a/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.h b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.h new file mode 100644 index 000000000..75c82a1b7 --- /dev/null +++ b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.h @@ -0,0 +1,25 @@ +#ifndef OPENRGBDMXSETTINGSENTRY_H +#define OPENRGBDMXSETTINGSENTRY_H + +#include "ui_OpenRGBDMXSettingsEntry.h" +#include + +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 diff --git a/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.ui b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.ui new file mode 100644 index 000000000..24acbd14b --- /dev/null +++ b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsEntry.ui @@ -0,0 +1,99 @@ + + + OpenRGBDMXSettingsEntryUi + + + + 0 + 0 + 531 + 199 + + + + + 0 + 0 + + + + E131 settings entry + + + + + + + + + + + + + + + + + + Red Channel: + + + + + + + Brightness Channel: + + + + + + + + + + + + + Name: + + + + + + + Green Channel: + + + + + + + Blue Channel: + + + + + + + + + + Keepalive Time: + + + + + + + + + + + + + NameEdit + + + + diff --git a/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.cpp b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.cpp new file mode 100644 index 000000000..35d30daad --- /dev/null +++ b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.cpp @@ -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(); +} diff --git a/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.h b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.h new file mode 100644 index 000000000..5427b4a92 --- /dev/null +++ b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.h @@ -0,0 +1,35 @@ +#ifndef OPENRGBDMXSETTINGSPAGE_H +#define OPENRGBDMXSETTINGSPAGE_H + +#include "ui_OpenRGBDMXSettingsPage.h" +#include + +#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 entries; + +}; + +#endif // OPENRGBDMXSETTINGSPAGE_H diff --git a/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.ui b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.ui new file mode 100644 index 000000000..850191823 --- /dev/null +++ b/qt/OpenRGBDMXSettingsPage/OpenRGBDMXSettingsPage.ui @@ -0,0 +1,49 @@ + + + OpenRGBDMXSettingsPageUi + + + + 0 + 0 + 400 + 300 + + + + E131 settings page + + + + + + Add + + + + + + + Remove + + + + + + + Save + + + + + + + QAbstractItemView::ScrollPerPixel + + + + + + + + diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 444107f0b..4c2e9a635 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -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() { /*-----------------------------------------------------*\ diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index 54bab9f02..907cb4653 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -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();