Compare commits

...
Author SHA1 Message Date
Adam Honse ebaed20534 Clean up unused hidapi files 2020-03-01 15:43:18 -06:00
Adam Honse 85d91d2d63 Add refreshing thread for HyperX keyboard Direct mode 2020-03-01 11:52:44 -06:00
Adam Honse 8d2f188c0b Add timeouts to fix HyperX and Poseidon Z RGB in Linux 2020-03-01 11:52:05 -06:00
Adam Honse 4ba3beab63 Get hidapi over libusb working on linux 2020-02-29 16:03:52 -06:00
Adam Honse b92082b545 libusb-based hidapi on Windows 2020-02-29 16:03:11 -06:00
Adam Honse c7960c090a Add software version information to CLI 2020-02-29 14:01:06 -06:00
Adam Honse 85b2545409 Fill in software information and set version to 0.0 for now 2020-02-29 13:45:43 -06:00
Adam Honse e10881db3e Add empty software information tab to information UI 2020-02-28 12:31:32 -06:00
Adam Honse 977feabe6e Add profile selection to system tray icon menu 2020-02-27 13:16:10 -06:00
Adam Honse a6c9d1232a Don't apply colors unless per LED mode 2020-02-26 21:16:02 -06:00
Adam Honse 4024e6de85 Fix build on Linux 2020-02-26 19:40:25 -06:00
Adam Honse f3df584d3a Don't update devices if the profile could not be loaded 2020-02-26 19:36:00 -06:00
Adam Honse 60a0ab5c93 Populate profile list with .orp files and load profile selected in list 2020-02-26 19:36:00 -06:00
Adam Honse c908847577 Add dialog to name profile. Save all controllers to a single file. Add a file header with version number and use extension .orp for OpenRgb Profile 2020-02-26 19:36:00 -06:00
Adam Honse bd027e596e Set colors when updating mode 2020-02-26 19:36:00 -06:00
Adam Honse 51c3568f7a Profile save and load test 2020-02-26 19:36:00 -06:00
Adam Honse 4f8db7d63f Add cstring include to fix build on Linux 2020-02-25 21:07:06 -06:00
26 changed files with 2255 additions and 53 deletions
@@ -137,7 +137,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
red_color_data
);
Sleep(2);
Sleep(5);
SendDirect
(
@@ -145,7 +145,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
grn_color_data
);
Sleep(2);
Sleep(5);
SendDirect
(
@@ -153,7 +153,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
blu_color_data
);
Sleep(2);
Sleep(5);
SendDirectExtended
(
@@ -189,6 +189,8 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
red_color_data
);
Sleep(5);
SendColor
(
0x01,
@@ -196,6 +198,8 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
grn_color_data
);
Sleep(5);
SendColor
(
0x01,
@@ -203,6 +207,8 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
blu_color_data
);
Sleep(5);
SendExtendedColor
(
0x01,
@@ -104,6 +104,9 @@ void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors)
| Send packets |
\*-----------------------------------------------------*/
hid_send_feature_report(dev, red_grn_buf, 264);
Sleep(5);
hid_send_feature_report(dev, blu_buf, 264);
}
+1 -1
View File
@@ -310,7 +310,7 @@ void DetectRGBFusion2Controllers(std::vector<RGBController*> &rgb_controllers);
* Detect and populate RGB Controllers vector *
* *
\******************************************************************************************/
#include "RGBController_Dummy.h"
void DetectRGBControllers(void)
{
DetectI2CBusses();
+24 -13
View File
@@ -5,6 +5,20 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenRGB
TEMPLATE = app
VERSION = 0.0
win32:BUILDDATE = $$system(date /t)
unix:BUILDDATE = $$system(date -R)
GIT_COMMIT_ID = $$system(git --git-dir $$_PRO_FILE_PWD_/.git --work-tree $$_PRO_FILE_PWD_ rev-parse HEAD)
GIT_COMMIT_DATE = $$system(git --git-dir $$_PRO_FILE_PWD_/.git --work-tree $$_PRO_FILE_PWD_ show -s --format=%ci HEAD)
GIT_BRANCH = $$system(git --git-dir $$_PRO_FILE_PWD_/.git --work-tree $$_PRO_FILE_PWD_ rev-parse --abbrev-ref HEAD)
DEFINES += \
VERSION_STRING=\\"\"\"$$VERSION\\"\"\" \
BUILDDATE_STRING=\\"\"\"$$BUILDDATE\\"\"\" \
GIT_COMMIT_ID=\\"\"\"$$GIT_COMMIT_ID\\"\"\" \
GIT_COMMIT_DATE=\\"\"\"$$GIT_COMMIT_DATE\\"\"\" \
GIT_BRANCH=\\"\"\"$$GIT_BRANCH\\"\"\"
RC_ICONS = qt/OpenRGB.ico
INCLUDEPATH += \
@@ -52,6 +66,8 @@ SOURCES += \
i2c_tools/i2c_tools.cpp \
net_port/net_port.cpp \
qt/OpenRGBDialog2.cpp \
qt/OpenRGBProfileSaveDialog.cpp \
qt/OpenRGBSoftwareInfoPage.cpp \
qt/OpenRGBSystemInfoPage.cpp \
qt/hsv.cpp \
serial_port/serial_port.cpp \
@@ -138,6 +154,8 @@ HEADERS += \
i2c_tools/i2c_tools.h \
net_port/net_port.h \
qt/OpenRGBDialog2.h \
qt/OpenRGBProfileSaveDialog.h \
qt/OpenRGBSoftwareInfoPage.h \
qt/OpenRGBSystemInfoPage.h \
serial_port/find_usb_serial_port.h \
serial_port/serial_port.h \
@@ -199,6 +217,8 @@ FORMS += \
qt/OpenRGBDevicePage.ui \
qt/OpenRGBDialog.ui \
qt/OpenRGBDialog2.ui \
qt/OpenRGBProfileSaveDialog.ui \
qt/OpenRGBSoftwareInfoPage.ui \
qt/OpenRGBSystemInfoPage.ui
#-----------------------------------------------
@@ -214,6 +234,7 @@ win32:INCLUDEPATH += \
win32:SOURCES += \
dependencies/NVFC/nvapi.cpp \
dependencies/hidapi/hid_win.c \
i2c_smbus/i2c_smbus_i801.cpp \
i2c_smbus/i2c_smbus_nct6775.cpp \
i2c_smbus/i2c_smbus_nvapi.cpp \
@@ -238,7 +259,6 @@ win32:contains(QMAKE_TARGET.arch, x86_64) {
-lws2_32 \
-L"$$PWD/dependencies/inpout32_1501/x64/" -linpoutx64 \
-L"$$PWD/dependencies/libusb-1.0.22/MS64/dll" -llibusb-1.0 \
-L"$$PWD/dependencies/hidapi-win/x64/" -lhidapi
}
win32:contains(QMAKE_TARGET.arch, x86) {
@@ -246,7 +266,6 @@ win32:contains(QMAKE_TARGET.arch, x86) {
-lws2_32 \
-L"$$PWD/dependencies/inpout32_1501/Win32/" -linpout32 \
-L"$$PWD/dependencies/libusb-1.0.22/MS32/dll" -llibusb-1.0 \
-L"$$PWD/dependencies/hidapi-win/x86/" -lhidapi
}
win32:DEFINES -= \
@@ -280,6 +299,7 @@ win32:contains(QMAKE_TARGET.arch, x86) {
# Linux specific project configuration
#-----------------------------------------------
unix:INCLUDEPATH += \
dependencies/hidapi \
unix:HEADERS += \
i2c_smbus/i2c_smbus_linux.h \
@@ -287,19 +307,10 @@ unix:HEADERS += \
unix:LIBS += \
-lusb-1.0 \
packagesExist(hidapi-libusb){
unix:LIBS += -lhidapi-libusb
} else {
packagesExist(hidapi) {
unix:LIBS += -lhidapi
} else {
unix:LIBS += -lhidapi-libusb
}
}
-lstdc++fs \
unix:SOURCES += \
dependencies/hidapi/hid_win.c \
i2c_smbus/i2c_smbus_linux.cpp \
serial_port/find_usb_serial_port_linux.cpp \
RGBController/OpenRazerDetect.cpp \
+10
View File
@@ -1,4 +1,5 @@
#include "RGBController.h"
#include <cstring>
unsigned char * RGBController::GetDeviceDescription()
{
@@ -26,6 +27,7 @@ unsigned char * RGBController::GetDeviceDescription()
unsigned short *zone_map_rows = new unsigned short[num_zones];
data_size += sizeof(data_size);
data_size += sizeof(device_type);
data_size += name_len + sizeof(name_len);
data_size += description_len + sizeof(description_len);
@@ -94,6 +96,12 @@ unsigned char * RGBController::GetDeviceDescription()
\*---------------------------------------------------------*/
unsigned char *data_buf = new unsigned char[data_size];
/*---------------------------------------------------------*\
| Copy in data size |
\*---------------------------------------------------------*/
memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size));
data_ptr += sizeof(data_size);
/*---------------------------------------------------------*\
| Copy in type |
\*---------------------------------------------------------*/
@@ -357,6 +365,8 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf)
{
unsigned int data_ptr = 0;
data_ptr += sizeof(unsigned int);
/*---------------------------------------------------------*\
| Copy in type |
\*---------------------------------------------------------*/
@@ -9,6 +9,41 @@
#include "RGBController_HyperXKeyboard.h"
//Include thread libraries for Windows or Linux
#ifdef WIN32
#include <process.h>
#else
#include "pthread.h"
#include "unistd.h"
#endif
//Thread functions have different types in Windows and Linux
#ifdef WIN32
#define THREAD static void
#define THREADRETURN
#else
#define THREAD static void*
#define THREADRETURN return(NULL);
#endif
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
THREAD keepalive_thread(void *param)
{
RGBController_HyperXKeyboard* controller = static_cast<RGBController_HyperXKeyboard*>(param);
controller->KeepaliveThread();
THREADRETURN
}
static const char* zone_names[] =
{
"Keyboard",
@@ -223,6 +258,19 @@ RGBController_HyperXKeyboard::RGBController_HyperXKeyboard(HyperXKeyboardControl
zones.push_back(new_zone);
}
/*-----------------------------------------------------*\
| The Corsair Lighting Node Pro requires a packet within|
| 20 seconds of sending the lighting change in order |
| to not revert back into rainbow mode. Start a thread |
| to continuously send a keepalive packet every 5s |
\*-----------------------------------------------------*/
#ifdef WIN32
_beginthread(keepalive_thread, 0, this);
#else
pthread_t thread;
pthread_create(&thread, NULL, &keepalive_thread, this);
#endif
}
RGBController_HyperXKeyboard::~RGBController_HyperXKeyboard()
@@ -269,3 +317,15 @@ void RGBController_HyperXKeyboard::UpdateMode()
hyperx->SetMode(modes[active_mode].value, modes[active_mode].direction, modes[active_mode].speed, temp_colors);
}
}
void RGBController_HyperXKeyboard::KeepaliveThread()
{
while(1)
{
if(active_mode == 0)
{
hyperx->SetLEDsDirect(colors);
}
Sleep(200);
}
}
@@ -23,6 +23,8 @@ public:
void SetCustomMode();
void UpdateMode();
void KeepaliveThread();
private:
HyperXKeyboardController* hyperx;
};
+31 -1
View File
@@ -31,7 +31,9 @@ struct Options
void PrintHelp()
{
std::string help_text;
help_text += "OpenRGB, for controlling RGB lighting.\n";
help_text += "OpenRGB ";
help_text += VERSION_STRING;
help_text += ", for controlling RGB lighting.\n";
help_text += "Usage: OpenRGB (--device [--mode] [--color])...\n";
help_text += "\nOptions:\n";
help_text += "--gui\t\t\t\t\t Show GUI, also appears when not passing any parameters\n";
@@ -41,10 +43,32 @@ void PrintHelp()
help_text += "-c, --color \"FFFFFF,00AAFF...\"\t\t Sets colors on each device directly if no effect is specified, and sets the effect color if an effect is specified\n";
help_text += "\t\t\t\t\t If there are more LEDs than colors given, the last color will be applied to the remaining LEDs\n";
help_text += "-m, --mode [breathing | static | ...] Sets the mode to be applied, check --list-devices to see which modes are supported on your device\n";
help_text += "-v, --version\t\t\t\t Display version and software build information\n";
std::cout << help_text << std::endl;
}
void PrintVersion()
{
std::string version_text;
version_text += "OpenRGB ";
version_text += VERSION_STRING;
version_text += ", for controlling RGB lighting.\n";
version_text += " Version:\t\t ";
version_text += VERSION_STRING;
version_text += "\n Build Date\t\t ";
version_text += BUILDDATE_STRING;
version_text += "\n Git Commit ID\t\t ";
version_text += GIT_COMMIT_ID;
version_text += "\n Git Commit Date\t ";
version_text += GIT_COMMIT_DATE;
version_text += "\n Git Branch\t\t ";
version_text += GIT_BRANCH;
version_text += "\n";
std::cout << version_text << std::endl;
}
bool ParseColors(std::string colors_string, DeviceOptions *options)
{
while (colors_string.length() >= 6)
@@ -309,6 +333,12 @@ int cli_main(int argc, char *argv[])
return 0;
}
if (argc == 2 && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v")))
{
PrintVersion();
return 0;
}
DetectRGBControllers();
Options options;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1383
View File
File diff suppressed because it is too large Load Diff
+28 -32
View File
@@ -30,7 +30,7 @@
#include <wchar.h>
#ifdef _WIN32
#define HID_API_EXPORT __declspec(dllexport)
#define HID_API_EXPORT
#define HID_API_CALL
#else
#define HID_API_EXPORT /**< API export macro */
@@ -69,13 +69,9 @@ extern "C" {
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
represents.
* Valid on both Linux implementations in all cases.
* Valid on the Windows implementation only if the device
contains more than one interface.
* Valid on the Mac implementation if and only if the device
is a USB HID device. */
represents. Valid on both Linux implementations
in all cases, and valid on the Windows implementation
only if the device contains more than one interface. */
int interface_number;
/** Pointer to the next device */
@@ -129,7 +125,7 @@ extern "C" {
@returns
This function returns a pointer to a linked list of type
struct #hid_device_info, containing information about the HID devices
struct #hid_device, containing information about the HID devices
attached to the system, or NULL in the case of failure. Free
this linked list by calling hid_free_enumeration().
*/
@@ -195,7 +191,7 @@ extern "C" {
the Control Endpoint (Endpoint 0).
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send.
@@ -204,7 +200,7 @@ extern "C" {
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *data, size_t length);
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);
/** @brief Read an Input report from a HID device with timeout.
@@ -213,7 +209,7 @@ extern "C" {
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
@@ -234,7 +230,7 @@ extern "C" {
contain the Report number if the device uses numbered reports.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
@@ -245,7 +241,7 @@ extern "C" {
-1 on error. If no packet was available to be read and
the handle is in non-blocking mode, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length);
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);
/** @brief Set the device handle to be non-blocking.
@@ -257,7 +253,7 @@ extern "C" {
Nonblocking can be turned on and off at any time.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param nonblock enable or not the nonblocking reads
- 1 to enable nonblocking
- 0 to disable nonblocking.
@@ -265,7 +261,7 @@ extern "C" {
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock);
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);
/** @brief Send a Feature report to the device.
@@ -283,7 +279,7 @@ extern "C" {
in would be 17.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send, including
@@ -293,7 +289,7 @@ extern "C" {
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const unsigned char *data, size_t length);
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);
/** @brief Get a feature report from a HID device.
@@ -304,7 +300,7 @@ extern "C" {
start in data[1].
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into, including
the Report ID. Set the first byte of @p data[] to the
Report ID of the report to be read, or set it to zero
@@ -318,55 +314,55 @@ extern "C" {
one for the report ID (which is still in the first
byte), or -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length);
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);
/** @brief Close a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
*/
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev);
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);
/** @brief Get The Manufacturer String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen);
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get The Product String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen);
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get The Serial Number String from a HID device.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen);
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get a string from a HID device, based on its string index.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@param string_index The index of the string to get.
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@@ -374,18 +370,18 @@ extern "C" {
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen);
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);
/** @brief Get a string describing the last error which occurred.
@ingroup API
@param dev A device handle returned from hid_open().
@param device A device handle returned from hid_open().
@returns
This function returns a string containing the last error
which occurred or NULL if none has occurred.
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);
#ifdef __cplusplus
}
Binary file not shown.
+14
View File
@@ -597,6 +597,11 @@ void Ui::OpenRGBDevicePage::UpdateMode()
| Change device mode |
\*-----------------------------------------------------*/
device->SetMode(current_mode);
if(device->modes[current_mode].color_mode == MODE_COLORS_PER_LED)
{
device->UpdateLEDs();
}
}
}
}
@@ -613,6 +618,15 @@ void Ui::OpenRGBDevicePage::SetDevice(unsigned char red, unsigned char green, un
on_SetDeviceButton_clicked();
}
void Ui::OpenRGBDevicePage::UpdateDevice()
{
ui->ModeBox->blockSignals(true);
ui->ModeBox->setCurrentIndex(device->active_mode);
ui->ModeBox->blockSignals(false);
UpdateModeUi();
UpdateMode();
}
void Ui::OpenRGBDevicePage::SetCustomMode()
{
device->SetCustomMode();
+1
View File
@@ -20,6 +20,7 @@ public:
void SetDevice(unsigned char red, unsigned char green, unsigned char blue);
void SetCustomMode();
void UpdateDevice();
void UpdateMode();
void UpdateModeUi();
+384 -1
View File
@@ -1,9 +1,18 @@
#include <fstream>
#include "OpenRGBDialog2.h"
#include "OpenRGBDevicePage.h"
#include "OpenRGBDeviceInfoPage.h"
#include "OpenRGBSoftwareInfoPage.h"
#include "OpenRGBSystemInfoPage.h"
#include "OpenRGBProfileSaveDialog.h"
#include "RGBController_Dummy.h"
#include <QLabel>
#include <QTabBar>
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
using namespace Ui;
@@ -14,6 +23,44 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
QIcon logo(":OpenRGB.png");
setWindowIcon(logo);
/*---------------------------------------------------------*\
| Load profiles by looking for .orp files in current dir |
\*---------------------------------------------------------*/
for(const auto & entry : fs::directory_iterator("."))
{
std::string filename = entry.path().filename().string();
if(filename.find(".orp") != std::string::npos)
{
/*---------------------------------------------------------*\
| Open input file in binary mode |
\*---------------------------------------------------------*/
std::ifstream profile_file(filename, std::ios::in | std::ios::binary);
/*---------------------------------------------------------*\
| Read and verify file header |
\*---------------------------------------------------------*/
char header_string[16];
unsigned int header_version;
profile_file.read(header_string, 16);
profile_file.read((char *)&header_version, sizeof(unsigned int));
if(strcmp(header_string, "OPENRGB_PROFILE") == 0)
{
if(header_version == 1)
{
/*---------------------------------------------------------*\
| Add this profile to the list |
\*---------------------------------------------------------*/
ui->comboBox->addItem(filename.c_str());
}
}
profile_file.close();
}
}
/*-----------------------------------------------------*\
| Set up tray icon menu |
\*-----------------------------------------------------*/
@@ -25,6 +72,18 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
connect(actionShowHide, SIGNAL(triggered()), this, SLOT(on_ShowHide()));
trayIconMenu->addAction(actionShowHide);
QMenu* profileMenu = new QMenu("Profiles", this);
for(int profile_index = 0; profile_index < ui->comboBox->count(); profile_index++)
{
QAction* actionProfileSelected = new QAction(ui->comboBox->itemText(profile_index), this);
actionProfileSelected->setObjectName(ui->comboBox->itemText(profile_index));
connect(actionProfileSelected, SIGNAL(triggered()), this, SLOT(on_ProfileSelected()));
profileMenu->addAction(actionProfileSelected);
}
trayIconMenu->addMenu(profileMenu);
QMenu* quickColorsMenu = new QMenu("Quick Colors", this);
QAction* actionQuickRed = new QAction("Red", this);
@@ -200,6 +259,25 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
SystemTabLabel->setGeometry(0, 0, 200, 20);
InformationTabBar->setTabButton(control.size(), QTabBar::LeftSide, SystemTabLabel);
OpenRGBSoftwareInfoPage *SoftInfoPage = new OpenRGBSoftwareInfoPage();
ui->InformationTabBar->addTab(SoftInfoPage, "");
/*-----------------------------------------------------*\
| Use Qt's HTML capabilities to display both icon and |
| text in the tab label. Choose icon based on device |
| type and append device name string. |
\*-----------------------------------------------------*/
QString SoftwareLabelString = "<html><table><tr><td width='30'><img src='";
SoftwareLabelString += ":/keyboard.svg";
SoftwareLabelString += "' height='15' width='15'></td><td>Software</td></tr></table></html>";
QLabel *SoftwareTabLabel = new QLabel();
SoftwareTabLabel->setText(SoftwareLabelString);
SoftwareTabLabel->setIndent(20);
SoftwareTabLabel->setGeometry(0, 0, 200, 20);
InformationTabBar->setTabButton(control.size() + 1, QTabBar::LeftSide, SoftwareTabLabel);
}
OpenRGBDialog2::~OpenRGBDialog2()
@@ -276,4 +354,309 @@ void OpenRGBDialog2::on_ShowHide()
{
hide();
}
}
}
void Ui::OpenRGBDialog2::on_ProfileSelected()
{
std::vector<RGBController*> temp_controllers;
unsigned int controller_size;
unsigned int controller_offset = 0;
std::string filename = QObject::sender()->objectName().toStdString();
/*---------------------------------------------------------*\
| Open input file in binary mode |
\*---------------------------------------------------------*/
std::ifstream controller_file(filename, std::ios::in | std::ios::binary);
/*---------------------------------------------------------*\
| Read and verify file header |
\*---------------------------------------------------------*/
char header_string[16];
unsigned int header_version;
controller_file.read(header_string, 16);
controller_file.read((char *)&header_version, sizeof(unsigned int));
controller_offset += 16 + sizeof(unsigned int);
controller_file.seekg(controller_offset);
if(strcmp(header_string, "OPENRGB_PROFILE") == 0)
{
if(header_version == 1)
{
/*---------------------------------------------------------*\
| Read controller data from file until EOF |
\*---------------------------------------------------------*/
while(!(controller_file.peek() == EOF))
{
controller_file.read((char *)&controller_size, sizeof(controller_size));
unsigned char *controller_data = new unsigned char[controller_size];
controller_file.seekg(controller_offset);
controller_file.read((char *)controller_data, controller_size);
RGBController_Dummy *temp_controller = new RGBController_Dummy();
temp_controller->ReadDeviceDescription(controller_data);
temp_controllers.push_back(temp_controller);
delete[] controller_data;
controller_offset += controller_size;
controller_file.seekg(controller_offset);
}
for(int controller_index = 0; controller_index < controllers.size(); controller_index++)
{
RGBController *temp_controller = temp_controllers[controller_index];
RGBController *controller_ptr = controllers[controller_index];
/*---------------------------------------------------------*\
| Test if saved controller data matches this controller |
\*---------------------------------------------------------*/
if((temp_controller->type == controller_ptr->type )
&&(temp_controller->name == controller_ptr->name )
&&(temp_controller->description == controller_ptr->description)
&&(temp_controller->version == controller_ptr->version )
&&(temp_controller->serial == controller_ptr->serial )
&&(temp_controller->location == controller_ptr->location ))
{
/*---------------------------------------------------------*\
| Update all modes |
\*---------------------------------------------------------*/
if(temp_controller->modes.size() == controller_ptr->modes.size())
{
for(int mode_index = 0; mode_index < temp_controller->modes.size(); mode_index++)
{
if((temp_controller->modes[mode_index].name == controller_ptr->modes[mode_index].name )
&&(temp_controller->modes[mode_index].value == controller_ptr->modes[mode_index].value )
&&(temp_controller->modes[mode_index].flags == controller_ptr->modes[mode_index].flags )
&&(temp_controller->modes[mode_index].speed_min == controller_ptr->modes[mode_index].speed_min )
&&(temp_controller->modes[mode_index].speed_max == controller_ptr->modes[mode_index].speed_max )
&&(temp_controller->modes[mode_index].colors_min == controller_ptr->modes[mode_index].colors_min)
&&(temp_controller->modes[mode_index].colors_max == controller_ptr->modes[mode_index].colors_max))
{
controller_ptr->modes[mode_index].speed = temp_controller->modes[mode_index].speed;
controller_ptr->modes[mode_index].direction = temp_controller->modes[mode_index].direction;
controller_ptr->modes[mode_index].color_mode = temp_controller->modes[mode_index].color_mode;
controller_ptr->modes[mode_index].colors.resize(temp_controller->modes[mode_index].colors.size());
for(int mode_color_index = 0; mode_color_index < temp_controller->modes[mode_index].colors.size(); mode_color_index++)
{
controller_ptr->modes[mode_index].colors[mode_color_index] = temp_controller->modes[mode_index].colors[mode_color_index];
}
}
}
controller_ptr->active_mode = temp_controller->active_mode;
}
/*---------------------------------------------------------*\
| Update all colors |
\*---------------------------------------------------------*/
if(temp_controller->colors.size() == controller_ptr->colors.size())
{
for(int color_index = 0; color_index < temp_controller->colors.size(); color_index++)
{
controller_ptr->colors[color_index] = temp_controller->colors[color_index];
}
}
}
}
}
for(int device = 0; device < ui->DevicesTabBar->count(); device++)
{
qobject_cast<OpenRGBDevicePage *>(ui->DevicesTabBar->widget(device))->UpdateDevice();
}
}
}
void Ui::OpenRGBDialog2::on_ButtonSaveProfile_clicked()
{
OpenRGBProfileSaveDialog dialog;
/*---------------------------------------------------------*\
| Open Profile Name Dialog |
\*---------------------------------------------------------*/
std::string profile_name = dialog.show();
/*---------------------------------------------------------*\
| If a name was entered, save the profile file |
\*---------------------------------------------------------*/
if(profile_name != "")
{
/*---------------------------------------------------------*\
| Extension .orp - OpenRgb Profile |
\*---------------------------------------------------------*/
std::string filename = profile_name + ".orp";
/*---------------------------------------------------------*\
| Open an output file in binary mode |
\*---------------------------------------------------------*/
std::ofstream controller_file(filename, std::ios::out | std::ios::binary);
/*---------------------------------------------------------*\
| Write header |
| 16 bytes - "OPENRGB_PROFILE" |
| 4 bytes - Version, unsigned int |
\*---------------------------------------------------------*/
unsigned int profile_version = 1;
controller_file.write("OPENRGB_PROFILE", 16);
controller_file.write((char *)&profile_version, sizeof(unsigned int));
/*---------------------------------------------------------*\
| Write controller data for each controller |
\*---------------------------------------------------------*/
for(int controller_index = 0; controller_index < controllers.size(); controller_index++)
{
unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription();
unsigned int controller_size;
memcpy(&controller_size, controller_data, sizeof(controller_size));
controller_file.write((const char *)controller_data, controller_size);
}
/*---------------------------------------------------------*\
| Close the file when done |
\*---------------------------------------------------------*/
controller_file.close();
/*---------------------------------------------------------*\
| Add the new file to the profile list |
\*---------------------------------------------------------*/
ui->comboBox->addItem(filename.c_str());
}
}
void Ui::OpenRGBDialog2::on_ButtonLoadProfile_clicked()
{
std::vector<RGBController*> temp_controllers;
unsigned int controller_size;
unsigned int controller_offset = 0;
/*---------------------------------------------------------*\
| Get the profile filename from the profiles list |
\*---------------------------------------------------------*/
std::string filename = ui->comboBox->currentText().toStdString();
/*---------------------------------------------------------*\
| Open input file in binary mode |
\*---------------------------------------------------------*/
std::ifstream controller_file(filename, std::ios::in | std::ios::binary);
/*---------------------------------------------------------*\
| Read and verify file header |
\*---------------------------------------------------------*/
char header_string[16];
unsigned int header_version;
controller_file.read(header_string, 16);
controller_file.read((char *)&header_version, sizeof(unsigned int));
controller_offset += 16 + sizeof(unsigned int);
controller_file.seekg(controller_offset);
if(strcmp(header_string, "OPENRGB_PROFILE") == 0)
{
if(header_version == 1)
{
/*---------------------------------------------------------*\
| Read controller data from file until EOF |
\*---------------------------------------------------------*/
while(!(controller_file.peek() == EOF))
{
controller_file.read((char *)&controller_size, sizeof(controller_size));
unsigned char *controller_data = new unsigned char[controller_size];
controller_file.seekg(controller_offset);
controller_file.read((char *)controller_data, controller_size);
RGBController_Dummy *temp_controller = new RGBController_Dummy();
temp_controller->ReadDeviceDescription(controller_data);
temp_controllers.push_back(temp_controller);
delete[] controller_data;
controller_offset += controller_size;
controller_file.seekg(controller_offset);
}
for(int controller_index = 0; controller_index < controllers.size(); controller_index++)
{
RGBController *temp_controller = temp_controllers[controller_index];
RGBController *controller_ptr = controllers[controller_index];
/*---------------------------------------------------------*\
| Test if saved controller data matches this controller |
\*---------------------------------------------------------*/
if((temp_controller->type == controller_ptr->type )
&&(temp_controller->name == controller_ptr->name )
&&(temp_controller->description == controller_ptr->description)
&&(temp_controller->version == controller_ptr->version )
&&(temp_controller->serial == controller_ptr->serial )
&&(temp_controller->location == controller_ptr->location ))
{
/*---------------------------------------------------------*\
| Update all modes |
\*---------------------------------------------------------*/
if(temp_controller->modes.size() == controller_ptr->modes.size())
{
for(int mode_index = 0; mode_index < temp_controller->modes.size(); mode_index++)
{
if((temp_controller->modes[mode_index].name == controller_ptr->modes[mode_index].name )
&&(temp_controller->modes[mode_index].value == controller_ptr->modes[mode_index].value )
&&(temp_controller->modes[mode_index].flags == controller_ptr->modes[mode_index].flags )
&&(temp_controller->modes[mode_index].speed_min == controller_ptr->modes[mode_index].speed_min )
&&(temp_controller->modes[mode_index].speed_max == controller_ptr->modes[mode_index].speed_max )
&&(temp_controller->modes[mode_index].colors_min == controller_ptr->modes[mode_index].colors_min)
&&(temp_controller->modes[mode_index].colors_max == controller_ptr->modes[mode_index].colors_max))
{
controller_ptr->modes[mode_index].speed = temp_controller->modes[mode_index].speed;
controller_ptr->modes[mode_index].direction = temp_controller->modes[mode_index].direction;
controller_ptr->modes[mode_index].color_mode = temp_controller->modes[mode_index].color_mode;
controller_ptr->modes[mode_index].colors.resize(temp_controller->modes[mode_index].colors.size());
for(int mode_color_index = 0; mode_color_index < temp_controller->modes[mode_index].colors.size(); mode_color_index++)
{
controller_ptr->modes[mode_index].colors[mode_color_index] = temp_controller->modes[mode_index].colors[mode_color_index];
}
}
}
controller_ptr->active_mode = temp_controller->active_mode;
}
/*---------------------------------------------------------*\
| Update all colors |
\*---------------------------------------------------------*/
if(temp_controller->colors.size() == controller_ptr->colors.size())
{
for(int color_index = 0; color_index < temp_controller->colors.size(); color_index++)
{
controller_ptr->colors[color_index] = temp_controller->colors[color_index];
}
}
}
}
}
for(int device = 0; device < ui->DevicesTabBar->count(); device++)
{
qobject_cast<OpenRGBDevicePage *>(ui->DevicesTabBar->widget(device))->UpdateDevice();
}
}
}
+3
View File
@@ -48,6 +48,9 @@ private slots:
void on_QuickWhite();
void on_SetAllDevices(unsigned char red, unsigned char green, unsigned char blue);
void on_ShowHide();
void on_ProfileSelected();
void on_ButtonSaveProfile_clicked();
void on_ButtonLoadProfile_clicked();
};
#endif // OPENRGBDIALOG2_H
+19 -2
View File
@@ -15,7 +15,24 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="3" column="1">
<widget class="QPushButton" name="ButtonLoadProfile">
<property name="text">
<string>Load Profile</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="ButtonSaveProfile">
<property name="text">
<string>Save Profile</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QComboBox" name="comboBox"/>
</item>
<item row="2" column="0" colspan="3">
<widget class="QTabWidget" name="MainTabBar">
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
@@ -34,7 +51,7 @@
<string>Devices</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<item row="1" column="0">
<widget class="QTabWidget" name="DevicesTabBar">
<property name="tabPosition">
<enum>QTabWidget::West</enum>
+31
View File
@@ -0,0 +1,31 @@
#include "OpenRGBProfileSaveDialog.h"
#include "ui_OpenRGBProfileSaveDialog.h"
Ui::OpenRGBProfileSaveDialog::OpenRGBProfileSaveDialog(QWidget *parent) :
QDialog(parent), ui(new Ui::OpenRGBProfileSaveDialogUi)
{
ui->setupUi(this);
}
Ui::OpenRGBProfileSaveDialog::~OpenRGBProfileSaveDialog()
{
delete ui;
}
std::string Ui::OpenRGBProfileSaveDialog::show()
{
std::string return_string;
int result = this->exec();
if(result == QDialog::Rejected)
{
return_string = "";
}
else
{
return_string = ui->lineEdit->text().toStdString();
}
return(return_string);
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef OPENRGBPROFILESAVEDIALOG_H
#define OPENRGBPROFILESAVEDIALOG_H
#include <QDialog>
#include "ui_OpenRGBProfileSaveDialog.h"
namespace Ui
{
class OpenRGBProfileSaveDialog;
}
class Ui::OpenRGBProfileSaveDialog : public QDialog
{
Q_OBJECT
public:
explicit OpenRGBProfileSaveDialog(QWidget *parent = nullptr);
~OpenRGBProfileSaveDialog();
std::string show();
private:
Ui::OpenRGBProfileSaveDialogUi *ui;
};
#endif // OPENRGBPROFILESAVEDIALOG_H
+91
View File
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OpenRGBProfileSaveDialogUi</class>
<widget class="QDialog" name="OpenRGBProfileSaveDialogUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>160</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>120</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>30</x>
<y>70</y>
<width>341</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>341</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>New Profile Name:</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>OpenRGBProfileSaveDialogUi</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>OpenRGBProfileSaveDialogUi</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+21
View File
@@ -0,0 +1,21 @@
#include "OpenRGBSoftwareInfoPage.h"
using namespace Ui;
OpenRGBSoftwareInfoPage::OpenRGBSoftwareInfoPage(QWidget *parent) :
QFrame(parent),
ui(new Ui::OpenRGBSoftwareInfoPageUi)
{
ui->setupUi(this);
ui->VersionValue->setText(VERSION_STRING);
ui->BuildDateValue->setText(BUILDDATE_STRING);
ui->GitCommitIDValue->setText(GIT_COMMIT_ID);
ui->GitCommitDateValue->setText(GIT_COMMIT_DATE);
ui->GitBranchValue->setText(GIT_BRANCH);
}
OpenRGBSoftwareInfoPage::~OpenRGBSoftwareInfoPage()
{
delete ui;
}
+23
View File
@@ -0,0 +1,23 @@
#ifndef OPENRGBSOFTWAREINFOPAGE_H
#define OPENRGBSOFTWAREINFOPAGE_H
#include <QFrame>
#include "ui_OpenRGBSoftwareInfoPage.h"
namespace Ui {
class OpenRGBSoftwareInfoPage;
}
class Ui::OpenRGBSoftwareInfoPage : public QFrame
{
Q_OBJECT
public:
explicit OpenRGBSoftwareInfoPage(QWidget *parent = nullptr);
~OpenRGBSoftwareInfoPage();
private:
Ui::OpenRGBSoftwareInfoPageUi *ui;
};
#endif // OPENRGBSOFTWAREINFOPAGE_H
+91
View File
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OpenRGBSoftwareInfoPageUi</class>
<widget class="QFrame" name="OpenRGBSoftwareInfoPageUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="GitBranchLabel">
<property name="text">
<string>Git Branch:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="GitCommitIDValue">
<property name="text">
<string>Git Commit ID Value</string>
</property>
</widget>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="VersionLabel">
<property name="text">
<string>Version:</string>
</property>
</widget>
</item>
<item row="1" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="BuildDateLabel">
<property name="text">
<string>Build Date:</string>
</property>
</widget>
</item>
<item row="3" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="GitCommitDateLabel">
<property name="text">
<string>Git Commit Date:</string>
</property>
</widget>
</item>
<item row="2" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="GitCommitIDLabel">
<property name="text">
<string>Git Commit ID:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="BuildDateValue">
<property name="text">
<string>Build Date Value</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="GitBranchValue">
<property name="text">
<string>Git Branch Value</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="GitCommitDateValue">
<property name="text">
<string>Git Commit Date Value</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="VersionValue">
<property name="text">
<string>Version Value</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>