mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-05-24 14:35:01 -04:00
Add Support on Mountain Everest 60 Device
This commit is contained in:
committed by
Adam Honse
parent
6a80f24962
commit
9d1bfcab7d
@@ -14,4 +14,4 @@ insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
indent_size = 4
|
||||
indent_size = 4
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| Mountain60KeyboardController.cpp |
|
||||
| |
|
||||
| Driver for Mountain keyboard |
|
||||
| |
|
||||
| Soufian Batta Jan 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include "Mountain60KeyboardController.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
Mountain60KeyboardController::Mountain60KeyboardController(hid_device* dev_handle, const char* path)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
}
|
||||
|
||||
Mountain60KeyboardController::~Mountain60KeyboardController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string Mountain60KeyboardController::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
const char* Mountain60KeyboardController::GetPath()
|
||||
{
|
||||
return location.c_str();
|
||||
}
|
||||
|
||||
std::string Mountain60KeyboardController::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
return(StringUtils::wstring_to_string(serial_string));
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SetDevice(hid_device* new_device)
|
||||
{
|
||||
hid_close(dev);
|
||||
dev = new_device;
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::UpdateData()
|
||||
{
|
||||
unsigned char usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
unsigned char read[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
memset(usb_buf, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
|
||||
usb_buf[0x01] = MOUNTAIN60_KEYBOARD_CHECK_NUMPAD;
|
||||
usb_buf[0x02] = 0x46; //constant data
|
||||
usb_buf[0x03] = 0x23; //constant data
|
||||
usb_buf[0x04] = 0xEA; //constant data
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
memset(read, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
hid_get_feature_report(dev, read, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SendModeDetails(const mode* current_mode)
|
||||
{
|
||||
unsigned char usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
unsigned char color_mode [] = {MOUNTAIN60_KEYBOARD_COLOR_MODE_SINGLE,MOUNTAIN60_KEYBOARD_COLOR_MODE_DUAL};
|
||||
memset(usb_buf, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
|
||||
usb_buf[0x01] = MOUNTAIN60_KEYBOARD_SEND_CMD;
|
||||
usb_buf[0x02] = 0x46; //constant data
|
||||
usb_buf[0x03] = 0x23; //constant data
|
||||
usb_buf[0x04] = 0xEA; //constant data
|
||||
|
||||
usb_buf[0x05] = current_mode->value;
|
||||
usb_buf[0x07] = current_mode->value == MOUNTAIN60_KEYBOARD_MODE_STATIC ? 0x32 : current_mode->speed * 25;
|
||||
usb_buf[0x08] = current_mode->brightness * 25;
|
||||
usb_buf[0x09] = current_mode->color_mode == MODE_COLORS_RANDOM ? MOUNTAIN60_KEYBOARD_COLOR_MODE_RAINBOW : color_mode[current_mode->colors.size() - 1];
|
||||
usb_buf[0x0A] = ConvertDirection(current_mode->direction,current_mode->value == MOUNTAIN60_KEYBOARD_MODE_TORNADO);
|
||||
|
||||
for (int idx = 0; idx < current_mode->colors.size(); ++idx)
|
||||
{
|
||||
unsigned int offset = 12 + (idx * 3);
|
||||
usb_buf[offset] = RGBGetRValue(current_mode->colors[idx]);
|
||||
usb_buf[offset+1] = RGBGetGValue(current_mode->colors[idx]);
|
||||
usb_buf[offset+2] = RGBGetBValue(current_mode->colors[idx]);
|
||||
}
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
std::this_thread::sleep_for(10ms);
|
||||
SaveData(current_mode->value);
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SelectMode(unsigned char mode_idx)
|
||||
{
|
||||
unsigned char usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
unsigned char read[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
memset(usb_buf, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
|
||||
usb_buf[0x01] = MOUNTAIN60_KEYBOARD_SELECT_MODE_CMD;
|
||||
usb_buf[0x02] = 0x46; //constant data
|
||||
usb_buf[0x03] = 0x23; //constant data
|
||||
usb_buf[0x04] = 0xEA; //constant data
|
||||
usb_buf[0x05] = 0x01; //constant data
|
||||
|
||||
usb_buf[0x09] = mode_idx;
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
memset(read, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
hid_get_feature_report(dev, read, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SaveData(unsigned char mode_idx)
|
||||
{
|
||||
unsigned char usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
unsigned char read[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
memset(usb_buf, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
|
||||
usb_buf[0x01] = MOUNTAIN60_KEYBOARD_SAVE_CMD;
|
||||
usb_buf[0x02] = 0x46; //constant data
|
||||
usb_buf[0x03] = 0x23; //constant data
|
||||
usb_buf[0x04] = 0xEA; //constant data
|
||||
|
||||
usb_buf[0x05] = mode_idx;
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
memset(read, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
hid_get_feature_report(dev, read, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SendDirectStartPacketCmd(unsigned int brightness)
|
||||
{
|
||||
unsigned char usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
unsigned char read[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
memset(usb_buf, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
|
||||
usb_buf[0x01] = MOUNTAIN60_KEYBOARD_START_DIRECT_CMD;
|
||||
usb_buf[0x02] = 0x46; //constant data
|
||||
usb_buf[0x03] = 0x23; //constant data
|
||||
usb_buf[0x04] = 0xEA; //constant data
|
||||
usb_buf[0x06] = 0xC0; //constant data
|
||||
|
||||
usb_buf[0x05] = brightness * 25;
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
memset(read, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
hid_get_feature_report(dev, read, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SendDirectPacketCmd(unsigned char stream_control, unsigned char *data, unsigned int data_size)
|
||||
{
|
||||
unsigned char usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
memset(usb_buf, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_HEADER_SIZE);
|
||||
|
||||
usb_buf[0x01] = MOUNTAIN60_KEYBOARD_MAP_DIRECT_CMD;
|
||||
usb_buf[0x02] = 0x46; //constant data
|
||||
usb_buf[0x03] = 0x23; //constant data
|
||||
usb_buf[0x04] = 0xEA; //constant data
|
||||
|
||||
usb_buf[0x05] = stream_control;
|
||||
|
||||
if(data_size <= MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE)
|
||||
{
|
||||
unsigned char read[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
memcpy(&usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_HEADER_SIZE],data,data_size);
|
||||
|
||||
if(data_size < MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE)
|
||||
{
|
||||
memset(&usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_HEADER_SIZE + data_size],0xFF,MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE-data_size);
|
||||
}
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
memset(read, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
hid_get_feature_report(dev, read, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SendDirectPacketFinishCmd()
|
||||
{
|
||||
unsigned char usb_buf[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
unsigned char read[MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE];
|
||||
memset(usb_buf, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
|
||||
usb_buf[0x01] = MOUNTAIN60_KEYBOARD_END_DIRECT_CMD;
|
||||
usb_buf[0x02] = 0x46; //constant data
|
||||
usb_buf[0x03] = 0x23; //constant data
|
||||
usb_buf[0x04] = 0xEA; //constant data
|
||||
|
||||
hid_send_feature_report(dev, usb_buf, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
memset(read, 0x00, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
hid_get_feature_report(dev, read, MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void Mountain60KeyboardController::SendDirect(unsigned int brightness, unsigned char* color_data, unsigned int data_size)
|
||||
{
|
||||
static unsigned char prv_buffer[MOUNTAIN60_KEYBOARD_TRANSFER_BUFFER_SIZE] = {0xFF};
|
||||
unsigned char *data_ptr = color_data;
|
||||
unsigned char *prv_data_ptr = prv_buffer;
|
||||
unsigned int data_len = data_size;
|
||||
unsigned char stream_control_flag = 0x0E;
|
||||
|
||||
SendDirectStartPacketCmd(brightness);
|
||||
|
||||
while(data_len>0)
|
||||
{
|
||||
if(data_len >= MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE)
|
||||
{
|
||||
Mountain60KeyboardController::SendDirectPacketCmd(stream_control_flag,data_ptr,MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE);
|
||||
memcpy(prv_data_ptr,data_ptr,MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE);
|
||||
|
||||
data_ptr += MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE;
|
||||
prv_data_ptr += MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE;
|
||||
data_len -= MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
stream_control_flag = 0x0A;
|
||||
Mountain60KeyboardController::SendDirectPacketCmd(stream_control_flag,data_ptr,data_len);
|
||||
memcpy(prv_data_ptr,data_ptr,data_len);
|
||||
data_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
SendDirectPacketFinishCmd();
|
||||
}
|
||||
|
||||
unsigned char Mountain60KeyboardController::ConvertDirection(unsigned int direction, bool rotation)
|
||||
{
|
||||
unsigned char ret;
|
||||
switch(direction)
|
||||
{
|
||||
case MODE_DIRECTION_LEFT:
|
||||
{
|
||||
ret = rotation?MOUNTAIN60_KEYBOARD_DIRECTION_ANTICLK:MOUNTAIN60_KEYBOARD_DIRECTION_LEFT;
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_DIRECTION_RIGHT:
|
||||
{
|
||||
ret = rotation?MOUNTAIN60_KEYBOARD_DIRECTION_CLK:MOUNTAIN60_KEYBOARD_DIRECTION_RIGHT;
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_DIRECTION_UP:
|
||||
{
|
||||
ret = MOUNTAIN60_KEYBOARD_DIRECTION_UP;
|
||||
}
|
||||
break;
|
||||
|
||||
case MODE_DIRECTION_DOWN:
|
||||
{
|
||||
ret = MOUNTAIN60_KEYBOARD_DIRECTION_DOWN;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
ret = MOUNTAIN60_KEYBOARD_DIRECTION_LEFT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| MountainKeyboardController.h |
|
||||
| |
|
||||
| Driver for Mountain keyboard |
|
||||
| |
|
||||
| Soufian Batta Jan 2023 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
|
||||
#define MOUNTAIN60_KEYBOARD_MAX_TRANSFER_COLORS 191
|
||||
#define MOUNTAIN60_KEYBOARD_TRANSFER_BUFFER_SIZE (4*MOUNTAIN60_KEYBOARD_MAX_TRANSFER_COLORS)
|
||||
|
||||
#define MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE 65
|
||||
#define MOUNTAIN60_KEYBOARD_USB_BUFFER_HEADER_SIZE 9
|
||||
|
||||
#define MOUNTAIN60_KEYBOARD_USB_MAX_DIRECT_PAYLOAD_SIZE \
|
||||
(MOUNTAIN60_KEYBOARD_USB_BUFFER_SIZE-MOUNTAIN60_KEYBOARD_USB_BUFFER_HEADER_SIZE)
|
||||
|
||||
enum
|
||||
{
|
||||
MOUNTAIN60_KEYBOARD_CHECK_NUMPAD = 0x08,
|
||||
MOUNTAIN60_KEYBOARD_SELECT_MODE_CMD = 0x16,
|
||||
MOUNTAIN60_KEYBOARD_SEND_CMD = 0x17,
|
||||
MOUNTAIN60_KEYBOARD_START_DIRECT_CMD = 0x34,
|
||||
MOUNTAIN60_KEYBOARD_MAP_DIRECT_CMD = 0x35,
|
||||
MOUNTAIN60_KEYBOARD_END_DIRECT_CMD = 0x36,
|
||||
MOUNTAIN60_KEYBOARD_SAVE_CMD = 0x1A,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MOUNTAIN60_KEYBOARD_MODE_STATIC = 0x01,
|
||||
MOUNTAIN60_KEYBOARD_MODE_COLOR_WAVE = 0x02,
|
||||
MOUNTAIN60_KEYBOARD_MODE_TORNADO = 0x03,
|
||||
MOUNTAIN60_KEYBOARD_MODE_BREATHING = 0x04,
|
||||
MOUNTAIN60_KEYBOARD_MODE_REACTIVE = 0x05,
|
||||
MOUNTAIN60_KEYBOARD_MODE_MATRIX = 0x06,
|
||||
MOUNTAIN60_KEYBOARD_MODE_CUSTOM = 0x07,
|
||||
MOUNTAIN60_KEYBOARD_MODE_YETI = 0x08,
|
||||
MOUNTAIN60_KEYBOARD_MODE_OFF = 0x09,
|
||||
MOUNTAIN60_KEYBOARD_MODE_INVALID = 0xFF,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MOUNTAIN60_KEYBOARD_COLOR_MODE_RAINBOW = 0x02,
|
||||
MOUNTAIN60_KEYBOARD_COLOR_MODE_SINGLE = 0x00,
|
||||
MOUNTAIN60_KEYBOARD_COLOR_MODE_DUAL = 0x10
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MOUNTAIN60_KEYBOARD_DIRECTION_UP = 0x06,
|
||||
MOUNTAIN60_KEYBOARD_DIRECTION_DOWN = 0x02,
|
||||
MOUNTAIN60_KEYBOARD_DIRECTION_LEFT = 0x04,
|
||||
MOUNTAIN60_KEYBOARD_DIRECTION_RIGHT = 0x00,
|
||||
MOUNTAIN60_KEYBOARD_DIRECTION_ANTICLK = 0x0A,
|
||||
MOUNTAIN60_KEYBOARD_DIRECTION_CLK = 0x09,
|
||||
};
|
||||
|
||||
class Mountain60KeyboardController
|
||||
{
|
||||
public:
|
||||
Mountain60KeyboardController(hid_device* dev_handle, const char* path);
|
||||
~Mountain60KeyboardController();
|
||||
|
||||
const char* GetPath();
|
||||
std::string GetSerialString();
|
||||
std::string GetDeviceLocation();
|
||||
|
||||
void UpdateData();
|
||||
void SaveData(unsigned char mode_idx);
|
||||
void SelectMode(unsigned char mode_idx);
|
||||
void SetDevice(hid_device * new_device);
|
||||
void SendModeDetails(const mode* current_mode);
|
||||
void SendDirect(unsigned int brightness,unsigned char* color_data, unsigned int color_count);
|
||||
|
||||
private:
|
||||
unsigned char ConvertDirection(unsigned int direction, bool rotation);
|
||||
|
||||
void SendDirectStartPacketCmd(unsigned int brightness);
|
||||
void SendDirectPacketCmd(unsigned char stream_control, unsigned char *data, unsigned int data_size);
|
||||
void SendDirectPacketFinishCmd();
|
||||
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
};
|
||||
s
|
||||
@@ -14,10 +14,6 @@
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mountain vendor ID |
|
||||
\*-----------------------------------------------------*/
|
||||
#define MOUNTAIN_VID 0x3282
|
||||
/*-----------------------------------------------------*\
|
||||
| Everest keyboard product IDs |
|
||||
\*-----------------------------------------------------*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
| |
|
||||
| Detector for Mountain keyboard |
|
||||
| |
|
||||
| Wojciech Lazarski Jan 2023 |
|
||||
| Wojciech Lazarski / Soufian Batta Jan 2023 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
@@ -11,9 +11,24 @@
|
||||
|
||||
#include <hidapi.h>
|
||||
#include "Detector.h"
|
||||
#include "QMessageLogger"
|
||||
#include "MountainKeyboardController.h"
|
||||
#include "RGBController_MountainKeyboard.h"
|
||||
#include "Mountain60KeyboardController.h"
|
||||
#include "RGBController_Mountain60Keyboard.h"
|
||||
|
||||
/*---------------------------------------------------------------*\
|
||||
| Mountain vendor ID |
|
||||
\*---------------------------------------------------------------*/
|
||||
#define MOUNTAIN_VID 0x3282
|
||||
|
||||
/*----------------------------------------------------------------*\
|
||||
| Everest 60 keyboard Connection IDs |
|
||||
\*----------------------------------------------------------------*/
|
||||
#define MOUNTAIN60_EVEREST_60_PID 0x0005
|
||||
#define MOUNTAIN60_EVEREST_60_INTERFACE 2
|
||||
#define MOUNTAIN60_EVEREST_60_U 0x01
|
||||
#define MOUNTAIN60_EVEREST_60_UP 0xffff
|
||||
/*----------------------------------------------------------------------------------------*\
|
||||
| |
|
||||
| DetectMountainKeyboardControllers |
|
||||
@@ -22,6 +37,21 @@
|
||||
| |
|
||||
\*----------------------------------------------------------------------------------------*/
|
||||
|
||||
void DetectMountain60KeyboardControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
QMessageLogger* log = new QMessageLogger();
|
||||
|
||||
log->info("Hello World 2");
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
if(dev)
|
||||
{
|
||||
Mountain60KeyboardController* controller = new Mountain60KeyboardController(dev, info->path);
|
||||
RGBController_Mountain60Keyboard* rgb_controller = new RGBController_Mountain60Keyboard(controller);
|
||||
rgb_controller->name = name;
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
void DetectMountainKeyboardControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
@@ -33,6 +63,7 @@ void DetectMountainKeyboardControllers(hid_device_info* info, const std::string&
|
||||
rgb_controller->name = name;
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
} /* DetectMountainKeyboardControllers() */
|
||||
}
|
||||
|
||||
REGISTER_HID_DETECTOR_IPU("Mountain Everest", DetectMountainKeyboardControllers, MOUNTAIN_VID, MOUNTAIN_EVEREST_PID, 3, 0xFF00, 0x01);
|
||||
REGISTER_HID_DETECTOR_IPU("Mountain Everest 60", DetectMountain60KeyboardControllers, MOUNTAIN_VID, MOUNTAIN60_EVEREST_60_PID, MOUNTAIN60_EVEREST_60_INTERFACE, MOUNTAIN60_EVEREST_60_UP, MOUNTAIN60_EVEREST_60_U);
|
||||
|
||||
@@ -0,0 +1,490 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_MountainKeyboard.cpp |
|
||||
| |
|
||||
| RGBController for Mountain keyboard |
|
||||
| |
|
||||
| Soufian Batta Jan 2023 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_Mountain60Keyboard.h"
|
||||
#include "RGBControllerKeyNames.h"
|
||||
#include "KeyboardLayoutManager.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
/*-------------------------------*\
|
||||
| TODO: Detect detached keypad |
|
||||
\*-------------------------------*/
|
||||
|
||||
std::vector<unsigned int> mountain60_keyboard_key_id_values =
|
||||
{
|
||||
/* ESC 1 2 3 4 5 6 7 8 9 0 - = BSPC */
|
||||
0, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
|
||||
/* TAB Q W E R T Y U I O P [ ] \ */
|
||||
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
|
||||
/* CPLK A S D F G H J K L ; " ENTR */
|
||||
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 76,
|
||||
/* LSFT Z X C V B N M , . / RSFT ARWU DEL */
|
||||
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 97, 94, 56,
|
||||
/* LCTL LWIN LALT SPC RALT RFNC FNC ARWL ARWD ARWR */
|
||||
105, 106, 107, 110, 113, 115, 119, 120, 121,
|
||||
};
|
||||
|
||||
layout_values mountain60_layout =
|
||||
{
|
||||
mountain60_keyboard_key_id_values,
|
||||
{
|
||||
/*------------------------------------------*\
|
||||
| No regional layout fix for the moment |
|
||||
\*------------------------------------------*/
|
||||
},
|
||||
};
|
||||
|
||||
keyboard_keymap_overlay_values mountain60_keyboard_overlay_no_numpad =
|
||||
{
|
||||
KEYBOARD_SIZE::KEYBOARD_SIZE_SIXTY,
|
||||
mountain60_layout,
|
||||
{
|
||||
/*-------------------------------------------------------------------------------------------------------------*\
|
||||
| Edit Keys |
|
||||
| Zone, Row, Column, Value, Key, OpCode, |
|
||||
\*-------------------------------------------------------------------------------------------------------------*/
|
||||
{ 0, 4, 13, 120, KEY_EN_DOWN_ARROW, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 4, 12, 119, KEY_EN_LEFT_ARROW, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 4, 14, 121, KEY_EN_RIGHT_ARROW, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 4, 14, 121, KEY_EN_RIGHT_ARROW, KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 3, 13, 99, KEY_EN_UP_ARROW, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 12, 97, KEY_EN_RIGHT_SHIFT, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 2, 85, KEY_EN_Z, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 3, 86, KEY_EN_X, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 4, 87, KEY_EN_C, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 5, 88, KEY_EN_B, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 6, 89, KEY_EN_V, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 7, 90, KEY_EN_N, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 8, 91, KEY_EN_M, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 9, 92, KEY_EN_COMMA, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 10, 93, KEY_EN_PERIOD, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 14, 56, KEY_EN_DELETE, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 2, 13, 76, KEY_EN_ANSI_ENTER, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 0, 84, KEY_EN_LEFT_SHIFT, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
//upper edge
|
||||
{ 0, 0, 0, 126, "Edge 1", KEYBOARD_OPCODE_INSERT_ROW, },
|
||||
{ 0, 0, 1, 127, "Edge 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 2, 128, "Edge 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 3, 129, "Edge 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 4, 130, "Edge 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 5, 131, "Edge 6", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 6, 132, "Edge 7", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 7, 133, "Edge 8", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 8, 134, "Edge 9", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 9, 135, "Edge 10", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 10, 136, "Edge 11", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 11, 137, "Edge 12", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 12, 138, "Edge 13", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 13, 139, "Edge 14", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 14, 140, "Edge 15", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 15, 141, "Edge 16", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
//left edge
|
||||
{ 0, 0, 0, 169, "Edge 44", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 1, 0, 168, "Edge 43", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 2, 0, 167, "Edge 42", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 3, 0, 166, "Edge 41", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 4, 0, 165, "Edge 40", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 5, 0, 164, "Edge 39", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
//down edge
|
||||
{ 0, 6, 0, 1, KEY_EN_UNUSED, KEYBOARD_OPCODE_INSERT_ROW, },
|
||||
{ 0, 6, 0, 163, "Edge 38", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 1, 162, "Edge 37", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 2, 161, "Edge 36", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 3, 160, "Edge 35", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 4, 159, "Edge 34", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 5, 158, "Edge 33", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 6, 157, "Edge 32", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 7, 156, "Edge 31", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 8, 155, "Edge 30", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 9, 154, "Edge 29", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 10, 153, "Edge 28", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 11, 152, "Edge 27", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 12, 151, "Edge 26", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 13, 150, "Edge 25", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 14, 149, "Edge 24", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 15, 148, "Edge 23", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
//right edge
|
||||
{ 0, 1, 16, 142, "Edge 17", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 2, 16, 143, "Edge 18", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 3, 16, 144, "Edge 19", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 4, 16, 145, "Edge 20", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 5, 16, 146, "Edge 21", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 16, 147, "Edge 22", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 16, 147, "Edge 22", KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
//numpad left edge
|
||||
{ 0, 0, 17, 191, "Numpad Edge 22", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 1, 17, 190, "Numpad Edge 21", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 2, 17, 189, "Numpad Edge 20", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 3, 17, 188, "Numpad Edge 19", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 4, 17, 187, "Numpad Edge 18", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 5, 17, 186, "Numpad Edge 17", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
//numpad upper edge
|
||||
{ 0, 0, 18, 170, "Numpad Edge 1", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 19, 171, "Numpad Edge 2", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 20, 172, "Numpad Edge 3", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 21, 173, "Numpad Edge 4", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 0, 22, 174, "Numpad Edge 5", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
//numpad down edge
|
||||
{ 0, 6, 17, 185, "Numpad Edge 12", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT },
|
||||
{ 0, 6, 18, 184, "Numpad Edge 13", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 19, 183, "Numpad Edge 14", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 20, 182, "Numpad Edge 15", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 21, 181, "Numpad Edge 16", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
//numpad right edge
|
||||
{ 0, 1, 22, 175, "Numpad Edge 6", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 2, 22, 176, "Numpad Edge 7", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 3, 22, 177, "Numpad Edge 8", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 4, 22, 178, "Numpad Edge 9", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 5, 22, 179, "Numpad Edge 10", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 22, 180, "Numpad Edge 11", KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT, },
|
||||
{ 0, 6, 22, 180, "Numpad Edge 11", KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
//numpad keys
|
||||
{ 0, 1, 18, 38, KEY_EN_NUMPAD_LOCK, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 1, 19, 39, KEY_EN_NUMPAD_DIVIDE, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 1, 20, 40, KEY_EN_NUMPAD_TIMES, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 1, 21, 41, KEY_EN_NUMPAD_MINUS, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 2, 18, 59, KEY_EN_NUMPAD_7, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 2, 19, 60, KEY_EN_NUMPAD_8, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 2, 20, 61, KEY_EN_NUMPAD_9, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 2, 21, 62, KEY_EN_NUMPAD_PLUS, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 18, 80, KEY_EN_NUMPAD_4, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 19, 81, KEY_EN_NUMPAD_5, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 3, 20, 82, KEY_EN_NUMPAD_6, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 4, 18, 101, KEY_EN_NUMPAD_1, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 4, 19, 102, KEY_EN_NUMPAD_2, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 4, 20, 103, KEY_EN_NUMPAD_3, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 5, 18, 122, KEY_EN_NUMPAD_0, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 5, 20, 124, KEY_EN_NUMPAD_PERIOD, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
{ 0, 5, 21, 125, KEY_EN_NUMPAD_ENTER, KEYBOARD_OPCODE_SWAP_ONLY, },
|
||||
}
|
||||
};
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Mountain Keyboard
|
||||
@category Keyboard
|
||||
@type USB
|
||||
@save :white_check_mark:
|
||||
@direct :white_check_mark:
|
||||
@effects :white_check_mark:
|
||||
@detectors DetectMountainKeyboardControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_Mountain60Keyboard::RGBController_Mountain60Keyboard(Mountain60KeyboardController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
name = "Mountain Everest 60 Keyboard";
|
||||
vendor = "Mountain";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "Mountain Everest Keyboard 60%";
|
||||
location = controller->GetDeviceLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = MOUNTAIN60_KEYBOARD_MODE_CUSTOM;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
|
||||
Direct.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
Direct.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Direct.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = MOUNTAIN60_KEYBOARD_MODE_OFF;
|
||||
Off.flags = MODE_FLAG_MANUAL_SAVE;
|
||||
Off.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = MOUNTAIN60_KEYBOARD_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_MANUAL_SAVE;
|
||||
Static.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
Static.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Static.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Static.colors_min = 1;
|
||||
Static.colors_max = 1;
|
||||
Static.colors.resize(1);
|
||||
modes.push_back(Static);
|
||||
|
||||
mode ColorWaveRainbow;
|
||||
ColorWaveRainbow.name = "Rainbow Wave";
|
||||
ColorWaveRainbow.value = MOUNTAIN60_KEYBOARD_MODE_COLOR_WAVE;
|
||||
ColorWaveRainbow.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_DIRECTION_UD | MODE_FLAG_MANUAL_SAVE;
|
||||
ColorWaveRainbow.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
ColorWaveRainbow.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
ColorWaveRainbow.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
ColorWaveRainbow.speed_min = MOUNTAIN60_KEYBOARD_SPEED_MIN;
|
||||
ColorWaveRainbow.speed = MOUNTAIN60_KEYBOARD_SPEED_DEFAULT;
|
||||
ColorWaveRainbow.speed_max = MOUNTAIN60_KEYBOARD_SPEED_MAX;
|
||||
ColorWaveRainbow.color_mode = MODE_COLORS_RANDOM;
|
||||
|
||||
modes.push_back(ColorWaveRainbow);
|
||||
|
||||
mode ColorWave;
|
||||
ColorWave.name = "ColorWave";
|
||||
ColorWave.value = MOUNTAIN60_KEYBOARD_MODE_COLOR_WAVE;
|
||||
ColorWave.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_HAS_DIRECTION_UD | MODE_FLAG_MANUAL_SAVE;
|
||||
ColorWave.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
ColorWave.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
ColorWave.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
ColorWave.speed_min = MOUNTAIN60_KEYBOARD_SPEED_MIN;
|
||||
ColorWave.speed = MOUNTAIN60_KEYBOARD_SPEED_DEFAULT;
|
||||
ColorWave.speed_max = MOUNTAIN60_KEYBOARD_SPEED_MAX;
|
||||
ColorWave.colors_min = 1;
|
||||
ColorWave.colors_max = 2;
|
||||
ColorWave.colors.resize(2);
|
||||
ColorWave.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
modes.push_back(ColorWave);
|
||||
|
||||
mode Tornado;
|
||||
Tornado.name = "Tornado";
|
||||
Tornado.value = MOUNTAIN60_KEYBOARD_MODE_TORNADO;
|
||||
Tornado.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR | MODE_FLAG_MANUAL_SAVE;
|
||||
Tornado.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
Tornado.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Tornado.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Tornado.speed_min = MOUNTAIN60_KEYBOARD_SPEED_MIN;
|
||||
Tornado.speed = MOUNTAIN60_KEYBOARD_SPEED_DEFAULT;
|
||||
Tornado.speed_max = MOUNTAIN60_KEYBOARD_SPEED_MAX;
|
||||
Tornado.colors_min = 1;
|
||||
Tornado.colors_max = 1;
|
||||
Tornado.colors.resize(1);
|
||||
Tornado.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
modes.push_back(Tornado);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = MOUNTAIN60_KEYBOARD_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_MANUAL_SAVE;
|
||||
Breathing.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
Breathing.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Breathing.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Breathing.speed_min = MOUNTAIN60_KEYBOARD_SPEED_MIN;
|
||||
Breathing.speed = MOUNTAIN60_KEYBOARD_SPEED_DEFAULT;
|
||||
Breathing.speed_max = MOUNTAIN60_KEYBOARD_SPEED_MAX;
|
||||
Breathing.colors_min = 1;
|
||||
Breathing.colors_max = 2;
|
||||
Breathing.colors.resize(2);
|
||||
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode Reactive;
|
||||
Reactive.name = "Reactive";
|
||||
Reactive.value = MOUNTAIN60_KEYBOARD_MODE_REACTIVE;
|
||||
Reactive.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_MANUAL_SAVE;
|
||||
Reactive.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
Reactive.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Reactive.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Reactive.speed_min = MOUNTAIN60_KEYBOARD_SPEED_MIN;
|
||||
Reactive.speed = MOUNTAIN60_KEYBOARD_SPEED_DEFAULT;
|
||||
Reactive.speed_max = MOUNTAIN60_KEYBOARD_SPEED_MAX;
|
||||
Reactive.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Reactive.colors_min = 1;
|
||||
Reactive.colors_max = 2;
|
||||
Reactive.colors.resize(2);
|
||||
modes.push_back(Reactive);
|
||||
|
||||
mode Matrix;
|
||||
Matrix.name = "Matrix";
|
||||
Matrix.value = MOUNTAIN60_KEYBOARD_MODE_MATRIX;
|
||||
Matrix.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_MANUAL_SAVE;
|
||||
Matrix.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
Matrix.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Matrix.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Matrix.speed_min = MOUNTAIN60_KEYBOARD_SPEED_MIN;
|
||||
Matrix.speed = MOUNTAIN60_KEYBOARD_SPEED_DEFAULT;
|
||||
Matrix.speed_max = MOUNTAIN60_KEYBOARD_SPEED_MAX;
|
||||
Matrix.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Matrix.colors_min = 1;
|
||||
Matrix.colors_max = 2;
|
||||
Matrix.colors.resize(2);
|
||||
modes.push_back(Matrix);
|
||||
|
||||
mode Yeti;
|
||||
Yeti.name = "Yeti";
|
||||
Yeti.value = MOUNTAIN60_KEYBOARD_MODE_YETI;
|
||||
Yeti.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_MANUAL_SAVE;
|
||||
Yeti.brightness_min = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN;
|
||||
Yeti.brightness = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Yeti.brightness_max = MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX;
|
||||
Yeti.speed_min = MOUNTAIN60_KEYBOARD_SPEED_MIN;
|
||||
Yeti.speed = MOUNTAIN60_KEYBOARD_SPEED_DEFAULT;
|
||||
Yeti.speed_max = MOUNTAIN60_KEYBOARD_SPEED_MAX;
|
||||
Yeti.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Yeti.colors_min = 1;
|
||||
Yeti.colors_max = 2;
|
||||
Yeti.colors.resize(2);
|
||||
modes.push_back(Yeti);
|
||||
|
||||
SetupZones();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| The Mountain Everest 60 keyboard need to send a |
|
||||
| specific packet frequently so that leds get updated |
|
||||
\*-----------------------------------------------------*/
|
||||
mountain_thread = new std::thread(&RGBController_Mountain60Keyboard::UpdateMountain, this);
|
||||
mountaint_thread_running = true;
|
||||
update_device = true;
|
||||
found_device = true;
|
||||
}
|
||||
|
||||
RGBController_Mountain60Keyboard::~RGBController_Mountain60Keyboard()
|
||||
{
|
||||
update_device = false;
|
||||
mountaint_thread_running = false;
|
||||
mountain_thread->join();
|
||||
delete mountain_thread;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Delete the matrix map |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
|
||||
{
|
||||
if(zones[zone_index].type == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
delete zones[zone_index].matrix_map;
|
||||
}
|
||||
}
|
||||
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::SetupZones()
|
||||
{
|
||||
KeyboardLayoutManager new_kb(KEYBOARD_LAYOUT_ANSI_QWERTY, KEYBOARD_SIZE_SIXTY, mountain60_layout);
|
||||
new_kb.ChangeKeys(mountain60_keyboard_overlay_no_numpad);
|
||||
|
||||
zone new_zone;
|
||||
matrix_map_type * new_map = new matrix_map_type;
|
||||
|
||||
new_zone.name = "Mountain Everest 60";
|
||||
new_zone.type = ZONE_TYPE_MATRIX;
|
||||
new_zone.matrix_map = new_map;
|
||||
new_zone.matrix_map->height = new_kb.GetRowCount();
|
||||
new_zone.matrix_map->width = new_kb.GetColumnCount();
|
||||
new_zone.matrix_map->map = new unsigned int[new_map->height * new_map->width];
|
||||
new_zone.leds_count = new_kb.GetKeyCount();
|
||||
new_zone.leds_min = new_zone.leds_count;
|
||||
new_zone.leds_max = new_zone.leds_count;
|
||||
|
||||
new_kb.GetKeyMap(new_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT);
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = new_kb.GetKeyNameAt(led_idx);
|
||||
new_led.value = new_kb.GetKeyValueAt(led_idx);
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
zones.push_back(new_zone);
|
||||
SetupColors();
|
||||
DeviceUpdateMode();
|
||||
update_device = true;
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::DeviceUpdateLEDs()
|
||||
{
|
||||
if (update_device.load())
|
||||
{
|
||||
unsigned char* color_data = new unsigned char[(leds.size()*4)];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Filling the color_data vector with progressive index |
|
||||
| leaving space for RGB data |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
const unsigned int idx = led_idx * 4;
|
||||
color_data[idx] = leds[led_idx].value;
|
||||
color_data[idx + 1] = RGBGetRValue(colors[led_idx]);
|
||||
color_data[idx + 2] = RGBGetGValue(colors[led_idx]);
|
||||
color_data[idx + 3] = RGBGetBValue(colors[led_idx]);
|
||||
}
|
||||
|
||||
controller->SendDirect(modes[active_mode].brightness, color_data, (leds.size()*4));
|
||||
delete[] color_data;
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::DeviceUpdateMode()
|
||||
{
|
||||
static mode current_mode;
|
||||
|
||||
if(modes[active_mode].value != current_mode.value && found_device.load())
|
||||
{
|
||||
current_mode = modes[active_mode];
|
||||
controller->SelectMode(modes[active_mode].value);
|
||||
}
|
||||
|
||||
if(current_mode.color_mode != MODE_FLAG_HAS_PER_LED_COLOR && update_device.load())
|
||||
{
|
||||
controller->SendModeDetails(&modes[active_mode]);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::DeviceSaveMode()
|
||||
{
|
||||
controller->SaveData(modes[active_mode].value);
|
||||
}
|
||||
|
||||
void RGBController_Mountain60Keyboard::UpdateMountain()
|
||||
{
|
||||
while (mountaint_thread_running.load())
|
||||
{
|
||||
std::this_thread::sleep_for(MOUNTAIN60_KEEP_LIVE_PERIOD);
|
||||
|
||||
controller->UpdateData();
|
||||
|
||||
const char* Path = controller->GetPath();
|
||||
hid_device * rescan_device = hid_open_path(Path);
|
||||
|
||||
if (rescan_device)
|
||||
{
|
||||
if (!found_device.load())
|
||||
{
|
||||
controller->SetDevice(rescan_device);
|
||||
found_device = true;
|
||||
update_device = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (found_device.load())
|
||||
{
|
||||
update_device = false;
|
||||
found_device = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_MountainKeyboard.h |
|
||||
| |
|
||||
| RGBController for Mountain keyboard |
|
||||
| |
|
||||
| Soufian Batta Jan 2023 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include "RGBController.h"
|
||||
#include "Mountain60KeyboardController.h"
|
||||
|
||||
#define MOUNTAIN60_KEYBOARD_BRIGHTNESS_MIN 0
|
||||
#define MOUNTAIN60_KEYBOARD_BRIGHTNESS_MAX 4
|
||||
|
||||
#define MOUNTAIN60_KEYBOARD_SPEED_MIN 0
|
||||
#define MOUNTAIN60_KEYBOARD_SPEED_MAX 4
|
||||
#define MOUNTAIN60_KEYBOARD_SPEED_DEFAULT 2
|
||||
#define MOUNTAIN60_KEEP_LIVE_PERIOD 500ms
|
||||
|
||||
|
||||
class RGBController_Mountain60Keyboard : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_Mountain60Keyboard(Mountain60KeyboardController* controller_ptr);
|
||||
~RGBController_Mountain60Keyboard();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
void DeviceSaveMode();
|
||||
void UpdateMountain();
|
||||
|
||||
private:
|
||||
Mountain60KeyboardController* controller;
|
||||
std::thread* mountain_thread;
|
||||
std::atomic<bool> mountaint_thread_running;
|
||||
std::atomic<bool> update_device;
|
||||
std::atomic<bool> found_device;
|
||||
};
|
||||
174
Detector.h
174
Detector.h
@@ -11,31 +11,151 @@
|
||||
|
||||
#include "DeviceDetector.h"
|
||||
|
||||
#define REGISTER_DETECTOR(name, func) static DeviceDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_I2C_DETECTOR(name, func) static I2CDeviceDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_I2C_DIMM_DETECTOR(name, func, jedec_id, dimm_type) static I2CDIMMDeviceDetector device_detector_obj_##func##jedec_id(name, func, jedec_id, dimm_type)
|
||||
#define REGISTER_I2C_PCI_DETECTOR(name, func, ven, dev, subven, subdev, addr) static I2CPCIDeviceDetector device_detector_obj_##ven##dev##subven##subdev##addr##func(name, func, ven, dev, subven, subdev, addr)
|
||||
#define REGISTER_I2C_BUS_DETECTOR(func) static I2CBusDetector device_detector_obj_##func(func)
|
||||
#define REGISTER_HID_DETECTOR(name, func, vid, pid) static HIDDeviceDetector device_detector_obj_##vid##pid(name, func, vid, pid, HID_INTERFACE_ANY, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_I(name, func, vid, pid, interface) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface(name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_IP(name, func, vid, pid, interface, page) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, func, vid, pid, interface, page, HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
|
||||
#define REGISTER_HID_DETECTOR_P(name, func, vid, pid, page) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_PU(name, func, vid, pid, page, usage) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR(name, func, vid, pid) static HIDWrappedDeviceDetector device_detector_obj_##vid##pid(name, func, vid, pid, HID_INTERFACE_ANY, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR_I(name, func, vid, pid, interface) static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##_##interface(name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR_PU(name, func, vid, pid, page, usage) static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
|
||||
#define REGISTER_DYNAMIC_DETECTOR(name, func) static DynamicDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_PRE_DETECTION_HOOK(func) static PreDetectionHook device_detector_obj_##func(func)
|
||||
#define REGISTER_DETECTOR(name, func) static DeviceDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_I2C_DETECTOR(name, func) \
|
||||
static I2CDeviceDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_I2C_DIMM_DETECTOR(name, func, jedec_id, dimm_type) \
|
||||
static I2CDIMMDeviceDetector device_detector_obj_##func##jedec_id(name, \
|
||||
func, \
|
||||
jedec_id, \
|
||||
dimm_type)
|
||||
#define REGISTER_I2C_PCI_DETECTOR(name, func, ven, dev, subven, subdev, addr) \
|
||||
static I2CPCIDeviceDetector device_detector_obj_##ven##dev##subven##subdev##addr##func(name, \
|
||||
func, \
|
||||
ven, \
|
||||
dev, \
|
||||
subven, \
|
||||
subdev, \
|
||||
addr)
|
||||
#define REGISTER_I2C_BUS_DETECTOR(func) static I2CBusDetector device_detector_obj_##func(func)
|
||||
#define REGISTER_HID_DETECTOR(name, func, vid, pid) \
|
||||
static HIDDeviceDetector device_detector_obj_##vid##pid(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
HID_INTERFACE_ANY, \
|
||||
HID_USAGE_PAGE_ANY, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_I(name, func, vid, pid, interface) \
|
||||
static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
interface, \
|
||||
HID_USAGE_PAGE_ANY, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_IP(name, func, vid, pid, interface, page) \
|
||||
static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
interface, \
|
||||
page, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) \
|
||||
static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage( \
|
||||
name, func, vid, pid, interface, page, usage)
|
||||
#define REGISTER_HID_DETECTOR_P(name, func, vid, pid, page) \
|
||||
static HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
HID_INTERFACE_ANY, \
|
||||
page, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_HID_DETECTOR_PU(name, func, vid, pid, page, usage) \
|
||||
static HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
HID_INTERFACE_ANY, \
|
||||
page, \
|
||||
usage)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR(name, func, vid, pid) \
|
||||
static HIDWrappedDeviceDetector device_detector_obj_##vid##pid(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
HID_INTERFACE_ANY, \
|
||||
HID_USAGE_PAGE_ANY, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR_I(name, func, vid, pid, interface) \
|
||||
static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##_##interface( \
|
||||
name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) \
|
||||
static HIDWrappedDeviceDetector \
|
||||
device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
interface, \
|
||||
page, \
|
||||
usage)
|
||||
#define REGISTER_HID_WRAPPED_DETECTOR_PU(name, func, vid, pid, page, usage) \
|
||||
static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage( \
|
||||
name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
|
||||
#define REGISTER_DYNAMIC_DETECTOR(name, func) \
|
||||
static DynamicDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_PRE_DETECTION_HOOK(func) static PreDetectionHook device_detector_obj_##func(func)
|
||||
|
||||
#define REGISTER_DYNAMIC_I2C_DETECTOR(name, func) I2CDeviceDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_DYNAMIC_I2C_DIMM_DETECTOR(name, func, jedec_id, dimm_type) I2CDIMMDeviceDetector device_detector_obj_##func(name, func, jedec_id, dimm_type)
|
||||
#define REGISTER_DYNAMIC_I2C_PCI_DETECTOR(name, func, ven, dev, subven, subdev, addr) I2CPCIDeviceDetector device_detector_obj_##ven##dev##subven##subdev##addr##func(name, func, ven, dev, subven, subdev, addr)
|
||||
#define REGISTER_DYNAMIC_I2C_BUS_DETECTOR(func) I2CBusDetector device_detector_obj_##func(func)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR(name, func, vid, pid) HIDDeviceDetector device_detector_obj_##vid##pid(name, func, vid, pid, HID_INTERFACE_ANY, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_I(name, func, vid, pid, interface) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface(name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_IP(name, func, vid, pid, interface, page) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, func, vid, pid, interface, page, HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_P(name, func, vid, pid, page) HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_PU(name, func, vid, pid, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
|
||||
#define REGISTER_DYNAMIC_I2C_DETECTOR(name, func) \
|
||||
I2CDeviceDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_DYNAMIC_I2C_DIMM_DETECTOR(name, func, jedec_id, dimm_type) \
|
||||
I2CDIMMDeviceDetector device_detector_obj_##func(name, func, jedec_id, dimm_type)
|
||||
#define REGISTER_DYNAMIC_I2C_PCI_DETECTOR(name, func, ven, dev, subven, subdev, addr) \
|
||||
I2CPCIDeviceDetector device_detector_obj_##ven##dev##subven##subdev##addr##func(name, \
|
||||
func, \
|
||||
ven, \
|
||||
dev, \
|
||||
subven, \
|
||||
subdev, \
|
||||
addr)
|
||||
#define REGISTER_DYNAMIC_I2C_BUS_DETECTOR(func) I2CBusDetector device_detector_obj_##func(func)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR(name, func, vid, pid) \
|
||||
HIDDeviceDetector device_detector_obj_##vid##pid(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
HID_INTERFACE_ANY, \
|
||||
HID_USAGE_PAGE_ANY, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_I(name, func, vid, pid, interface) \
|
||||
HIDDeviceDetector device_detector_obj_##vid##pid##_##interface(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
interface, \
|
||||
HID_USAGE_PAGE_ANY, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_IP(name, func, vid, pid, interface, page) \
|
||||
HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
interface, \
|
||||
page, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) \
|
||||
HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
interface, \
|
||||
page, \
|
||||
usage)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_P(name, func, vid, pid, page) \
|
||||
HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
HID_INTERFACE_ANY, \
|
||||
page, \
|
||||
HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_PU(name, func, vid, pid, page, usage) \
|
||||
HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, \
|
||||
func, \
|
||||
vid, \
|
||||
pid, \
|
||||
HID_INTERFACE_ANY, \
|
||||
page, \
|
||||
usage)
|
||||
|
||||
@@ -19,35 +19,50 @@ class DeviceDetector
|
||||
{
|
||||
public:
|
||||
DeviceDetector(std::string name, DeviceDetectorFunction detector)
|
||||
{
|
||||
{
|
||||
ResourceManager::get()->RegisterDeviceDetector(name, detector);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class I2CDeviceDetector
|
||||
{
|
||||
public:
|
||||
I2CDeviceDetector(std::string name, I2CDeviceDetectorFunction detector)
|
||||
{
|
||||
{
|
||||
ResourceManager::get()->RegisterI2CDeviceDetector(name, detector);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class I2CDIMMDeviceDetector
|
||||
{
|
||||
public:
|
||||
I2CDIMMDeviceDetector(std::string name, I2CDIMMDeviceDetectorFunction detector, uint16_t jedec_id, uint8_t dimm_type)
|
||||
{
|
||||
I2CDIMMDeviceDetector(std::string name,
|
||||
I2CDIMMDeviceDetectorFunction detector,
|
||||
uint16_t jedec_id,
|
||||
uint8_t dimm_type)
|
||||
{
|
||||
ResourceManager::get()->RegisterI2CDIMMDeviceDetector(name, detector, jedec_id, dimm_type);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class I2CPCIDeviceDetector
|
||||
{
|
||||
public:
|
||||
I2CPCIDeviceDetector(std::string name, I2CPCIDeviceDetectorFunction detector, uint16_t ven_id, uint16_t dev_id, uint16_t subven_id, uint16_t subdev_id, uint8_t i2c_addr)
|
||||
I2CPCIDeviceDetector(std::string name,
|
||||
I2CPCIDeviceDetectorFunction detector,
|
||||
uint16_t ven_id,
|
||||
uint16_t dev_id,
|
||||
uint16_t subven_id,
|
||||
uint16_t subdev_id,
|
||||
uint8_t i2c_addr)
|
||||
{
|
||||
ResourceManager::get()->RegisterI2CPCIDeviceDetector(name, detector, ven_id, dev_id, subven_id, subdev_id, i2c_addr);
|
||||
ResourceManager::get()->RegisterI2CPCIDeviceDetector(name,
|
||||
detector,
|
||||
ven_id,
|
||||
dev_id,
|
||||
subven_id,
|
||||
subdev_id,
|
||||
i2c_addr);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -63,18 +78,37 @@ public:
|
||||
class HIDDeviceDetector
|
||||
{
|
||||
public:
|
||||
HIDDeviceDetector(std::string name, HIDDeviceDetectorFunction detector, uint16_t vid, uint16_t pid, int interface, int usage_page, int usage)
|
||||
HIDDeviceDetector(std::string name,
|
||||
HIDDeviceDetectorFunction detector,
|
||||
uint16_t vid,
|
||||
uint16_t pid,
|
||||
int interface,
|
||||
int usage_page,
|
||||
int usage)
|
||||
{
|
||||
ResourceManager::get()->RegisterHIDDeviceDetector(name, detector, vid, pid, interface, usage_page, usage);
|
||||
ResourceManager::get()
|
||||
->RegisterHIDDeviceDetector(name, detector, vid, pid, interface, usage_page, usage);
|
||||
}
|
||||
};
|
||||
|
||||
class HIDWrappedDeviceDetector
|
||||
{
|
||||
public:
|
||||
HIDWrappedDeviceDetector(std::string name, HIDWrappedDeviceDetectorFunction detector, uint16_t vid, uint16_t pid, int interface, int usage_page, int usage)
|
||||
HIDWrappedDeviceDetector(std::string name,
|
||||
HIDWrappedDeviceDetectorFunction detector,
|
||||
uint16_t vid,
|
||||
uint16_t pid,
|
||||
int interface,
|
||||
int usage_page,
|
||||
int usage)
|
||||
{
|
||||
ResourceManager::get()->RegisterHIDWrappedDeviceDetector(name, detector, vid, pid, interface, usage_page, usage);
|
||||
ResourceManager::get()->RegisterHIDWrappedDeviceDetector(name,
|
||||
detector,
|
||||
vid,
|
||||
pid,
|
||||
interface,
|
||||
usage_page,
|
||||
usage);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
206
LogManager.cpp
206
LogManager.cpp
@@ -17,10 +17,11 @@
|
||||
|
||||
#include "filesystem.h"
|
||||
|
||||
const char* LogManager::log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:", "Dialog:"};
|
||||
const char *LogManager::log_codes[]
|
||||
= {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:", "Dialog:"};
|
||||
|
||||
const char* TimestampPattern = "%04d%02d%02d_%02d%02d%02d";
|
||||
const char* TimestampRegex = "[0-9]{8}_[0-9]{6}"; // relies on the structure of the template above
|
||||
const char *TimestampPattern = "%04d%02d%02d_%02d%02d%02d";
|
||||
const char *TimestampRegex = "[0-9]{8}_[0-9]{6}"; // relies on the structure of the template above
|
||||
|
||||
LogManager::LogManager()
|
||||
{
|
||||
@@ -29,44 +30,39 @@ LogManager::LogManager()
|
||||
log_file_enabled = true;
|
||||
}
|
||||
|
||||
LogManager* LogManager::get()
|
||||
LogManager *LogManager::get()
|
||||
{
|
||||
static LogManager* _instance = nullptr;
|
||||
static LogManager *_instance = nullptr;
|
||||
static std::mutex instance_mutex;
|
||||
std::lock_guard<std::mutex> grd(instance_mutex);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Create a new instance if one does not exist |
|
||||
\*-------------------------------------------------*/
|
||||
if(!_instance)
|
||||
{
|
||||
if (!_instance) {
|
||||
_instance = new LogManager();
|
||||
}
|
||||
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
unsigned int LogManager::getLoglevel()
|
||||
{
|
||||
if(log_console_enabled)
|
||||
{
|
||||
return(LL_TRACE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(loglevel);
|
||||
if (log_console_enabled) {
|
||||
return (LL_TRACE);
|
||||
} else {
|
||||
return (loglevel);
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
void LogManager::configure(json config, const filesystem::path &defaultDir)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> grd(entry_mutex);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the log is not open, create a new log file |
|
||||
\*-------------------------------------------------*/
|
||||
if(!log_stream.is_open())
|
||||
{
|
||||
if (!log_stream.is_open()) {
|
||||
/*----------------------------------------------------*\
|
||||
| If a limit is declared in the config for the maximum |
|
||||
| number of log files, respect the limit |
|
||||
@@ -77,13 +73,11 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
| 0 or less equals no limit (default) |
|
||||
\*----------------------------------------------------*/
|
||||
int loglimit = 0;
|
||||
if(config.contains("file_count_limit") && config["file_count_limit"].is_number_integer())
|
||||
{
|
||||
if (config.contains("file_count_limit") && config["file_count_limit"].is_number_integer()) {
|
||||
loglimit = config["file_count_limit"];
|
||||
}
|
||||
|
||||
if(config.contains("log_file"))
|
||||
{
|
||||
if (config.contains("log_file")) {
|
||||
log_file_enabled = config["log_file"];
|
||||
}
|
||||
|
||||
@@ -93,21 +87,16 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
\*-----------------------------------------*/
|
||||
std::string logtempl = "OpenRGB_#.log";
|
||||
|
||||
if(log_file_enabled)
|
||||
{
|
||||
|
||||
if (log_file_enabled) {
|
||||
/*-------------------------------------------------*\
|
||||
| If the logfile is defined in the configuration, |
|
||||
| use the configured name |
|
||||
\*-------------------------------------------------*/
|
||||
if(config.contains("logfile"))
|
||||
{
|
||||
const json& logfile_obj = config["logfile"];
|
||||
if(logfile_obj.is_string())
|
||||
{
|
||||
if (config.contains("logfile")) {
|
||||
const json &logfile_obj = config["logfile"];
|
||||
if (logfile_obj.is_string()) {
|
||||
std::string tmpname = config["logfile"];
|
||||
if(!tmpname.empty())
|
||||
{
|
||||
if (!tmpname.empty()) {
|
||||
logtempl = tmpname;
|
||||
}
|
||||
}
|
||||
@@ -117,14 +106,21 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
| replace it with a timestamp |
|
||||
\*-------------------------------------------------*/
|
||||
time_t t = time(0);
|
||||
struct tm* tmp = localtime(&t);
|
||||
struct tm *tmp = localtime(&t);
|
||||
char time_string[64];
|
||||
snprintf(time_string, 64, TimestampPattern, 1900 + tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
|
||||
snprintf(time_string,
|
||||
64,
|
||||
TimestampPattern,
|
||||
1900 + tmp->tm_year,
|
||||
tmp->tm_mon + 1,
|
||||
tmp->tm_mday,
|
||||
tmp->tm_hour,
|
||||
tmp->tm_min,
|
||||
tmp->tm_sec);
|
||||
|
||||
std::string logname = logtempl;
|
||||
size_t oct = logname.find("#");
|
||||
if(oct != logname.npos)
|
||||
{
|
||||
if (oct != logname.npos) {
|
||||
logname.replace(oct, 1, time_string);
|
||||
}
|
||||
|
||||
@@ -132,8 +128,7 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
| If the path is relative, use logs dir |
|
||||
\*-------------------------------------------------*/
|
||||
filesystem::path p = filesystem::u8path(logname);
|
||||
if(p.is_relative())
|
||||
{
|
||||
if (p.is_relative()) {
|
||||
p = defaultDir / "logs" / logname;
|
||||
}
|
||||
filesystem::create_directories(p.parent_path());
|
||||
@@ -153,9 +148,12 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
| Print Git Commit info, version, etc. |
|
||||
\*-------------------------------------------------*/
|
||||
log_stream << " OpenRGB v" << VERSION_STRING << std::endl;
|
||||
log_stream << " Commit: " << GIT_COMMIT_ID << " from " << GIT_COMMIT_DATE << std::endl;
|
||||
log_stream << " Commit: " << GIT_COMMIT_ID << " from " << GIT_COMMIT_DATE
|
||||
<< std::endl;
|
||||
log_stream << " Launched: " << time_string << std::endl;
|
||||
log_stream << "====================================================================================================" << std::endl;
|
||||
log_stream << "========================================================================"
|
||||
"============================"
|
||||
<< std::endl;
|
||||
log_stream << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -163,15 +161,13 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
/*-------------------------------------------------*\
|
||||
| Check loglevel configuration |
|
||||
\*-------------------------------------------------*/
|
||||
if(config.contains("loglevel"))
|
||||
{
|
||||
const json& loglevel_obj = config["loglevel"];
|
||||
if (config.contains("loglevel")) {
|
||||
const json &loglevel_obj = config["loglevel"];
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set the log level if configured |
|
||||
\*-------------------------------------------------*/
|
||||
if(loglevel_obj.is_number_integer())
|
||||
{
|
||||
if (loglevel_obj.is_number_integer()) {
|
||||
loglevel = loglevel_obj;
|
||||
}
|
||||
}
|
||||
@@ -179,8 +175,7 @@ void LogManager::configure(json config, const filesystem::path& defaultDir)
|
||||
/*-------------------------------------------------*\
|
||||
| Check log console configuration |
|
||||
\*-------------------------------------------------*/
|
||||
if(config.contains("log_console"))
|
||||
{
|
||||
if (config.contains("log_console")) {
|
||||
log_console_enabled = config["log_console"];
|
||||
}
|
||||
|
||||
@@ -195,23 +190,22 @@ void LogManager::_flush()
|
||||
/*-------------------------------------------------*\
|
||||
| If the log is open, write out buffered messages |
|
||||
\*-------------------------------------------------*/
|
||||
if(log_stream.is_open())
|
||||
{
|
||||
for(size_t msg = 0; msg < temp_messages.size(); ++msg)
|
||||
{
|
||||
if(temp_messages[msg]->level <= loglevel || temp_messages[msg]->level == LL_DIALOG)
|
||||
{
|
||||
if (log_stream.is_open()) {
|
||||
for (size_t msg = 0; msg < temp_messages.size(); ++msg) {
|
||||
if (temp_messages[msg]->level <= loglevel || temp_messages[msg]->level == LL_DIALOG) {
|
||||
// Put the timestamp here
|
||||
std::chrono::milliseconds counter = std::chrono::duration_cast<std::chrono::milliseconds>(temp_messages[msg]->counted_second);
|
||||
log_stream << std::left << std::setw(6) << counter.count() << "|";
|
||||
std::chrono::milliseconds counter
|
||||
= std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
temp_messages[msg]->counted_second);
|
||||
log_stream << std::left << std::setw(6) << counter.count() << "|";
|
||||
log_stream << std::left << std::setw(9) << log_codes[temp_messages[msg]->level];
|
||||
log_stream << temp_messages[msg]->buffer;
|
||||
|
||||
if(print_source)
|
||||
{
|
||||
log_stream << " [" << temp_messages[msg]->filename << ":" << temp_messages[msg]->line << "]";
|
||||
|
||||
if (print_source) {
|
||||
log_stream << " [" << temp_messages[msg]->filename << ":"
|
||||
<< temp_messages[msg]->line << "]";
|
||||
}
|
||||
|
||||
|
||||
log_stream << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -234,14 +228,14 @@ void LogManager::flush()
|
||||
_flush();
|
||||
}
|
||||
|
||||
void LogManager::_append(const char* filename, int line, unsigned int level, const char* fmt, va_list va)
|
||||
void LogManager::_append(
|
||||
const char *filename, int line, unsigned int level, const char *fmt, va_list va)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| If a critical message occurs, enable source |
|
||||
| printing and set loglevel and verbosity to highest|
|
||||
\*-------------------------------------------------*/
|
||||
if(level == LL_FATAL)
|
||||
{
|
||||
if (level == LL_FATAL) {
|
||||
print_source = true;
|
||||
loglevel = LL_DEBUG;
|
||||
verbosity = LL_DEBUG;
|
||||
@@ -265,19 +259,17 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
||||
/*-------------------------------------------------*\
|
||||
| Fill in message information |
|
||||
\*-------------------------------------------------*/
|
||||
mes->level = level;
|
||||
mes->filename = filename;
|
||||
mes->line = line;
|
||||
mes->level = level;
|
||||
mes->filename = filename;
|
||||
mes->line = line;
|
||||
mes->counted_second = std::chrono::steady_clock::now() - base_clock;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If this is a dialog message, call the dialog show |
|
||||
| callback |
|
||||
\*-------------------------------------------------*/
|
||||
if(level == LL_DIALOG)
|
||||
{
|
||||
for(size_t idx = 0; idx < dialog_show_callbacks.size(); idx++)
|
||||
{
|
||||
if (level == LL_DIALOG) {
|
||||
for (size_t idx = 0; idx < dialog_show_callbacks.size(); idx++) {
|
||||
dialog_show_callbacks[idx](dialog_show_callback_args[idx], mes);
|
||||
}
|
||||
}
|
||||
@@ -287,11 +279,9 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
||||
| print it on the screen |
|
||||
| TODO: Put the timestamp here |
|
||||
\*-------------------------------------------------*/
|
||||
if(level <= verbosity || level == LL_DIALOG)
|
||||
{
|
||||
if (level <= verbosity || level == LL_DIALOG) {
|
||||
std::cout << mes->buffer;
|
||||
if(print_source)
|
||||
{
|
||||
if (print_source) {
|
||||
std::cout << " [" << mes->filename << ":" << mes->line << "]";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
@@ -302,8 +292,7 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
||||
\*-------------------------------------------------*/
|
||||
temp_messages.push_back(mes);
|
||||
|
||||
if(log_console_enabled)
|
||||
{
|
||||
if (log_console_enabled) {
|
||||
all_messages.push_back(mes);
|
||||
}
|
||||
|
||||
@@ -323,7 +312,7 @@ void LogManager::clearMessages()
|
||||
all_messages.clear();
|
||||
}
|
||||
|
||||
void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, ...)
|
||||
void LogManager::append(const char *filename, int line, unsigned int level, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
@@ -340,8 +329,7 @@ void LogManager::setLoglevel(unsigned int level)
|
||||
| Check that the new log level is valid, otherwise |
|
||||
| set it within the valid range |
|
||||
\*-------------------------------------------------*/
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
if (level > LL_TRACE) {
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
@@ -360,8 +348,7 @@ void LogManager::setVerbosity(unsigned int level)
|
||||
| set it within the valid range |
|
||||
\*-------------------------------------------------*/
|
||||
|
||||
if(level > LL_TRACE)
|
||||
{
|
||||
if (level > LL_TRACE) {
|
||||
level = LL_TRACE;
|
||||
}
|
||||
|
||||
@@ -379,29 +366,28 @@ void LogManager::setPrintSource(bool v)
|
||||
print_source = v;
|
||||
}
|
||||
|
||||
void LogManager::RegisterDialogShowCallback(LogDialogShowCallback callback, void* receiver)
|
||||
void LogManager::RegisterDialogShowCallback(LogDialogShowCallback callback, void *receiver)
|
||||
{
|
||||
LOG_DEBUG("[LogManager] dialog show callback registered");
|
||||
dialog_show_callbacks.push_back(callback);
|
||||
dialog_show_callback_args.push_back(receiver);
|
||||
}
|
||||
|
||||
void LogManager::UnregisterDialogShowCallback(LogDialogShowCallback callback, void* receiver)
|
||||
void LogManager::UnregisterDialogShowCallback(LogDialogShowCallback callback, void *receiver)
|
||||
{
|
||||
for(size_t idx = 0; idx < dialog_show_callbacks.size(); idx++)
|
||||
{
|
||||
if(dialog_show_callbacks[idx] == callback && dialog_show_callback_args[idx] == receiver)
|
||||
{
|
||||
for (size_t idx = 0; idx < dialog_show_callbacks.size(); idx++) {
|
||||
if (dialog_show_callbacks[idx] == callback && dialog_show_callback_args[idx] == receiver) {
|
||||
dialog_show_callbacks.erase(dialog_show_callbacks.begin() + idx);
|
||||
dialog_show_callback_args.erase(dialog_show_callback_args.begin() + idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogManager::rotate_logs(const filesystem::path& folder, const filesystem::path& templ, int max_count)
|
||||
void LogManager::rotate_logs(const filesystem::path &folder,
|
||||
const filesystem::path &templ,
|
||||
int max_count)
|
||||
{
|
||||
if(max_count < 1)
|
||||
{
|
||||
if (max_count < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -411,10 +397,8 @@ void LogManager::rotate_logs(const filesystem::path& folder, const filesystem::p
|
||||
// The # symbol is replaced with a timestamp regex
|
||||
// Any regex-unfriendly symbols are escaped with a backslash
|
||||
std::string regex_templ = "^";
|
||||
for(size_t i = 0; i < templ2.size(); ++i)
|
||||
{
|
||||
switch(templ2[i])
|
||||
{
|
||||
for (size_t i = 0; i < templ2.size(); ++i) {
|
||||
switch (templ2[i]) {
|
||||
// Symbols that have special meanings in regex'es need backslash escaping
|
||||
case '.':
|
||||
case '^':
|
||||
@@ -449,35 +433,35 @@ void LogManager::rotate_logs(const filesystem::path& folder, const filesystem::p
|
||||
|
||||
std::vector<filesystem::path> valid_paths;
|
||||
std::filesystem::directory_iterator it(folder);
|
||||
for(; it != filesystem::end(it); ++it)
|
||||
{
|
||||
if(it->is_regular_file())
|
||||
{
|
||||
for (; it != filesystem::end(it); ++it) {
|
||||
if (it->is_regular_file()) {
|
||||
std::string fname = it->path().filename().u8string();
|
||||
if(std::regex_match(fname, r))
|
||||
{
|
||||
if (std::regex_match(fname, r)) {
|
||||
valid_paths.push_back(it->path());
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(valid_paths.begin(), valid_paths.end());
|
||||
|
||||
size_t remove_count = valid_paths.size() - max_count + 1; // NOTE: the "1" extra file to remove creates space for the one we're about to create
|
||||
if(remove_count > valid_paths.size()) // for max_count <= 0 and to prevent any possible errors in the above logic
|
||||
size_t remove_count
|
||||
= valid_paths.size() - max_count
|
||||
+ 1; // NOTE: the "1" extra file to remove creates space for the one we're about to create
|
||||
if (remove_count
|
||||
> valid_paths
|
||||
.size()) // for max_count <= 0 and to prevent any possible errors in the above logic
|
||||
{
|
||||
remove_count = valid_paths.size();
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < remove_count; ++i)
|
||||
{
|
||||
for (size_t i = 0; i < remove_count; ++i) {
|
||||
std::error_code ec; // Uses error code to force the `remove` call to be `noexcept`
|
||||
if(filesystem::remove(valid_paths[i], ec))
|
||||
{
|
||||
LOG_VERBOSE("[LogManager] Removed log file [%s] during rotation", valid_paths[i].u8string().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[LogManager] Failed to remove log file [%s] during rotation: %s", valid_paths[i].u8string().c_str(), ec.message().c_str());
|
||||
if (filesystem::remove(valid_paths[i], ec)) {
|
||||
LOG_VERBOSE("[LogManager] Removed log file [%s] during rotation",
|
||||
valid_paths[i].u8string().c_str());
|
||||
} else {
|
||||
LOG_WARNING("[LogManager] Failed to remove log file [%s] during rotation: %s",
|
||||
valid_paths[i].u8string().c_str(),
|
||||
ec.message().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
76
LogManager.h
76
LogManager.h
@@ -22,50 +22,54 @@
|
||||
| Common LOG strings |
|
||||
| This may need to be in it's own .h file |
|
||||
\*-------------------------------------------------*/
|
||||
#define SMBUS_CHECK_DEVICE_MESSAGE_EN "[%s] Bus %02d is a motherboard and the subvendor matches the one for %s, looking for a device at 0x%02X"
|
||||
#define SMBUS_CHECK_DEVICE_FAILURE_EN "[%s] Bus %02d is not a motherboard or the subvendor does not match the one for %s, skipping detection"
|
||||
#define SMBUS_CHECK_DEVICE_MESSAGE_EN \
|
||||
"[%s] Bus %02d is a motherboard and the subvendor matches the one for %s, looking for a " \
|
||||
"device at 0x%02X"
|
||||
#define SMBUS_CHECK_DEVICE_FAILURE_EN \
|
||||
"[%s] Bus %02d is not a motherboard or the subvendor does not match the one for %s, skipping " \
|
||||
"detection"
|
||||
|
||||
#define GPU_DETECT_MESSAGE "[%s] Found a device match at Bus %02d for Device 0x%04X and SubDevice 0x%04X: %s"
|
||||
#define GPU_DETECT_MESSAGE \
|
||||
"[%s] Found a device match at Bus %02d for Device 0x%04X and SubDevice 0x%04X: %s"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
enum
|
||||
{
|
||||
LL_FATAL, // Critical unrecoverable errors that cause a generalized crash of a module or of the entire app
|
||||
LL_ERROR, // Local errors that abort an operation
|
||||
LL_WARNING, // Local errors that may cause an operation to have an undefined behavior or may have dangerous/unforeseen consequences
|
||||
LL_INFO, // Initialization messages, significant actions and follow-up information
|
||||
LL_VERBOSE, // Tracing of commands and performed actions, usually for debug purposes, comments on the higher priority messages
|
||||
LL_DEBUG, // Deep tracing, "printf-style debugging" alternative, for debug purposes. Such messages should be put all over the code instead of comments
|
||||
enum {
|
||||
LL_FATAL, // Critical unrecoverable errors that cause a generalized crash of a module or of the entire app
|
||||
LL_ERROR, // Local errors that abort an operation
|
||||
LL_WARNING, // Local errors that may cause an operation to have an undefined behavior or may have dangerous/unforeseen consequences
|
||||
LL_INFO, // Initialization messages, significant actions and follow-up information
|
||||
LL_VERBOSE, // Tracing of commands and performed actions, usually for debug purposes, comments on the higher priority messages
|
||||
LL_DEBUG, // Deep tracing, "printf-style debugging" alternative, for debug purposes. Such messages should be put all over the code instead of comments
|
||||
LL_TRACE,
|
||||
LL_DIALOG // Log messages to be shown in a GUI dialog box
|
||||
LL_DIALOG // Log messages to be shown in a GUI dialog box
|
||||
};
|
||||
|
||||
struct LogMessage
|
||||
{
|
||||
std::string buffer;
|
||||
unsigned int level;
|
||||
const char* filename;
|
||||
const char *filename;
|
||||
int line;
|
||||
std::chrono::duration<double> counted_second;
|
||||
// int timestamp or float time_offset? TBD
|
||||
};
|
||||
typedef std::shared_ptr<LogMessage> PLogMessage;
|
||||
typedef void(*LogDialogShowCallback)(void*, PLogMessage);
|
||||
typedef void (*LogDialogShowCallback)(void *, PLogMessage);
|
||||
|
||||
class LogManager
|
||||
{
|
||||
private:
|
||||
LogManager();
|
||||
LogManager(const LogManager&) = delete;
|
||||
LogManager(LogManager&&) = delete;
|
||||
LogManager(const LogManager &) = delete;
|
||||
LogManager(LogManager &&) = delete;
|
||||
~LogManager();
|
||||
std::recursive_mutex entry_mutex;
|
||||
std::mutex section_mutex;
|
||||
std::ofstream log_stream;
|
||||
|
||||
std::vector<LogDialogShowCallback> dialog_show_callbacks;
|
||||
std::vector<void*> dialog_show_callback_args;
|
||||
std::vector<LogDialogShowCallback> dialog_show_callbacks;
|
||||
std::vector<void *> dialog_show_callback_args;
|
||||
|
||||
// A temporary log message storage to hold them until the stream opens
|
||||
std::vector<PLogMessage> temp_messages;
|
||||
@@ -86,41 +90,41 @@ private:
|
||||
std::chrono::time_point<std::chrono::steady_clock> base_clock;
|
||||
|
||||
// A non-guarded append()
|
||||
void _append(const char* filename, int line, unsigned int level, const char* fmt, va_list va);
|
||||
void _append(const char *filename, int line, unsigned int level, const char *fmt, va_list va);
|
||||
|
||||
// A non-guarded flush()
|
||||
void _flush();
|
||||
|
||||
void rotate_logs(const filesystem::path& folder, const filesystem::path& templ, int max_count);
|
||||
void rotate_logs(const filesystem::path &folder, const filesystem::path &templ, int max_count);
|
||||
|
||||
public:
|
||||
static LogManager* get();
|
||||
void configure(json config, const filesystem::path & defaultDir);
|
||||
static LogManager *get();
|
||||
void configure(json config, const filesystem::path &defaultDir);
|
||||
void flush();
|
||||
void append(const char* filename, int line, unsigned int level, const char* fmt, ...);
|
||||
void append(const char *filename, int line, unsigned int level, const char *fmt, ...);
|
||||
void setLoglevel(unsigned int);
|
||||
void setVerbosity(unsigned int);
|
||||
void setPrintSource(bool);
|
||||
void RegisterDialogShowCallback(LogDialogShowCallback callback, void* receiver);
|
||||
void UnregisterDialogShowCallback(LogDialogShowCallback callback, void* receiver);
|
||||
void RegisterDialogShowCallback(LogDialogShowCallback callback, void *receiver);
|
||||
void UnregisterDialogShowCallback(LogDialogShowCallback callback, void *receiver);
|
||||
unsigned int getLoglevel();
|
||||
unsigned int getVerbosity() {return verbosity;}
|
||||
unsigned int getVerbosity() { return verbosity; }
|
||||
void clearMessages();
|
||||
std::vector<PLogMessage> messages();
|
||||
|
||||
bool log_console_enabled;
|
||||
bool log_file_enabled;
|
||||
static const char* log_codes[];
|
||||
static const char *log_codes[];
|
||||
};
|
||||
|
||||
#define LogAppend(level, ...) LogManager::get()->append(__FILE__, __LINE__, level, __VA_ARGS__)
|
||||
#define LOG_FATAL(...) LogAppend(LL_FATAL, __VA_ARGS__)
|
||||
#define LOG_ERROR(...) LogAppend(LL_ERROR, __VA_ARGS__)
|
||||
#define LOG_WARNING(...) LogAppend(LL_WARNING, __VA_ARGS__)
|
||||
#define LOG_INFO(...) LogAppend(LL_INFO, __VA_ARGS__)
|
||||
#define LOG_VERBOSE(...) LogAppend(LL_VERBOSE, __VA_ARGS__)
|
||||
#define LOG_DEBUG(...) LogAppend(LL_DEBUG, __VA_ARGS__)
|
||||
#define LOG_TRACE(...) LogAppend(LL_TRACE, __VA_ARGS__)
|
||||
#define LOG_DIALOG(...) LogAppend(LL_DIALOG, __VA_ARGS__)
|
||||
#define LogAppend(level, ...) LogManager::get()->append(__FILE__, __LINE__, level, __VA_ARGS__)
|
||||
#define LOG_FATAL(...) LogAppend(LL_FATAL, __VA_ARGS__)
|
||||
#define LOG_ERROR(...) LogAppend(LL_ERROR, __VA_ARGS__)
|
||||
#define LOG_WARNING(...) LogAppend(LL_WARNING, __VA_ARGS__)
|
||||
#define LOG_INFO(...) LogAppend(LL_INFO, __VA_ARGS__)
|
||||
#define LOG_VERBOSE(...) LogAppend(LL_VERBOSE, __VA_ARGS__)
|
||||
#define LOG_DEBUG(...) LogAppend(LL_DEBUG, __VA_ARGS__)
|
||||
#define LOG_TRACE(...) LogAppend(LL_TRACE, __VA_ARGS__)
|
||||
#define LOG_DIALOG(...) LogAppend(LL_DIALOG, __VA_ARGS__)
|
||||
|
||||
#endif // LOGMANAGER_H
|
||||
|
||||
@@ -29,17 +29,18 @@
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
|
||||
NetworkClient::NetworkClient(std::vector<RGBController *> &control)
|
||||
: controllers(control)
|
||||
{
|
||||
port_ip = "127.0.0.1";
|
||||
port_num = OPENRGB_SDK_PORT;
|
||||
client_sock = -1;
|
||||
server_connected = false;
|
||||
port_ip = "127.0.0.1";
|
||||
port_num = OPENRGB_SDK_PORT;
|
||||
client_sock = -1;
|
||||
server_connected = false;
|
||||
server_controller_count = 0;
|
||||
change_in_progress = false;
|
||||
change_in_progress = false;
|
||||
|
||||
ListenThread = NULL;
|
||||
ConnectionThread = NULL;
|
||||
ListenThread = NULL;
|
||||
ConnectionThread = NULL;
|
||||
}
|
||||
|
||||
NetworkClient::~NetworkClient()
|
||||
@@ -61,8 +62,8 @@ void NetworkClient::ClientInfoChanged()
|
||||
/*---------------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int callback_idx = 0; callback_idx < ClientInfoChangeCallbacks.size(); callback_idx++)
|
||||
{
|
||||
for (unsigned int callback_idx = 0; callback_idx < ClientInfoChangeCallbacks.size();
|
||||
callback_idx++) {
|
||||
ClientInfoChangeCallbacks[callback_idx](ClientInfoChangeCallbackArgs[callback_idx]);
|
||||
}
|
||||
|
||||
@@ -84,29 +85,27 @@ unsigned int NetworkClient::GetProtocolVersion()
|
||||
{
|
||||
unsigned int protocol_version = 0;
|
||||
|
||||
if(server_protocol_version > OPENRGB_SDK_PROTOCOL_VERSION)
|
||||
{
|
||||
if (server_protocol_version > OPENRGB_SDK_PROTOCOL_VERSION) {
|
||||
protocol_version = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
protocol_version = server_protocol_version;
|
||||
}
|
||||
|
||||
return(protocol_version);
|
||||
return (protocol_version);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetConnected()
|
||||
{
|
||||
return(server_connected);
|
||||
return (server_connected);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetOnline()
|
||||
{
|
||||
return(server_connected && server_initialized);
|
||||
return (server_connected && server_initialized);
|
||||
}
|
||||
|
||||
void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg)
|
||||
void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callback,
|
||||
void *new_callback_arg)
|
||||
{
|
||||
ClientInfoChangeCallbacks.push_back(new_callback);
|
||||
ClientInfoChangeCallbackArgs.push_back(new_callback_arg);
|
||||
@@ -114,8 +113,7 @@ void NetworkClient::RegisterClientInfoChangeCallback(NetClientCallback new_callb
|
||||
|
||||
void NetworkClient::SetIP(std::string new_ip)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
if (server_connected == false) {
|
||||
port_ip = new_ip;
|
||||
}
|
||||
}
|
||||
@@ -124,16 +122,14 @@ void NetworkClient::SetName(std::string new_name)
|
||||
{
|
||||
client_name = new_name;
|
||||
|
||||
if(server_connected == true)
|
||||
{
|
||||
if (server_connected == true) {
|
||||
SendData_ClientString();
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::SetPort(unsigned short new_port)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
if (server_connected == false) {
|
||||
port_num = new_port;
|
||||
}
|
||||
}
|
||||
@@ -167,25 +163,23 @@ void NetworkClient::StopClient()
|
||||
| Disconnect the server and set it as inactive |
|
||||
\*---------------------------------------------------------*/
|
||||
server_connected = false;
|
||||
client_active = false;
|
||||
client_active = false;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Shut down and close the client socket |
|
||||
\*---------------------------------------------------------*/
|
||||
if(server_connected)
|
||||
{
|
||||
if (server_connected) {
|
||||
shutdown(client_sock, SD_RECEIVE);
|
||||
closesocket(client_sock);
|
||||
}
|
||||
|
||||
client_active = false;
|
||||
client_active = false;
|
||||
server_connected = false;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Close the listen thread |
|
||||
\*---------------------------------------------------------*/
|
||||
if(ListenThread)
|
||||
{
|
||||
if (ListenThread) {
|
||||
ListenThread->join();
|
||||
delete ListenThread;
|
||||
ListenThread = nullptr;
|
||||
@@ -194,8 +188,7 @@ void NetworkClient::StopClient()
|
||||
/*---------------------------------------------------------*\
|
||||
| Close the connection thread |
|
||||
\*---------------------------------------------------------*/
|
||||
if(ConnectionThread)
|
||||
{
|
||||
if (ConnectionThread) {
|
||||
connection_cv.notify_all();
|
||||
ConnectionThread->join();
|
||||
delete ConnectionThread;
|
||||
@@ -217,10 +210,8 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
/*---------------------------------------------------------*\
|
||||
| This thread manages the connection to the server |
|
||||
\*---------------------------------------------------------*/
|
||||
while(client_active == true)
|
||||
{
|
||||
if(server_connected == false)
|
||||
{
|
||||
while (client_active == true) {
|
||||
if (server_connected == false) {
|
||||
/*---------------------------------------------------------*\
|
||||
| Connect to server and reconnect if the connection is lost |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -229,10 +220,9 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
/*---------------------------------------------------------*\
|
||||
| Try to connect to server |
|
||||
\*---------------------------------------------------------*/
|
||||
if(port.tcp_client_connect() == true)
|
||||
{
|
||||
if (port.tcp_client_connect() == true) {
|
||||
client_sock = port.sock;
|
||||
printf( "Connected to server\n" );
|
||||
printf("Connected to server\n");
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Server is now connected |
|
||||
@@ -253,21 +243,18 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
| Client info has changed, call the callbacks |
|
||||
\*---------------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "Connection attempt failed\n" );
|
||||
} else {
|
||||
printf("Connection attempt failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| Double-check client_active as it could have changed |
|
||||
\*-------------------------------------------------------------*/
|
||||
if(client_active && server_initialized == false && server_connected == true)
|
||||
{
|
||||
unsigned int timeout_counter = 0;
|
||||
requested_controllers = 0;
|
||||
server_controller_count = 0;
|
||||
if (client_active && server_initialized == false && server_connected == true) {
|
||||
unsigned int timeout_counter = 0;
|
||||
requested_controllers = 0;
|
||||
server_controller_count = 0;
|
||||
server_controller_count_received = false;
|
||||
server_protocol_version_received = false;
|
||||
|
||||
@@ -275,8 +262,7 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
| Wait for server to connect |
|
||||
\*---------------------------------------------------------*/
|
||||
connection_cv.wait_for(lock, 100ms);
|
||||
if(!client_active)
|
||||
{
|
||||
if (!client_active) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -288,11 +274,9 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
/*---------------------------------------------------------*\
|
||||
| Wait up to 1s for protocol version reply |
|
||||
\*---------------------------------------------------------*/
|
||||
while(!server_protocol_version_received)
|
||||
{
|
||||
while (!server_protocol_version_received) {
|
||||
connection_cv.wait_for(lock, 5ms);
|
||||
if(!client_active)
|
||||
{
|
||||
if (!client_active) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -303,9 +287,8 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
| server doesn't support protocol versioning and use |
|
||||
| protocol version 0 |
|
||||
\*---------------------------------------------------------*/
|
||||
if(timeout_counter > 200)
|
||||
{
|
||||
server_protocol_version = 0;
|
||||
if (timeout_counter > 200) {
|
||||
server_protocol_version = 0;
|
||||
server_protocol_version_received = true;
|
||||
}
|
||||
}
|
||||
@@ -323,11 +306,9 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
/*---------------------------------------------------------*\
|
||||
| Wait for server controller count |
|
||||
\*---------------------------------------------------------*/
|
||||
while(!server_controller_count_received)
|
||||
{
|
||||
while (!server_controller_count_received) {
|
||||
connection_cv.wait_for(lock, 5ms);
|
||||
if(!client_active)
|
||||
{
|
||||
if (!client_active) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -337,8 +318,7 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
/*---------------------------------------------------------*\
|
||||
| Once count is received, request controllers |
|
||||
\*---------------------------------------------------------*/
|
||||
while(requested_controllers < server_controller_count)
|
||||
{
|
||||
while (requested_controllers < server_controller_count) {
|
||||
printf("Client: Requesting controller %d\r\n", requested_controllers);
|
||||
|
||||
controller_data_received = false;
|
||||
@@ -347,11 +327,9 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
/*---------------------------------------------------------*\
|
||||
| Wait until controller is received |
|
||||
\*---------------------------------------------------------*/
|
||||
while(controller_data_received == false)
|
||||
{
|
||||
while (controller_data_received == false) {
|
||||
connection_cv.wait_for(lock, 5ms);
|
||||
if(!client_active)
|
||||
{
|
||||
if (!client_active) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -365,8 +343,8 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
| All controllers received, add them to master list |
|
||||
\*---------------------------------------------------------*/
|
||||
printf("Client: All controllers received, adding them to master list\r\n");
|
||||
for(std::size_t controller_idx = 0; controller_idx < server_controllers.size(); controller_idx++)
|
||||
{
|
||||
for (std::size_t controller_idx = 0; controller_idx < server_controllers.size();
|
||||
controller_idx++) {
|
||||
controllers.push_back(server_controllers[controller_idx]);
|
||||
}
|
||||
|
||||
@@ -389,32 +367,25 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
|
||||
int NetworkClient::recv_select(SOCKET s, char *buf, int len, int flags)
|
||||
{
|
||||
fd_set set;
|
||||
struct timeval timeout;
|
||||
fd_set set;
|
||||
struct timeval timeout;
|
||||
|
||||
while(1)
|
||||
{
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
while (1) {
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&set);
|
||||
FD_SET(s, &set);
|
||||
|
||||
int rv = select((int)s + 1, &set, NULL, NULL, &timeout);
|
||||
int rv = select((int) s + 1, &set, NULL, NULL, &timeout);
|
||||
|
||||
if(rv == SOCKET_ERROR || server_connected == false)
|
||||
{
|
||||
if (rv == SOCKET_ERROR || server_connected == false) {
|
||||
return 0;
|
||||
}
|
||||
else if(rv == 0)
|
||||
{
|
||||
} else if (rv == 0) {
|
||||
continue;
|
||||
} else {
|
||||
return (recv(s, buf, len, flags));
|
||||
}
|
||||
else
|
||||
{
|
||||
return(recv(s, buf, len, flags));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,29 +396,25 @@ void NetworkClient::ListenThreadFunction()
|
||||
/*---------------------------------------------------------*\
|
||||
| This thread handles messages received from the server |
|
||||
\*---------------------------------------------------------*/
|
||||
while(server_connected == true)
|
||||
{
|
||||
while (server_connected == true) {
|
||||
NetPacketHeader header;
|
||||
int bytes_read = 0;
|
||||
char * data = NULL;
|
||||
int bytes_read = 0;
|
||||
char *data = NULL;
|
||||
|
||||
for(unsigned int i = 0; i < 4; i++)
|
||||
{
|
||||
for (unsigned int i = 0; i < 4; i++) {
|
||||
/*---------------------------------------------------------*\
|
||||
| Read byte of magic |
|
||||
\*---------------------------------------------------------*/
|
||||
bytes_read = recv_select(client_sock, &header.pkt_magic[i], 1, 0);
|
||||
|
||||
if(bytes_read <= 0)
|
||||
{
|
||||
if (bytes_read <= 0) {
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Test characters of magic "ORGB" |
|
||||
\*---------------------------------------------------------*/
|
||||
if(header.pkt_magic[i] != openrgb_sdk_magic[i])
|
||||
{
|
||||
if (header.pkt_magic[i] != openrgb_sdk_magic[i]) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -457,84 +424,82 @@ void NetworkClient::ListenThreadFunction()
|
||||
| rest of the header |
|
||||
\*---------------------------------------------------------*/
|
||||
bytes_read = 0;
|
||||
do
|
||||
{
|
||||
do {
|
||||
int tmp_bytes_read = 0;
|
||||
|
||||
tmp_bytes_read = recv_select(client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read, 0);
|
||||
tmp_bytes_read = recv_select(client_sock,
|
||||
(char *) &header.pkt_dev_idx + bytes_read,
|
||||
sizeof(header) - sizeof(header.pkt_magic) - bytes_read,
|
||||
0);
|
||||
|
||||
bytes_read += tmp_bytes_read;
|
||||
|
||||
if(tmp_bytes_read <= 0)
|
||||
{
|
||||
if (tmp_bytes_read <= 0) {
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
} while(bytes_read != sizeof(header) - sizeof(header.pkt_magic));
|
||||
} while (bytes_read != sizeof(header) - sizeof(header.pkt_magic));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Header received, now receive the data |
|
||||
\*---------------------------------------------------------*/
|
||||
if(header.pkt_size > 0)
|
||||
{
|
||||
if (header.pkt_size > 0) {
|
||||
bytes_read = 0;
|
||||
|
||||
data = new char[header.pkt_size];
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
int tmp_bytes_read = 0;
|
||||
|
||||
tmp_bytes_read = recv_select(client_sock, &data[(unsigned int)bytes_read], header.pkt_size - bytes_read, 0);
|
||||
tmp_bytes_read = recv_select(client_sock,
|
||||
&data[(unsigned int) bytes_read],
|
||||
header.pkt_size - bytes_read,
|
||||
0);
|
||||
|
||||
if(tmp_bytes_read <= 0)
|
||||
{
|
||||
if (tmp_bytes_read <= 0) {
|
||||
goto listen_done;
|
||||
}
|
||||
bytes_read += tmp_bytes_read;
|
||||
|
||||
} while ((unsigned int)bytes_read < header.pkt_size);
|
||||
} while ((unsigned int) bytes_read < header.pkt_size);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Entire request received, select functionality based on |
|
||||
| request ID |
|
||||
\*---------------------------------------------------------*/
|
||||
switch(header.pkt_id)
|
||||
{
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
|
||||
ProcessReply_ControllerCount(header.pkt_size, data);
|
||||
break;
|
||||
switch (header.pkt_id) {
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
|
||||
ProcessReply_ControllerCount(header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
ProcessReply_ControllerData(header.pkt_size, data, header.pkt_dev_idx);
|
||||
break;
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
ProcessReply_ControllerData(header.pkt_size, data, header.pkt_dev_idx);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_PROTOCOL_VERSION:
|
||||
ProcessReply_ProtocolVersion(header.pkt_size, data);
|
||||
break;
|
||||
case NET_PACKET_ID_REQUEST_PROTOCOL_VERSION:
|
||||
ProcessReply_ProtocolVersion(header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_DEVICE_LIST_UPDATED:
|
||||
ProcessRequest_DeviceListChanged();
|
||||
break;
|
||||
case NET_PACKET_ID_DEVICE_LIST_UPDATED:
|
||||
ProcessRequest_DeviceListChanged();
|
||||
break;
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
listen_done:
|
||||
printf( "Client socket has been closed");
|
||||
printf("Client socket has been closed");
|
||||
server_initialized = false;
|
||||
server_connected = false;
|
||||
|
||||
ControllerListMutex.lock();
|
||||
|
||||
for(size_t server_controller_idx = 0; server_controller_idx < server_controllers.size(); server_controller_idx++)
|
||||
{
|
||||
for(size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
|
||||
{
|
||||
if(controllers[controller_idx] == server_controllers[server_controller_idx])
|
||||
{
|
||||
for (size_t server_controller_idx = 0; server_controller_idx < server_controllers.size();
|
||||
server_controller_idx++) {
|
||||
for (size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++) {
|
||||
if (controllers[controller_idx] == server_controllers[server_controller_idx]) {
|
||||
controllers.erase(controllers.begin() + controller_idx);
|
||||
break;
|
||||
}
|
||||
@@ -545,8 +510,8 @@ listen_done:
|
||||
|
||||
server_controllers.clear();
|
||||
|
||||
for(size_t server_controller_idx = 0; server_controller_idx < server_controllers_copy.size(); server_controller_idx++)
|
||||
{
|
||||
for (size_t server_controller_idx = 0; server_controller_idx < server_controllers_copy.size();
|
||||
server_controller_idx++) {
|
||||
delete server_controllers_copy[server_controller_idx];
|
||||
}
|
||||
|
||||
@@ -560,10 +525,8 @@ listen_done:
|
||||
|
||||
void NetworkClient::WaitOnControllerData()
|
||||
{
|
||||
for(int i = 0; i < 1000; i++)
|
||||
{
|
||||
if(controller_data_received)
|
||||
{
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
if (controller_data_received) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(1ms);
|
||||
@@ -572,26 +535,26 @@ void NetworkClient::WaitOnControllerData()
|
||||
return;
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ControllerCount(unsigned int data_size, char * data)
|
||||
void NetworkClient::ProcessReply_ControllerCount(unsigned int data_size, char *data)
|
||||
{
|
||||
if(data_size == sizeof(unsigned int))
|
||||
{
|
||||
if (data_size == sizeof(unsigned int)) {
|
||||
memcpy(&server_controller_count, data, sizeof(unsigned int));
|
||||
server_controller_count_received = true;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx)
|
||||
void NetworkClient::ProcessReply_ControllerData(unsigned int data_size,
|
||||
char *data,
|
||||
unsigned int dev_idx)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Verify the controller description size (first 4 bytes of |
|
||||
| data) matches the packet size in the header |
|
||||
\*---------------------------------------------------------*/
|
||||
if(data_size == *((unsigned int*)data))
|
||||
{
|
||||
RGBController_Network * new_controller = new RGBController_Network(this, dev_idx);
|
||||
if (data_size == *((unsigned int *) data)) {
|
||||
RGBController_Network *new_controller = new RGBController_Network(this, dev_idx);
|
||||
|
||||
new_controller->ReadDeviceDescription((unsigned char *)data, GetProtocolVersion());
|
||||
new_controller->ReadDeviceDescription((unsigned char *) data, GetProtocolVersion());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mark this controller as remote owned |
|
||||
@@ -601,20 +564,17 @@ void NetworkClient::ProcessReply_ControllerData(unsigned int data_size, char * d
|
||||
|
||||
ControllerListMutex.lock();
|
||||
|
||||
if(dev_idx >= server_controllers.size())
|
||||
{
|
||||
if (dev_idx >= server_controllers.size()) {
|
||||
server_controllers.push_back(new_controller);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
server_controllers[dev_idx]->active_mode = new_controller->active_mode;
|
||||
server_controllers[dev_idx]->leds.clear();
|
||||
server_controllers[dev_idx]->leds = new_controller->leds;
|
||||
server_controllers[dev_idx]->leds = new_controller->leds;
|
||||
server_controllers[dev_idx]->colors.clear();
|
||||
server_controllers[dev_idx]->colors = new_controller->colors;
|
||||
for(unsigned int i = 0; i < server_controllers[dev_idx]->zones.size(); i++)
|
||||
{
|
||||
server_controllers[dev_idx]->zones[i].leds_count = new_controller->zones[i].leds_count;
|
||||
server_controllers[dev_idx]->colors = new_controller->colors;
|
||||
for (unsigned int i = 0; i < server_controllers[dev_idx]->zones.size(); i++) {
|
||||
server_controllers[dev_idx]->zones[i].leds_count = new_controller->zones[i]
|
||||
.leds_count;
|
||||
server_controllers[dev_idx]->zones[i].segments.clear();
|
||||
server_controllers[dev_idx]->zones[i].segments = new_controller->zones[i].segments;
|
||||
}
|
||||
@@ -629,10 +589,9 @@ void NetworkClient::ProcessReply_ControllerData(unsigned int data_size, char * d
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ProtocolVersion(unsigned int data_size, char * data)
|
||||
void NetworkClient::ProcessReply_ProtocolVersion(unsigned int data_size, char *data)
|
||||
{
|
||||
if(data_size == sizeof(unsigned int))
|
||||
{
|
||||
if (data_size == sizeof(unsigned int)) {
|
||||
memcpy(&server_protocol_version, data, sizeof(unsigned int));
|
||||
server_protocol_version_received = true;
|
||||
}
|
||||
@@ -644,12 +603,10 @@ void NetworkClient::ProcessRequest_DeviceListChanged()
|
||||
|
||||
ControllerListMutex.lock();
|
||||
|
||||
for(size_t server_controller_idx = 0; server_controller_idx < server_controllers.size(); server_controller_idx++)
|
||||
{
|
||||
for(size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++)
|
||||
{
|
||||
if(controllers[controller_idx] == server_controllers[server_controller_idx])
|
||||
{
|
||||
for (size_t server_controller_idx = 0; server_controller_idx < server_controllers.size();
|
||||
server_controller_idx++) {
|
||||
for (size_t controller_idx = 0; controller_idx < controllers.size(); controller_idx++) {
|
||||
if (controllers[controller_idx] == server_controllers[server_controller_idx]) {
|
||||
controllers.erase(controllers.begin() + controller_idx);
|
||||
break;
|
||||
}
|
||||
@@ -660,8 +617,8 @@ void NetworkClient::ProcessRequest_DeviceListChanged()
|
||||
|
||||
server_controllers.clear();
|
||||
|
||||
for(size_t server_controller_idx = 0; server_controller_idx < server_controllers_copy.size(); server_controller_idx++)
|
||||
{
|
||||
for (size_t server_controller_idx = 0; server_controller_idx < server_controllers_copy.size();
|
||||
server_controller_idx++) {
|
||||
delete server_controllers_copy[server_controller_idx];
|
||||
}
|
||||
|
||||
@@ -684,11 +641,14 @@ void NetworkClient::SendData_ClientString()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_SET_CLIENT_NAME, (unsigned int)strlen(client_name.c_str()) + 1);
|
||||
InitNetPacketHeader(&reply_hdr,
|
||||
0,
|
||||
NET_PACKET_ID_SET_CLIENT_NAME,
|
||||
(unsigned int) strlen(client_name.c_str()) + 1);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)client_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) client_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
@@ -699,50 +659,44 @@ void NetworkClient::SendRequest_ControllerCount()
|
||||
InitNetPacketHeader(&request_hdr, 0, NET_PACKET_ID_REQUEST_CONTROLLER_COUNT, 0);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
|
||||
{
|
||||
NetPacketHeader request_hdr;
|
||||
unsigned int protocol_version;
|
||||
unsigned int protocol_version;
|
||||
|
||||
controller_data_received = false;
|
||||
|
||||
memcpy(request_hdr.pkt_magic, openrgb_sdk_magic, sizeof(openrgb_sdk_magic));
|
||||
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
|
||||
if(server_protocol_version == 0)
|
||||
{
|
||||
request_hdr.pkt_size = 0;
|
||||
if (server_protocol_version == 0) {
|
||||
request_hdr.pkt_size = 0;
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
request_hdr.pkt_size = sizeof(unsigned int);
|
||||
} else {
|
||||
request_hdr.pkt_size = sizeof(unsigned int);
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| Limit the protocol version to the highest supported by both |
|
||||
| the client and the server. |
|
||||
\*-------------------------------------------------------------*/
|
||||
if(server_protocol_version > OPENRGB_SDK_PROTOCOL_VERSION)
|
||||
{
|
||||
if (server_protocol_version > OPENRGB_SDK_PROTOCOL_VERSION) {
|
||||
protocol_version = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
protocol_version = server_protocol_version;
|
||||
}
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&protocol_version, sizeof(unsigned int), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &protocol_version, sizeof(unsigned int), MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
}
|
||||
@@ -750,40 +704,46 @@ void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
|
||||
void NetworkClient::SendRequest_ProtocolVersion()
|
||||
{
|
||||
NetPacketHeader request_hdr;
|
||||
unsigned int request_data;
|
||||
unsigned int request_data;
|
||||
|
||||
InitNetPacketHeader(&request_hdr, 0, NET_PACKET_ID_REQUEST_PROTOCOL_VERSION, sizeof(unsigned int));
|
||||
InitNetPacketHeader(&request_hdr,
|
||||
0,
|
||||
NET_PACKET_ID_REQUEST_PROTOCOL_VERSION,
|
||||
sizeof(unsigned int));
|
||||
|
||||
request_data = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
request_data = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_data, sizeof(unsigned int), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_data, sizeof(unsigned int), MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_ClearSegments(unsigned int dev_idx, int zone)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader request_hdr;
|
||||
int request_data[1];
|
||||
int request_data[1];
|
||||
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS, sizeof(request_data));
|
||||
InitNetPacketHeader(&request_hdr,
|
||||
dev_idx,
|
||||
NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS,
|
||||
sizeof(request_data));
|
||||
|
||||
request_data[0] = zone;
|
||||
request_data[0] = zone;
|
||||
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_data, sizeof(request_data), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_data, sizeof(request_data), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_AddSegment(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
void NetworkClient::SendRequest_RGBController_AddSegment(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -791,35 +751,40 @@ void NetworkClient::SendRequest_RGBController_AddSegment(unsigned int dev_idx, u
|
||||
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT, size);
|
||||
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, 0);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) data, size, 0);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size)
|
||||
void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx,
|
||||
int zone,
|
||||
int new_size)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader request_hdr;
|
||||
int request_data[2];
|
||||
int request_data[2];
|
||||
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE, sizeof(request_data));
|
||||
InitNetPacketHeader(&request_hdr,
|
||||
dev_idx,
|
||||
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE,
|
||||
sizeof(request_data));
|
||||
|
||||
request_data[0] = zone;
|
||||
request_data[1] = new_size;
|
||||
request_data[0] = zone;
|
||||
request_data[1] = new_size;
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_data, sizeof(request_data), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_data, sizeof(request_data), MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -828,15 +793,16 @@ void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, u
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS, size);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, 0);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) data, size, 0);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -845,15 +811,16 @@ void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_id
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS, size);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) data, size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -862,15 +829,14 @@ void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_i
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED, size);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) data, size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_SetCustomMode(unsigned int dev_idx)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -879,14 +845,15 @@ void NetworkClient::SendRequest_RGBController_SetCustomMode(unsigned int dev_idx
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE, 0);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -895,15 +862,16 @@ void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, u
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE, size);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) data, size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
void NetworkClient::SendRequest_RGBController_SaveMode(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size)
|
||||
{
|
||||
if(change_in_progress)
|
||||
{
|
||||
if (change_in_progress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -912,8 +880,8 @@ void NetworkClient::SendRequest_RGBController_SaveMode(unsigned int dev_idx, uns
|
||||
InitNetPacketHeader(&request_hdr, dev_idx, NET_PACKET_ID_RGBCONTROLLER_SAVEMODE, size);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) data, size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
@@ -921,11 +889,14 @@ void NetworkClient::SendRequest_LoadProfile(std::string profile_name)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_REQUEST_LOAD_PROFILE, (unsigned int)strlen(profile_name.c_str()) + 1);
|
||||
InitNetPacketHeader(&reply_hdr,
|
||||
0,
|
||||
NET_PACKET_ID_REQUEST_LOAD_PROFILE,
|
||||
(unsigned int) strlen(profile_name.c_str()) + 1);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)profile_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) profile_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
@@ -933,11 +904,14 @@ void NetworkClient::SendRequest_SaveProfile(std::string profile_name)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_REQUEST_SAVE_PROFILE, (unsigned int)strlen(profile_name.c_str()) + 1);
|
||||
InitNetPacketHeader(&reply_hdr,
|
||||
0,
|
||||
NET_PACKET_ID_REQUEST_SAVE_PROFILE,
|
||||
(unsigned int) strlen(profile_name.c_str()) + 1);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)profile_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) profile_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
@@ -945,11 +919,14 @@ void NetworkClient::SendRequest_DeleteProfile(std::string profile_name)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_REQUEST_DELETE_PROFILE, (unsigned int)strlen(profile_name.c_str()) + 1);
|
||||
InitNetPacketHeader(&reply_hdr,
|
||||
0,
|
||||
NET_PACKET_ID_REQUEST_DELETE_PROFILE,
|
||||
(unsigned int) strlen(profile_name.c_str()) + 1);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)profile_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) profile_name.c_str(), reply_hdr.pkt_size, MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
@@ -960,16 +937,15 @@ void NetworkClient::SendRequest_GetProfileList()
|
||||
InitNetPacketHeader(&reply_hdr, 0, NET_PACKET_ID_REQUEST_PROFILE_LIST, 0);
|
||||
|
||||
send_in_progress.lock();
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *) &reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send_in_progress.unlock();
|
||||
}
|
||||
|
||||
std::vector<std::string> * NetworkClient::ProcessReply_ProfileList(unsigned int data_size, char * data)
|
||||
std::vector<std::string> *NetworkClient::ProcessReply_ProfileList(unsigned int data_size, char *data)
|
||||
{
|
||||
std::vector<std::string> * profile_list;
|
||||
std::vector<std::string> *profile_list;
|
||||
|
||||
if(data_size > 0)
|
||||
{
|
||||
if (data_size > 0) {
|
||||
profile_list = new std::vector<std::string>(data_size);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -981,8 +957,7 @@ std::vector<std::string> * NetworkClient::ProcessReply_ProfileList(unsigned int
|
||||
memcpy(&num_profile, data, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
for(int i = 0; i < num_profile; i++)
|
||||
{
|
||||
for (int i = 0; i < num_profile; i++) {
|
||||
unsigned short name_len;
|
||||
|
||||
memcpy(&name_len, data, sizeof(unsigned short));
|
||||
@@ -995,9 +970,7 @@ std::vector<std::string> * NetworkClient::ProcessReply_ProfileList(unsigned int
|
||||
}
|
||||
|
||||
server_controller_count_received = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
profile_list = new std::vector<std::string>(0);
|
||||
}
|
||||
|
||||
|
||||
138
NetworkClient.h
138
NetworkClient.h
@@ -23,99 +23,109 @@ typedef void (*NetClientCallback)(void *);
|
||||
class NetworkClient
|
||||
{
|
||||
public:
|
||||
NetworkClient(std::vector<RGBController *>& control);
|
||||
NetworkClient(std::vector<RGBController *> &control);
|
||||
~NetworkClient();
|
||||
|
||||
void ClientInfoChanged();
|
||||
void ClientInfoChanged();
|
||||
|
||||
bool GetConnected();
|
||||
std::string GetIP();
|
||||
unsigned short GetPort();
|
||||
unsigned int GetProtocolVersion();
|
||||
bool GetOnline();
|
||||
bool GetConnected();
|
||||
std::string GetIP();
|
||||
unsigned short GetPort();
|
||||
unsigned int GetProtocolVersion();
|
||||
bool GetOnline();
|
||||
|
||||
void ClearCallbacks();
|
||||
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
|
||||
void ClearCallbacks();
|
||||
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void *new_callback_arg);
|
||||
|
||||
void SetIP(std::string new_ip);
|
||||
void SetName(std::string new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
void SetIP(std::string new_ip);
|
||||
void SetName(std::string new_name);
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
void StartClient();
|
||||
void StopClient();
|
||||
void StartClient();
|
||||
void StopClient();
|
||||
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction();
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction();
|
||||
|
||||
void WaitOnControllerData();
|
||||
void WaitOnControllerData();
|
||||
|
||||
void ProcessReply_ControllerCount(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx);
|
||||
void ProcessReply_ProtocolVersion(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerCount(unsigned int data_size, char *data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char *data, unsigned int dev_idx);
|
||||
void ProcessReply_ProtocolVersion(unsigned int data_size, char *data);
|
||||
|
||||
void ProcessRequest_DeviceListChanged();
|
||||
void ProcessRequest_DeviceListChanged();
|
||||
|
||||
void SendData_ClientString();
|
||||
void SendData_ClientString();
|
||||
|
||||
void SendRequest_ControllerCount();
|
||||
void SendRequest_ControllerData(unsigned int dev_idx);
|
||||
void SendRequest_ProtocolVersion();
|
||||
void SendRequest_ControllerCount();
|
||||
void SendRequest_ControllerData(unsigned int dev_idx);
|
||||
void SendRequest_ProtocolVersion();
|
||||
|
||||
void SendRequest_RGBController_ClearSegments(unsigned int dev_idx, int zone);
|
||||
void SendRequest_RGBController_AddSegment(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
void SendRequest_RGBController_ClearSegments(unsigned int dev_idx, int zone);
|
||||
void SendRequest_RGBController_AddSegment(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size);
|
||||
void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size);
|
||||
|
||||
void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
|
||||
void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
|
||||
|
||||
void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateMode(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size);
|
||||
void SendRequest_RGBController_SaveMode(unsigned int dev_idx,
|
||||
unsigned char *data,
|
||||
unsigned int size);
|
||||
|
||||
std::vector<std::string> *ProcessReply_ProfileList(unsigned int data_size, char *data);
|
||||
|
||||
std::vector<std::string> * ProcessReply_ProfileList(unsigned int data_size, char * data);
|
||||
void SendRequest_GetProfileList();
|
||||
void SendRequest_LoadProfile(std::string profile_name);
|
||||
void SendRequest_SaveProfile(std::string profile_name);
|
||||
void SendRequest_DeleteProfile(std::string profile_name);
|
||||
|
||||
void SendRequest_GetProfileList();
|
||||
void SendRequest_LoadProfile(std::string profile_name);
|
||||
void SendRequest_SaveProfile(std::string profile_name);
|
||||
void SendRequest_DeleteProfile(std::string profile_name);
|
||||
std::vector<RGBController *> server_controllers;
|
||||
|
||||
std::vector<RGBController *> server_controllers;
|
||||
|
||||
std::mutex ControllerListMutex;
|
||||
std::mutex ControllerListMutex;
|
||||
|
||||
protected:
|
||||
std::vector<RGBController *>& controllers;
|
||||
|
||||
std::vector<RGBController *> &controllers;
|
||||
|
||||
private:
|
||||
SOCKET client_sock;
|
||||
std::string client_name;
|
||||
net_port port;
|
||||
std::string port_ip;
|
||||
unsigned short port_num;
|
||||
SOCKET client_sock;
|
||||
std::string client_name;
|
||||
net_port port;
|
||||
std::string port_ip;
|
||||
unsigned short port_num;
|
||||
std::atomic<bool> client_active;
|
||||
bool controller_data_received;
|
||||
bool server_connected;
|
||||
bool server_initialized;
|
||||
unsigned int server_controller_count;
|
||||
bool server_controller_count_received;
|
||||
unsigned int server_protocol_version;
|
||||
bool server_protocol_version_received;
|
||||
bool change_in_progress;
|
||||
std::mutex send_in_progress;
|
||||
bool controller_data_received;
|
||||
bool server_connected;
|
||||
bool server_initialized;
|
||||
unsigned int server_controller_count;
|
||||
bool server_controller_count_received;
|
||||
unsigned int server_protocol_version;
|
||||
bool server_protocol_version_received;
|
||||
bool change_in_progress;
|
||||
std::mutex send_in_progress;
|
||||
|
||||
std::mutex connection_mutex;
|
||||
std::mutex connection_mutex;
|
||||
std::condition_variable connection_cv;
|
||||
|
||||
std::thread * ConnectionThread;
|
||||
std::thread * ListenThread;
|
||||
std::thread *ConnectionThread;
|
||||
std::thread *ListenThread;
|
||||
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetClientCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetClientCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
};
|
||||
|
||||
@@ -15,19 +15,16 @@
|
||||
/*-----------------------------------------------------*\
|
||||
| OpenRGB SDK Magic Value "ORGB" |
|
||||
\*-----------------------------------------------------*/
|
||||
const char openrgb_sdk_magic[OPENRGB_SDK_MAGIC_SIZE] = { 'O', 'R', 'G', 'B' };
|
||||
const char openrgb_sdk_magic[OPENRGB_SDK_MAGIC_SIZE] = {'O', 'R', 'G', 'B'};
|
||||
|
||||
void InitNetPacketHeader
|
||||
(
|
||||
NetPacketHeader * pkt_hdr,
|
||||
unsigned int pkt_dev_idx,
|
||||
unsigned int pkt_id,
|
||||
unsigned int pkt_size
|
||||
)
|
||||
void InitNetPacketHeader(NetPacketHeader *pkt_hdr,
|
||||
unsigned int pkt_dev_idx,
|
||||
unsigned int pkt_id,
|
||||
unsigned int pkt_size)
|
||||
{
|
||||
memcpy(pkt_hdr->pkt_magic, openrgb_sdk_magic, sizeof(openrgb_sdk_magic));
|
||||
|
||||
pkt_hdr->pkt_dev_idx = pkt_dev_idx;
|
||||
pkt_hdr->pkt_id = pkt_id;
|
||||
pkt_hdr->pkt_size = pkt_size;
|
||||
pkt_hdr->pkt_dev_idx = pkt_dev_idx;
|
||||
pkt_hdr->pkt_id = pkt_id;
|
||||
pkt_hdr->pkt_size = pkt_size;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
| 5: Zone flags, controller flags, resizable effects-only zones |
|
||||
(Release 1.0) |
|
||||
\*---------------------------------------------------------------------*/
|
||||
#define OPENRGB_SDK_PROTOCOL_VERSION 5
|
||||
#define OPENRGB_SDK_PROTOCOL_VERSION 5
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Default Interface to bind to. |
|
||||
@@ -43,54 +43,63 @@ extern const char openrgb_sdk_magic[OPENRGB_SDK_MAGIC_SIZE];
|
||||
|
||||
typedef struct NetPacketHeader
|
||||
{
|
||||
char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
|
||||
unsigned int pkt_dev_idx; /* Device index */
|
||||
unsigned int pkt_id; /* Packet ID */
|
||||
unsigned int pkt_size; /* Packet size */
|
||||
char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
|
||||
unsigned int pkt_dev_idx; /* Device index */
|
||||
unsigned int pkt_id; /* Packet ID */
|
||||
unsigned int pkt_size; /* Packet size */
|
||||
} NetPacketHeader;
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| Network requests |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_COUNT
|
||||
= 0, /* Request RGBController device count from server */
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_DATA
|
||||
= 1, /* Request RGBController data block */
|
||||
|
||||
NET_PACKET_ID_REQUEST_PROTOCOL_VERSION = 40, /* Request OpenRGB SDK protocol version from server */
|
||||
NET_PACKET_ID_REQUEST_PROTOCOL_VERSION
|
||||
= 40, /* Request OpenRGB SDK protocol version from server */
|
||||
|
||||
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
|
||||
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
|
||||
|
||||
NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */
|
||||
NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */
|
||||
|
||||
NET_PACKET_ID_REQUEST_PROFILE_LIST = 150, /* Request profile list */
|
||||
NET_PACKET_ID_REQUEST_SAVE_PROFILE = 151, /* Save current configuration in a new profile */
|
||||
NET_PACKET_ID_REQUEST_LOAD_PROFILE = 152, /* Load a given profile */
|
||||
NET_PACKET_ID_REQUEST_DELETE_PROFILE = 153, /* Delete a given profile */
|
||||
NET_PACKET_ID_REQUEST_PROFILE_LIST = 150, /* Request profile list */
|
||||
NET_PACKET_ID_REQUEST_SAVE_PROFILE = 151, /* Save current configuration in a new profile */
|
||||
NET_PACKET_ID_REQUEST_LOAD_PROFILE = 152, /* Load a given profile */
|
||||
NET_PACKET_ID_REQUEST_DELETE_PROFILE
|
||||
= 153, /* Delete a given profile */
|
||||
|
||||
NET_PACKET_ID_REQUEST_PLUGIN_LIST = 200, /* Request list of plugins */
|
||||
NET_PACKET_ID_PLUGIN_SPECIFIC = 201, /* Interact with a plugin */
|
||||
NET_PACKET_ID_REQUEST_PLUGIN_LIST = 200, /* Request list of plugins */
|
||||
NET_PACKET_ID_PLUGIN_SPECIFIC = 201, /* Interact with a plugin */
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
| RGBController class functions |
|
||||
\*----------------------------------------------------------------------------------------------------------*/
|
||||
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS = 1001, /* RGBController::ClearSegments() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT = 1002, /* RGBController::AddSegment() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE
|
||||
= 1000, /* RGBController::ResizeZone() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_CLEARSEGMENTS
|
||||
= 1001, /* RGBController::ClearSegments() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_ADDSEGMENT
|
||||
= 1002, /* RGBController::AddSegment() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS
|
||||
= 1050, /* RGBController::UpdateLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS
|
||||
= 1051, /* RGBController::UpdateZoneLEDs() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED
|
||||
= 1052, /* RGBController::UpdateSingleLED() */
|
||||
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_SAVEMODE = 1102, /* RGBController::SaveMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE
|
||||
= 1100, /* RGBController::SetCustomMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE
|
||||
= 1101, /* RGBController::UpdateMode() */
|
||||
NET_PACKET_ID_RGBCONTROLLER_SAVEMODE
|
||||
= 1102, /* RGBController::SaveMode() */
|
||||
};
|
||||
|
||||
void InitNetPacketHeader
|
||||
(
|
||||
NetPacketHeader * pkt_hdr,
|
||||
unsigned int pkt_dev_idx,
|
||||
unsigned int pkt_id,
|
||||
unsigned int pkt_size
|
||||
);
|
||||
void InitNetPacketHeader(NetPacketHeader *pkt_hdr,
|
||||
unsigned int pkt_dev_idx,
|
||||
unsigned int pkt_id,
|
||||
unsigned int pkt_size);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
131
NetworkServer.h
131
NetworkServer.h
@@ -23,7 +23,7 @@
|
||||
#define TCP_TIMEOUT_SECONDS 5
|
||||
|
||||
typedef void (*NetServerCallback)(void *);
|
||||
typedef unsigned char* (*NetPluginCallback)(void *, unsigned int, unsigned char*, unsigned int*);
|
||||
typedef unsigned char *(*NetPluginCallback)(void *, unsigned int, unsigned char *, unsigned int *);
|
||||
|
||||
struct NetworkPlugin
|
||||
{
|
||||
@@ -31,7 +31,7 @@ struct NetworkPlugin
|
||||
std::string description;
|
||||
std::string version;
|
||||
NetPluginCallback callback;
|
||||
void* callback_arg;
|
||||
void *callback_arg;
|
||||
unsigned int protocol_version;
|
||||
};
|
||||
|
||||
@@ -41,95 +41,102 @@ public:
|
||||
NetworkClientInfo();
|
||||
~NetworkClientInfo();
|
||||
|
||||
SOCKET client_sock;
|
||||
std::thread * client_listen_thread;
|
||||
std::string client_string;
|
||||
unsigned int client_protocol_version;
|
||||
std::string client_ip;
|
||||
SOCKET client_sock;
|
||||
std::thread *client_listen_thread;
|
||||
std::string client_string;
|
||||
unsigned int client_protocol_version;
|
||||
std::string client_ip;
|
||||
};
|
||||
|
||||
class NetworkServer
|
||||
{
|
||||
public:
|
||||
NetworkServer(std::vector<RGBController *>& control);
|
||||
NetworkServer(std::vector<RGBController *> &control);
|
||||
~NetworkServer();
|
||||
|
||||
std::string GetHost();
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
bool GetListening();
|
||||
unsigned int GetNumClients();
|
||||
const char * GetClientString(unsigned int client_num);
|
||||
const char * GetClientIP(unsigned int client_num);
|
||||
unsigned int GetClientProtocolVersion(unsigned int client_num);
|
||||
std::string GetHost();
|
||||
unsigned short GetPort();
|
||||
bool GetOnline();
|
||||
bool GetListening();
|
||||
unsigned int GetNumClients();
|
||||
const char *GetClientString(unsigned int client_num);
|
||||
const char *GetClientIP(unsigned int client_num);
|
||||
unsigned int GetClientProtocolVersion(unsigned int client_num);
|
||||
|
||||
void ClientInfoChanged();
|
||||
void DeviceListChanged();
|
||||
void RegisterClientInfoChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
void ClientInfoChanged();
|
||||
void DeviceListChanged();
|
||||
void RegisterClientInfoChangeCallback(NetServerCallback, void *new_callback_arg);
|
||||
|
||||
void ServerListeningChanged();
|
||||
void RegisterServerListeningChangeCallback(NetServerCallback, void * new_callback_arg);
|
||||
void ServerListeningChanged();
|
||||
void RegisterServerListeningChangeCallback(NetServerCallback, void *new_callback_arg);
|
||||
|
||||
void SetHost(std::string host);
|
||||
void SetLegacyWorkaroundEnable(bool enable);
|
||||
void SetPort(unsigned short new_port);
|
||||
void SetHost(std::string host);
|
||||
void SetLegacyWorkaroundEnable(bool enable);
|
||||
void SetPort(unsigned short new_port);
|
||||
|
||||
void StartServer();
|
||||
void StopServer();
|
||||
void StartServer();
|
||||
void StopServer();
|
||||
|
||||
void ConnectionThreadFunction(int socket_idx);
|
||||
void ListenThreadFunction(NetworkClientInfo * client_sock);
|
||||
void ConnectionThreadFunction(int socket_idx);
|
||||
void ListenThreadFunction(NetworkClientInfo *client_sock);
|
||||
|
||||
void ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data);
|
||||
void ProcessRequest_ClientProtocolVersion(SOCKET client_sock,
|
||||
unsigned int data_size,
|
||||
char *data);
|
||||
void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char *data);
|
||||
|
||||
void SendReply_ControllerCount(SOCKET client_sock);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx, unsigned int protocol_version);
|
||||
void SendReply_ProtocolVersion(SOCKET client_sock);
|
||||
void SendReply_ControllerCount(SOCKET client_sock);
|
||||
void SendReply_ControllerData(SOCKET client_sock,
|
||||
unsigned int dev_idx,
|
||||
unsigned int protocol_version);
|
||||
void SendReply_ProtocolVersion(SOCKET client_sock);
|
||||
|
||||
void SendRequest_DeviceListChanged(SOCKET client_sock);
|
||||
void SendReply_ProfileList(SOCKET client_sock);
|
||||
void SendReply_PluginList(SOCKET client_sock);
|
||||
void SendReply_PluginSpecific(SOCKET client_sock, unsigned int pkt_type, unsigned char* data, unsigned int data_size);
|
||||
void SendRequest_DeviceListChanged(SOCKET client_sock);
|
||||
void SendReply_ProfileList(SOCKET client_sock);
|
||||
void SendReply_PluginList(SOCKET client_sock);
|
||||
void SendReply_PluginSpecific(SOCKET client_sock,
|
||||
unsigned int pkt_type,
|
||||
unsigned char *data,
|
||||
unsigned int data_size);
|
||||
|
||||
void SetProfileManager(ProfileManagerInterface* profile_manager_pointer);
|
||||
void SetProfileManager(ProfileManagerInterface *profile_manager_pointer);
|
||||
|
||||
void RegisterPlugin(NetworkPlugin plugin);
|
||||
void UnregisterPlugin(std::string plugin_name);
|
||||
void RegisterPlugin(NetworkPlugin plugin);
|
||||
void UnregisterPlugin(std::string plugin_name);
|
||||
|
||||
protected:
|
||||
std::string host;
|
||||
unsigned short port_num;
|
||||
std::atomic<bool> server_online;
|
||||
std::atomic<bool> server_listening;
|
||||
std::string host;
|
||||
unsigned short port_num;
|
||||
std::atomic<bool> server_online;
|
||||
std::atomic<bool> server_listening;
|
||||
|
||||
std::vector<RGBController *>& controllers;
|
||||
std::vector<RGBController *> &controllers;
|
||||
|
||||
std::mutex ServerClientsMutex;
|
||||
std::vector<NetworkClientInfo *> ServerClients;
|
||||
std::thread * ConnectionThread[MAXSOCK];
|
||||
std::mutex ServerClientsMutex;
|
||||
std::vector<NetworkClientInfo *> ServerClients;
|
||||
std::thread *ConnectionThread[MAXSOCK];
|
||||
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
std::mutex ClientInfoChangeMutex;
|
||||
std::vector<NetServerCallback> ClientInfoChangeCallbacks;
|
||||
std::vector<void *> ClientInfoChangeCallbackArgs;
|
||||
|
||||
std::mutex ServerListeningChangeMutex;
|
||||
std::vector<NetServerCallback> ServerListeningChangeCallbacks;
|
||||
std::vector<void *> ServerListeningChangeCallbackArgs;
|
||||
std::mutex ServerListeningChangeMutex;
|
||||
std::vector<NetServerCallback> ServerListeningChangeCallbacks;
|
||||
std::vector<void *> ServerListeningChangeCallbackArgs;
|
||||
|
||||
ProfileManagerInterface* profile_manager;
|
||||
ProfileManagerInterface *profile_manager;
|
||||
|
||||
std::vector<NetworkPlugin> plugins;
|
||||
std::vector<NetworkPlugin> plugins;
|
||||
|
||||
private:
|
||||
#ifdef WIN32
|
||||
WSADATA wsa;
|
||||
WSADATA wsa;
|
||||
#endif
|
||||
|
||||
bool legacy_workaround_enabled;
|
||||
int socket_count;
|
||||
SOCKET server_sock[MAXSOCK];
|
||||
bool legacy_workaround_enabled;
|
||||
int socket_count;
|
||||
SOCKET server_sock[MAXSOCK];
|
||||
|
||||
int accept_select(int sockfd);
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
int accept_select(int sockfd);
|
||||
int recv_select(SOCKET s, char *buf, int len, int flags);
|
||||
};
|
||||
|
||||
@@ -170,6 +170,8 @@ HEADERS +=
|
||||
$$GUI_H \
|
||||
$$CONTROLLER_H \
|
||||
Colors.h \
|
||||
Controllers/MachenikeG5ProController/MachenikeG5ProController.h \
|
||||
Controllers/MachenikeG5ProController/RGBController_MachenikeG5Pro.h \
|
||||
dependencies/ColorWheel/ColorWheel.h \
|
||||
dependencies/json/nlohmann/json.hpp \
|
||||
LogManager.h \
|
||||
@@ -210,6 +212,9 @@ HEADERS +=
|
||||
SOURCES += \
|
||||
$$GUI_CPP \
|
||||
$$CONTROLLER_CPP \
|
||||
Controllers/MachenikeG5ProController/MachenikeG5ProController.cpp \
|
||||
Controllers/MachenikeG5ProController/MachenikeG5ProControllerDetect.cpp \
|
||||
Controllers/MachenikeG5ProController/RGBController_MachenikeG5Pro.cpp \
|
||||
dependencies/ColorWheel/ColorWheel.cpp \
|
||||
dependencies/hueplusplus-1.2.0/src/Action.cpp \
|
||||
dependencies/hueplusplus-1.2.0/src/APICache.cpp \
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <QMenu>
|
||||
#include "ResourceManagerInterface.h"
|
||||
|
||||
#define OpenRGBPluginInterface_IID "com.OpenRGBPluginInterface"
|
||||
#define OpenRGBPluginInterface_IID "com.OpenRGBPluginInterface"
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| OpenRGB Plugin API Versions |
|
||||
@@ -27,17 +27,16 @@
|
||||
| 3: OpenRGB 0.9 Use filesystem::path for paths, Added segments |
|
||||
| 4: OpenRGB 1.0 Resizable effects-only zones, zone flags |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
#define OPENRGB_PLUGIN_API_VERSION 4
|
||||
#define OPENRGB_PLUGIN_API_VERSION 4
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Plugin Tab Location Values |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
enum
|
||||
{
|
||||
OPENRGB_PLUGIN_LOCATION_TOP = 0, /* Top-level tab (no icon) */
|
||||
OPENRGB_PLUGIN_LOCATION_DEVICES = 1, /* Devices tab */
|
||||
OPENRGB_PLUGIN_LOCATION_INFORMATION = 2, /* Information tab */
|
||||
OPENRGB_PLUGIN_LOCATION_SETTINGS = 3, /* Settings tab */
|
||||
enum {
|
||||
OPENRGB_PLUGIN_LOCATION_TOP = 0, /* Top-level tab (no icon) */
|
||||
OPENRGB_PLUGIN_LOCATION_DEVICES = 1, /* Devices tab */
|
||||
OPENRGB_PLUGIN_LOCATION_INFORMATION = 2, /* Information tab */
|
||||
OPENRGB_PLUGIN_LOCATION_SETTINGS = 3, /* Settings tab */
|
||||
};
|
||||
|
||||
struct OpenRGBPluginInfo
|
||||
@@ -45,42 +44,42 @@ struct OpenRGBPluginInfo
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Plugin Details |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
std::string Name; /* Plugin name string */
|
||||
std::string Description; /* Plugin description string */
|
||||
std::string Version; /* Plugin version string */
|
||||
std::string Commit; /* Plugin commit (git or otherwise) string */
|
||||
std::string URL; /* Plugin project URL string */
|
||||
QImage Icon; /* Icon image (displayed 64x64) */
|
||||
std::string Name; /* Plugin name string */
|
||||
std::string Description; /* Plugin description string */
|
||||
std::string Version; /* Plugin version string */
|
||||
std::string Commit; /* Plugin commit (git or otherwise) string */
|
||||
std::string URL; /* Plugin project URL string */
|
||||
QImage Icon; /* Icon image (displayed 64x64) */
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Plugin Tab Configuration |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
unsigned int Location; /* Plugin tab location from Plugin Tab Location enum */
|
||||
/* This field is mandatory, an invalid value will */
|
||||
/* prevent plugin tab from being displayed */
|
||||
std::string Label; /* Plugin tab label string */
|
||||
std::string TabIconString; /* Plugin tab icon string, leave empty to use custom */
|
||||
QImage TabIcon; /* Custom tab icon image (displayed 16x16) */
|
||||
unsigned int Location; /* Plugin tab location from Plugin Tab Location enum */
|
||||
/* This field is mandatory, an invalid value will */
|
||||
/* prevent plugin tab from being displayed */
|
||||
std::string Label; /* Plugin tab label string */
|
||||
std::string TabIconString; /* Plugin tab icon string, leave empty to use custom */
|
||||
QImage TabIcon; /* Custom tab icon image (displayed 16x16) */
|
||||
};
|
||||
|
||||
class OpenRGBPluginInterface
|
||||
{
|
||||
public:
|
||||
virtual ~OpenRGBPluginInterface() {}
|
||||
virtual ~OpenRGBPluginInterface() {}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Plugin Information |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
virtual OpenRGBPluginInfo GetPluginInfo() = 0;
|
||||
virtual unsigned int GetPluginAPIVersion() = 0;
|
||||
virtual OpenRGBPluginInfo GetPluginInfo() = 0;
|
||||
virtual unsigned int GetPluginAPIVersion() = 0;
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Plugin Functionality |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
virtual void Load(ResourceManagerInterface* resource_manager_ptr) = 0;
|
||||
virtual QWidget* GetWidget() = 0;
|
||||
virtual QMenu* GetTrayMenu() = 0;
|
||||
virtual void Unload() = 0;
|
||||
virtual void Load(ResourceManagerInterface *resource_manager_ptr) = 0;
|
||||
virtual QWidget *GetWidget() = 0;
|
||||
virtual QMenu *GetTrayMenu() = 0;
|
||||
virtual void Unload() = 0;
|
||||
};
|
||||
|
||||
Q_DECLARE_INTERFACE(OpenRGBPluginInterface, OpenRGBPluginInterface_IID)
|
||||
|
||||
@@ -23,26 +23,28 @@ PluginManager::PluginManager()
|
||||
/*---------------------------------------------------------*\
|
||||
| Initialize plugin manager class variables |
|
||||
\*---------------------------------------------------------*/
|
||||
AddPluginCallbackVal = nullptr;
|
||||
AddPluginCallbackArg = nullptr;
|
||||
AddPluginCallbackVal = nullptr;
|
||||
AddPluginCallbackArg = nullptr;
|
||||
RemovePluginCallbackVal = nullptr;
|
||||
RemovePluginCallbackArg = nullptr;
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
| Create OpenRGB plugins directory |
|
||||
\*-------------------------------------------------------------------------*/
|
||||
filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory() / plugins_path;
|
||||
filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory()
|
||||
/ plugins_path;
|
||||
|
||||
filesystem::create_directories(plugins_dir);
|
||||
}
|
||||
|
||||
void PluginManager::RegisterAddPluginCallback(AddPluginCallback new_callback, void * new_callback_arg)
|
||||
void PluginManager::RegisterAddPluginCallback(AddPluginCallback new_callback, void *new_callback_arg)
|
||||
{
|
||||
AddPluginCallbackVal = new_callback;
|
||||
AddPluginCallbackArg = new_callback_arg;
|
||||
AddPluginCallbackVal = new_callback;
|
||||
AddPluginCallbackArg = new_callback_arg;
|
||||
}
|
||||
|
||||
void PluginManager::RegisterRemovePluginCallback(RemovePluginCallback new_callback, void * new_callback_arg)
|
||||
void PluginManager::RegisterRemovePluginCallback(RemovePluginCallback new_callback,
|
||||
void *new_callback_arg)
|
||||
{
|
||||
RemovePluginCallbackVal = new_callback;
|
||||
RemovePluginCallbackArg = new_callback_arg;
|
||||
@@ -56,7 +58,8 @@ void PluginManager::ScanAndLoadPlugins()
|
||||
| The user plugins directory is a directory named "plugins" |
|
||||
| in the configuration directory |
|
||||
\*---------------------------------------------------------*/
|
||||
filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory() / plugins_path;
|
||||
filesystem::path plugins_dir = ResourceManager::get()->GetConfigurationDirectory()
|
||||
/ plugins_path;
|
||||
ScanAndLoadPluginsFrom(plugins_dir, false);
|
||||
|
||||
#ifdef OPENRGB_SYSTEM_PLUGIN_DIRECTORY
|
||||
@@ -89,19 +92,17 @@ void PluginManager::ScanAndLoadPlugins()
|
||||
#endif
|
||||
}
|
||||
|
||||
void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir, bool is_system)
|
||||
void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path &plugins_dir, bool is_system)
|
||||
{
|
||||
if(is_system)
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Scanning system plugin directory: %s", plugins_dir.generic_u8string().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Scanning user plugin directory: %s", plugins_dir.generic_u8string().c_str());
|
||||
if (is_system) {
|
||||
LOG_TRACE("[PluginManager] Scanning system plugin directory: %s",
|
||||
plugins_dir.generic_u8string().c_str());
|
||||
} else {
|
||||
LOG_TRACE("[PluginManager] Scanning user plugin directory: %s",
|
||||
plugins_dir.generic_u8string().c_str());
|
||||
}
|
||||
|
||||
if(!filesystem::is_directory(plugins_dir))
|
||||
{
|
||||
if (!filesystem::is_directory(plugins_dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,22 +110,21 @@ void PluginManager::ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir,
|
||||
| Get a list of all files in the plugins directory |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
for(const filesystem::directory_entry& entry: filesystem::directory_iterator(plugins_dir))
|
||||
{
|
||||
if(filesystem::is_directory(entry.path()))
|
||||
{
|
||||
for (const filesystem::directory_entry &entry : filesystem::directory_iterator(plugins_dir)) {
|
||||
if (filesystem::is_directory(entry.path())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
filesystem::path plugin_path = entry.path();
|
||||
LOG_TRACE("[PluginManager] Found plugin file %s", plugin_path.filename().generic_u8string().c_str());
|
||||
LOG_TRACE("[PluginManager] Found plugin file %s",
|
||||
plugin_path.filename().generic_u8string().c_str());
|
||||
AddPlugin(plugin_path, is_system);
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
void PluginManager::AddPlugin(const filesystem::path &path, bool is_system)
|
||||
{
|
||||
OpenRGBPluginInterface* plugin = nullptr;
|
||||
OpenRGBPluginInterface *plugin = nullptr;
|
||||
|
||||
unsigned int plugin_idx;
|
||||
|
||||
@@ -136,14 +136,15 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Check if this plugin is on the remove list |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_settings.contains("plugins_remove"))
|
||||
{
|
||||
for(unsigned int plugin_remove_idx = 0; plugin_remove_idx < plugin_settings["plugins_remove"].size(); plugin_remove_idx++)
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Checking remove %d, %s", plugin_remove_idx, to_string(plugin_settings["plugins_remove"][plugin_remove_idx]).c_str());
|
||||
if (plugin_settings.contains("plugins_remove")) {
|
||||
for (unsigned int plugin_remove_idx = 0;
|
||||
plugin_remove_idx < plugin_settings["plugins_remove"].size();
|
||||
plugin_remove_idx++) {
|
||||
LOG_WARNING("[PluginManager] Checking remove %d, %s",
|
||||
plugin_remove_idx,
|
||||
to_string(plugin_settings["plugins_remove"][plugin_remove_idx]).c_str());
|
||||
|
||||
if(plugin_settings["plugins_remove"][plugin_remove_idx] == path.generic_u8string())
|
||||
{
|
||||
if (plugin_settings["plugins_remove"][plugin_remove_idx] == path.generic_u8string()) {
|
||||
/*---------------------------------------------------------*\
|
||||
| Delete the plugin file |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -163,10 +164,8 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
for (plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++) {
|
||||
if (path == ActivePlugins[plugin_idx].path) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -174,32 +173,30 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the path does not match an existing entry, create a new entry |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
if (plugin_idx == ActivePlugins.size()) {
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Create a QPluginLoader and load the plugin |
|
||||
\*-----------------------------------------------------------------*/
|
||||
std::string path_string = path.generic_u8string();
|
||||
QPluginLoader* loader = new QPluginLoader(QString::fromStdString(path_string));
|
||||
QObject* instance = loader->instance();
|
||||
std::string path_string = path.generic_u8string();
|
||||
QPluginLoader *loader = new QPluginLoader(QString::fromStdString(path_string));
|
||||
QObject *instance = loader->instance();
|
||||
|
||||
if(!loader->isLoaded())
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be loaded: %s", path.c_str(), loader->errorString().toStdString().c_str());
|
||||
if (!loader->isLoaded()) {
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be loaded: %s",
|
||||
path.c_str(),
|
||||
loader->errorString().toStdString().c_str());
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Check that the plugin is valid, then check the API version |
|
||||
\*-----------------------------------------------------------------*/
|
||||
if(instance)
|
||||
{
|
||||
plugin = qobject_cast<OpenRGBPluginInterface*>(instance);
|
||||
if (instance) {
|
||||
plugin = qobject_cast<OpenRGBPluginInterface *>(instance);
|
||||
|
||||
if(plugin)
|
||||
{
|
||||
if(plugin->GetPluginAPIVersion() == OPENRGB_PLUGIN_API_VERSION)
|
||||
{
|
||||
LOG_TRACE("[PluginManager] Plugin %s has a compatible API version", path.c_str());
|
||||
if (plugin) {
|
||||
if (plugin->GetPluginAPIVersion() == OPENRGB_PLUGIN_API_VERSION) {
|
||||
LOG_TRACE("[PluginManager] Plugin %s has a compatible API version",
|
||||
path.c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the plugin information |
|
||||
@@ -209,36 +206,35 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
/*-----------------------------------------------------*\
|
||||
| Search the settings to see if it is enabled |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string name = "";
|
||||
std::string description = "";
|
||||
bool enabled = true;
|
||||
bool found = false;
|
||||
unsigned int plugin_ct = 0;
|
||||
std::string name = "";
|
||||
std::string description = "";
|
||||
bool enabled = true;
|
||||
bool found = false;
|
||||
unsigned int plugin_ct = 0;
|
||||
|
||||
if(plugin_settings.contains("plugins"))
|
||||
{
|
||||
plugin_ct = (unsigned int)plugin_settings["plugins"].size();
|
||||
if (plugin_settings.contains("plugins")) {
|
||||
plugin_ct = (unsigned int) plugin_settings["plugins"].size();
|
||||
|
||||
for(unsigned int plugin_settings_idx = 0; plugin_settings_idx < plugin_settings["plugins"].size(); plugin_settings_idx++)
|
||||
{
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("name"))
|
||||
{
|
||||
name = plugin_settings["plugins"][plugin_settings_idx]["name"];
|
||||
for (unsigned int plugin_settings_idx = 0;
|
||||
plugin_settings_idx < plugin_settings["plugins"].size();
|
||||
plugin_settings_idx++) {
|
||||
if (plugin_settings["plugins"][plugin_settings_idx].contains("name")) {
|
||||
name = plugin_settings["plugins"][plugin_settings_idx]["name"];
|
||||
}
|
||||
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("description"))
|
||||
{
|
||||
description = plugin_settings["plugins"][plugin_settings_idx]["description"];
|
||||
if (plugin_settings["plugins"][plugin_settings_idx].contains(
|
||||
"description")) {
|
||||
description = plugin_settings["plugins"][plugin_settings_idx]
|
||||
["description"];
|
||||
}
|
||||
|
||||
if(plugin_settings["plugins"][plugin_settings_idx].contains("enabled"))
|
||||
{
|
||||
enabled = plugin_settings["plugins"][plugin_settings_idx]["enabled"];
|
||||
if (plugin_settings["plugins"][plugin_settings_idx].contains(
|
||||
"enabled")) {
|
||||
enabled
|
||||
= plugin_settings["plugins"][plugin_settings_idx]["enabled"];
|
||||
}
|
||||
|
||||
if((info.Name == name)
|
||||
&&(info.Description == description))
|
||||
{
|
||||
if ((info.Name == name) && (info.Description == description)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -249,13 +245,13 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
| If the plugin was not in the list, add it to the list |
|
||||
| and default it to enabled, then save the settings |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!found)
|
||||
{
|
||||
plugin_settings["plugins"][plugin_ct]["name"] = info.Name;
|
||||
plugin_settings["plugins"][plugin_ct]["description"] = info.Description;
|
||||
plugin_settings["plugins"][plugin_ct]["enabled"] = enabled;
|
||||
if (!found) {
|
||||
plugin_settings["plugins"][plugin_ct]["name"] = info.Name;
|
||||
plugin_settings["plugins"][plugin_ct]["description"] = info.Description;
|
||||
plugin_settings["plugins"][plugin_ct]["enabled"] = enabled;
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins",
|
||||
plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
|
||||
@@ -266,35 +262,33 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginEntry entry;
|
||||
|
||||
entry.info = info;
|
||||
entry.plugin = plugin;
|
||||
entry.loader = loader;
|
||||
entry.path = path_string;
|
||||
entry.enabled = enabled;
|
||||
entry.widget = nullptr;
|
||||
entry.incompatible = false;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
entry.is_system = is_system;
|
||||
entry.info = info;
|
||||
entry.plugin = plugin;
|
||||
entry.loader = loader;
|
||||
entry.path = path_string;
|
||||
entry.enabled = enabled;
|
||||
entry.widget = nullptr;
|
||||
entry.incompatible = false;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
entry.is_system = is_system;
|
||||
|
||||
loader->unload();
|
||||
|
||||
ActivePlugins.push_back(entry);
|
||||
|
||||
if(entry.enabled)
|
||||
{
|
||||
if (entry.enabled) {
|
||||
LoadPlugin(&ActivePlugins.back());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in a plugin information object with text showing |
|
||||
| the plugin is incompatible |
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginInfo info;
|
||||
|
||||
info.Name = "Incompatible Plugin";
|
||||
info.Description = "This plugin is not compatible with this version of OpenRGB.";
|
||||
info.Name = "Incompatible Plugin";
|
||||
info.Description
|
||||
= "This plugin is not compatible with this version of OpenRGB.";
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the plugin to the PluginManager active plugins |
|
||||
@@ -302,15 +296,15 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
\*-----------------------------------------------------*/
|
||||
OpenRGBPluginEntry entry;
|
||||
|
||||
entry.info = info;
|
||||
entry.plugin = plugin;
|
||||
entry.loader = loader;
|
||||
entry.path = path_string;
|
||||
entry.enabled = false;
|
||||
entry.widget = nullptr;
|
||||
entry.incompatible = true;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
entry.is_system = is_system;
|
||||
entry.info = info;
|
||||
entry.plugin = plugin;
|
||||
entry.loader = loader;
|
||||
entry.path = path_string;
|
||||
entry.enabled = false;
|
||||
entry.widget = nullptr;
|
||||
entry.incompatible = true;
|
||||
entry.api_version = plugin->GetPluginAPIVersion();
|
||||
entry.is_system = is_system;
|
||||
|
||||
loader->unload();
|
||||
|
||||
@@ -318,27 +312,24 @@ void PluginManager::AddPlugin(const filesystem::path& path, bool is_system)
|
||||
|
||||
bool unloaded = loader->unload();
|
||||
|
||||
LOG_WARNING("[PluginManager] Plugin %s has an incompatible API version", path.c_str());
|
||||
LOG_WARNING("[PluginManager] Plugin %s has an incompatible API version",
|
||||
path.c_str());
|
||||
|
||||
if(!unloaded)
|
||||
{
|
||||
if (!unloaded) {
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be unloaded", path.c_str());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be casted to OpenRGBPluginInterface",
|
||||
path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be casted to OpenRGBPluginInterface", path.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be instantiated.", path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::RemovePlugin(const filesystem::path& path)
|
||||
void PluginManager::RemovePlugin(const filesystem::path &path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
@@ -347,10 +338,8 @@ void PluginManager::RemovePlugin(const filesystem::path& path)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
for (plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++) {
|
||||
if (path == ActivePlugins[plugin_idx].path) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -358,8 +347,7 @@ void PluginManager::RemovePlugin(const filesystem::path& path)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active plugins list, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
if (plugin_idx == ActivePlugins.size()) {
|
||||
LOG_TRACE("[PluginManager] Plugin %s not active", path.c_str());
|
||||
return;
|
||||
}
|
||||
@@ -367,8 +355,7 @@ void PluginManager::RemovePlugin(const filesystem::path& path)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the selected plugin is in the list and loaded, unload it |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(ActivePlugins[plugin_idx].loader->isLoaded())
|
||||
{
|
||||
if (ActivePlugins[plugin_idx].loader->isLoaded()) {
|
||||
LOG_TRACE("[PluginManager] Plugin %s is active, unloading", path.c_str());
|
||||
UnloadPlugin(&ActivePlugins[plugin_idx]);
|
||||
}
|
||||
@@ -379,17 +366,15 @@ void PluginManager::RemovePlugin(const filesystem::path& path)
|
||||
ActivePlugins.erase(ActivePlugins.begin() + plugin_idx);
|
||||
}
|
||||
|
||||
void PluginManager::EnablePlugin(const filesystem::path& path)
|
||||
void PluginManager::EnablePlugin(const filesystem::path &path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
for (plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++) {
|
||||
if (path == ActivePlugins[plugin_idx].path) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -397,8 +382,7 @@ void PluginManager::EnablePlugin(const filesystem::path& path)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active plugins list, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
if (plugin_idx == ActivePlugins.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -406,33 +390,28 @@ void PluginManager::EnablePlugin(const filesystem::path& path)
|
||||
LoadPlugin(&ActivePlugins[plugin_idx]);
|
||||
}
|
||||
|
||||
void PluginManager::LoadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
void PluginManager::LoadPlugin(OpenRGBPluginEntry *plugin_entry)
|
||||
{
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin is in the list but is incompatible, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_entry->incompatible)
|
||||
{
|
||||
if (plugin_entry->incompatible) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the selected plugin is in the list but not loaded, load it |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(!plugin_entry->loader->isLoaded())
|
||||
{
|
||||
if (!plugin_entry->loader->isLoaded()) {
|
||||
plugin_entry->loader->load();
|
||||
|
||||
QObject* instance = plugin_entry->loader->instance();
|
||||
QObject *instance = plugin_entry->loader->instance();
|
||||
|
||||
if(instance)
|
||||
{
|
||||
OpenRGBPluginInterface* plugin = qobject_cast<OpenRGBPluginInterface*>(instance);
|
||||
if (instance) {
|
||||
OpenRGBPluginInterface *plugin = qobject_cast<OpenRGBPluginInterface *>(instance);
|
||||
|
||||
if(plugin)
|
||||
{
|
||||
if(plugin->GetPluginAPIVersion() == OPENRGB_PLUGIN_API_VERSION)
|
||||
{
|
||||
if (plugin) {
|
||||
if (plugin->GetPluginAPIVersion() == OPENRGB_PLUGIN_API_VERSION) {
|
||||
plugin_entry->plugin = plugin;
|
||||
|
||||
plugin->Load(ResourceManager::get());
|
||||
@@ -440,8 +419,7 @@ void PluginManager::LoadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
/*-------------------------------------------------*\
|
||||
| Call the Add Plugin callback |
|
||||
\*-------------------------------------------------*/
|
||||
if(AddPluginCallbackArg != nullptr)
|
||||
{
|
||||
if (AddPluginCallbackArg != nullptr) {
|
||||
AddPluginCallbackVal(AddPluginCallbackArg, plugin_entry);
|
||||
}
|
||||
}
|
||||
@@ -450,17 +428,15 @@ void PluginManager::LoadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::DisablePlugin(const filesystem::path& path)
|
||||
void PluginManager::DisablePlugin(const filesystem::path &path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
/*---------------------------------------------------------------------*\
|
||||
| Search active plugins to see if this path already exists |
|
||||
\*---------------------------------------------------------------------*/
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
for (plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++) {
|
||||
if (path == ActivePlugins[plugin_idx].path) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -468,8 +444,7 @@ void PluginManager::DisablePlugin(const filesystem::path& path)
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the plugin path does not exist in the active plugins list, return |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
if (plugin_idx == ActivePlugins.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -477,13 +452,12 @@ void PluginManager::DisablePlugin(const filesystem::path& path)
|
||||
UnloadPlugin(&ActivePlugins[plugin_idx]);
|
||||
}
|
||||
|
||||
void PluginManager::UnloadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
void PluginManager::UnloadPlugin(OpenRGBPluginEntry *plugin_entry)
|
||||
{
|
||||
/*---------------------------------------------------------------------*\
|
||||
| If the selected plugin is in the list and loaded, unload it |
|
||||
\*---------------------------------------------------------------------*/
|
||||
if(plugin_entry->loader->isLoaded())
|
||||
{
|
||||
if (plugin_entry->loader->isLoaded()) {
|
||||
/*-------------------------------------------------*\
|
||||
| Call plugin's Unload function before GUI removal |
|
||||
\*-------------------------------------------------*/
|
||||
@@ -492,34 +466,26 @@ void PluginManager::UnloadPlugin(OpenRGBPluginEntry* plugin_entry)
|
||||
/*-------------------------------------------------*\
|
||||
| Call the Remove Plugin callback |
|
||||
\*-------------------------------------------------*/
|
||||
if(RemovePluginCallbackVal != nullptr)
|
||||
{
|
||||
if (RemovePluginCallbackVal != nullptr) {
|
||||
RemovePluginCallbackVal(RemovePluginCallbackArg, plugin_entry);
|
||||
}
|
||||
|
||||
bool unloaded = plugin_entry->loader->unload();
|
||||
|
||||
if(!unloaded)
|
||||
{
|
||||
if (!unloaded) {
|
||||
LOG_WARNING("[PluginManager] Plugin %s cannot be unloaded", plugin_entry->path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_TRACE("[PluginManager] Plugin %s successfully unloaded", plugin_entry->path.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LOG_TRACE("[PluginManager] Plugin %s was already unloaded", plugin_entry->path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::LoadPlugins()
|
||||
{
|
||||
for(OpenRGBPluginEntry& plugin_entry: ActivePlugins)
|
||||
{
|
||||
if(plugin_entry.enabled)
|
||||
{
|
||||
for (OpenRGBPluginEntry &plugin_entry : ActivePlugins) {
|
||||
if (plugin_entry.enabled) {
|
||||
LoadPlugin(&plugin_entry);
|
||||
}
|
||||
}
|
||||
@@ -527,8 +493,7 @@ void PluginManager::LoadPlugins()
|
||||
|
||||
void PluginManager::UnloadPlugins()
|
||||
{
|
||||
for(OpenRGBPluginEntry& plugin_entry: ActivePlugins)
|
||||
{
|
||||
for (OpenRGBPluginEntry &plugin_entry : ActivePlugins) {
|
||||
UnloadPlugin(&plugin_entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,36 +19,36 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
OpenRGBPluginInfo info;
|
||||
OpenRGBPluginInterface* plugin;
|
||||
QPluginLoader* loader;
|
||||
QWidget* widget;
|
||||
QMenu* traymenu;
|
||||
std::string path;
|
||||
bool enabled;
|
||||
bool incompatible;
|
||||
bool is_system;
|
||||
int api_version;
|
||||
OpenRGBPluginInfo info;
|
||||
OpenRGBPluginInterface *plugin;
|
||||
QPluginLoader *loader;
|
||||
QWidget *widget;
|
||||
QMenu *traymenu;
|
||||
std::string path;
|
||||
bool enabled;
|
||||
bool incompatible;
|
||||
bool is_system;
|
||||
int api_version;
|
||||
} OpenRGBPluginEntry;
|
||||
|
||||
typedef void (*AddPluginCallback)(void *, OpenRGBPluginEntry* plugin);
|
||||
typedef void (*RemovePluginCallback)(void *, OpenRGBPluginEntry* plugin);
|
||||
typedef void (*AddPluginCallback)(void *, OpenRGBPluginEntry *plugin);
|
||||
typedef void (*RemovePluginCallback)(void *, OpenRGBPluginEntry *plugin);
|
||||
|
||||
class PluginManager
|
||||
{
|
||||
public:
|
||||
PluginManager();
|
||||
|
||||
void RegisterAddPluginCallback(AddPluginCallback new_callback, void * new_callback_arg);
|
||||
void RegisterRemovePluginCallback(RemovePluginCallback new_callback, void * new_callback_arg);
|
||||
void RegisterAddPluginCallback(AddPluginCallback new_callback, void *new_callback_arg);
|
||||
void RegisterRemovePluginCallback(RemovePluginCallback new_callback, void *new_callback_arg);
|
||||
|
||||
void ScanAndLoadPlugins();
|
||||
|
||||
void AddPlugin(const filesystem::path& path, bool is_system);
|
||||
void RemovePlugin(const filesystem::path& path);
|
||||
void AddPlugin(const filesystem::path &path, bool is_system);
|
||||
void RemovePlugin(const filesystem::path &path);
|
||||
|
||||
void EnablePlugin(const filesystem::path& path);
|
||||
void DisablePlugin(const filesystem::path& path);
|
||||
void EnablePlugin(const filesystem::path &path);
|
||||
void DisablePlugin(const filesystem::path &path);
|
||||
|
||||
void LoadPlugins();
|
||||
void UnloadPlugins();
|
||||
@@ -56,16 +56,16 @@ public:
|
||||
std::vector<OpenRGBPluginEntry> ActivePlugins;
|
||||
|
||||
private:
|
||||
void LoadPlugin(OpenRGBPluginEntry* plugin_entry);
|
||||
void UnloadPlugin(OpenRGBPluginEntry* plugin_entry);
|
||||
void LoadPlugin(OpenRGBPluginEntry *plugin_entry);
|
||||
void UnloadPlugin(OpenRGBPluginEntry *plugin_entry);
|
||||
|
||||
void ScanAndLoadPluginsFrom(const filesystem::path & plugins_dir, bool is_system);
|
||||
void ScanAndLoadPluginsFrom(const filesystem::path &plugins_dir, bool is_system);
|
||||
|
||||
AddPluginCallback AddPluginCallbackVal;
|
||||
void * AddPluginCallbackArg;
|
||||
AddPluginCallback AddPluginCallbackVal;
|
||||
void *AddPluginCallbackArg;
|
||||
|
||||
RemovePluginCallback RemovePluginCallbackVal;
|
||||
void * RemovePluginCallbackArg;
|
||||
RemovePluginCallback RemovePluginCallbackVal;
|
||||
void *RemovePluginCallbackArg;
|
||||
|
||||
const char * plugins_path = "plugins/";
|
||||
const char *plugins_path = "plugins/";
|
||||
};
|
||||
|
||||
@@ -18,19 +18,16 @@
|
||||
#include "filesystem.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
#define OPENRGB_PROFILE_HEADER "OPENRGB_PROFILE"
|
||||
#define OPENRGB_PROFILE_HEADER "OPENRGB_PROFILE"
|
||||
#define OPENRGB_PROFILE_VERSION OPENRGB_SDK_PROTOCOL_VERSION
|
||||
|
||||
ProfileManager::ProfileManager(const filesystem::path& config_dir)
|
||||
ProfileManager::ProfileManager(const filesystem::path &config_dir)
|
||||
{
|
||||
configuration_directory = config_dir;
|
||||
UpdateProfileList();
|
||||
}
|
||||
|
||||
ProfileManager::~ProfileManager()
|
||||
{
|
||||
|
||||
}
|
||||
ProfileManager::~ProfileManager() {}
|
||||
|
||||
bool ProfileManager::SaveProfile(std::string profile_name, bool sizes)
|
||||
{
|
||||
@@ -44,8 +41,7 @@ bool ProfileManager::SaveProfile(std::string profile_name, bool sizes)
|
||||
/*---------------------------------------------------------*\
|
||||
| If a name was entered, save the profile file |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_name != "")
|
||||
{
|
||||
if (profile_name != "") {
|
||||
/*---------------------------------------------------------*\
|
||||
| Extension .orp - OpenRgb Profile |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -54,12 +50,9 @@ bool ProfileManager::SaveProfile(std::string profile_name, bool sizes)
|
||||
/*---------------------------------------------------------*\
|
||||
| Determine file extension |
|
||||
\*---------------------------------------------------------*/
|
||||
if(sizes)
|
||||
{
|
||||
if (sizes) {
|
||||
filename += ".ors";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
filename += ".orp";
|
||||
}
|
||||
|
||||
@@ -67,7 +60,8 @@ bool ProfileManager::SaveProfile(std::string profile_name, bool sizes)
|
||||
| Open an output file in binary mode |
|
||||
\*---------------------------------------------------------*/
|
||||
filesystem::path profile_path = configuration_directory / filesystem::u8path(filename);
|
||||
std::ofstream controller_file(profile_path, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
std::ofstream controller_file(profile_path,
|
||||
std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Write header |
|
||||
@@ -76,29 +70,30 @@ bool ProfileManager::SaveProfile(std::string profile_name, bool sizes)
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned int profile_version = OPENRGB_PROFILE_VERSION;
|
||||
controller_file.write(OPENRGB_PROFILE_HEADER, 16);
|
||||
controller_file.write((char *)&profile_version, sizeof(unsigned int));
|
||||
controller_file.write((char *) &profile_version, sizeof(unsigned int));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Write controller data for each controller |
|
||||
\*---------------------------------------------------------*/
|
||||
for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++)
|
||||
{
|
||||
for (std::size_t controller_index = 0; controller_index < controllers.size();
|
||||
controller_index++) {
|
||||
/*-----------------------------------------------------*\
|
||||
| Ignore remote and virtual controllers when saving |
|
||||
| sizes |
|
||||
\*-----------------------------------------------------*/
|
||||
if(sizes && (controllers[controller_index]->flags & CONTROLLER_FLAG_REMOTE
|
||||
|| controllers[controller_index]->flags & CONTROLLER_FLAG_VIRTUAL))
|
||||
{
|
||||
if (sizes
|
||||
&& (controllers[controller_index]->flags & CONTROLLER_FLAG_REMOTE
|
||||
|| controllers[controller_index]->flags & CONTROLLER_FLAG_VIRTUAL)) {
|
||||
break;
|
||||
}
|
||||
|
||||
unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription(profile_version);
|
||||
unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription(
|
||||
profile_version);
|
||||
unsigned int controller_size;
|
||||
|
||||
memcpy(&controller_size, controller_data, sizeof(controller_size));
|
||||
|
||||
controller_file.write((const char *)controller_data, controller_size);
|
||||
controller_file.write((const char *) controller_data, controller_size);
|
||||
|
||||
delete[] controller_data;
|
||||
}
|
||||
@@ -113,15 +108,13 @@ bool ProfileManager::SaveProfile(std::string profile_name, bool sizes)
|
||||
\*---------------------------------------------------------*/
|
||||
UpdateProfileList();
|
||||
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileManager::SetConfigurationDirectory(const filesystem::path& directory)
|
||||
void ProfileManager::SetConfigurationDirectory(const filesystem::path &directory)
|
||||
{
|
||||
configuration_directory = directory;
|
||||
UpdateProfileList();
|
||||
@@ -130,38 +123,30 @@ void ProfileManager::SetConfigurationDirectory(const filesystem::path& directory
|
||||
bool ProfileManager::LoadProfile(std::string profile_name)
|
||||
{
|
||||
profile_name = StringUtils::remove_null_terminating_chars(profile_name);
|
||||
return(LoadProfileWithOptions(profile_name, false, true));
|
||||
return (LoadProfileWithOptions(profile_name, false, true));
|
||||
}
|
||||
|
||||
bool ProfileManager::LoadSizeFromProfile(std::string profile_name)
|
||||
{
|
||||
profile_name = StringUtils::remove_null_terminating_chars(profile_name);
|
||||
return(LoadProfileWithOptions(profile_name, true, false));
|
||||
return (LoadProfileWithOptions(profile_name, true, false));
|
||||
}
|
||||
|
||||
std::vector<RGBController*> ProfileManager::LoadProfileToList
|
||||
(
|
||||
std::string profile_name,
|
||||
bool sizes
|
||||
)
|
||||
std::vector<RGBController *> ProfileManager::LoadProfileToList(std::string profile_name, bool sizes)
|
||||
{
|
||||
std::vector<RGBController*> temp_controllers;
|
||||
unsigned int controller_size;
|
||||
unsigned int controller_offset = 0;
|
||||
std::vector<RGBController *> temp_controllers;
|
||||
unsigned int controller_size;
|
||||
unsigned int controller_offset = 0;
|
||||
|
||||
filesystem::path filename = configuration_directory / filesystem::u8path(profile_name);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Determine file extension |
|
||||
\*---------------------------------------------------------*/
|
||||
if(sizes)
|
||||
{
|
||||
if (sizes) {
|
||||
filename.concat(".ors");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(filename.extension() != ".orp")
|
||||
{
|
||||
} else {
|
||||
if (filename.extension() != ".orp") {
|
||||
filename.concat(".orp");
|
||||
}
|
||||
}
|
||||
@@ -174,41 +159,37 @@ std::vector<RGBController*> ProfileManager::LoadProfileToList
|
||||
/*---------------------------------------------------------*\
|
||||
| Read and verify file header |
|
||||
\*---------------------------------------------------------*/
|
||||
char profile_string[16] = "";
|
||||
unsigned int profile_version = 0;
|
||||
char profile_string[16] = "";
|
||||
unsigned int profile_version = 0;
|
||||
|
||||
controller_file.read(profile_string, 16);
|
||||
controller_file.read((char *)&profile_version, sizeof(unsigned int));
|
||||
controller_file.read((char *) &profile_version, sizeof(unsigned int));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Profile version started at 1 and protocol version started |
|
||||
| at 0. Version 1 profiles should use protocol 0, but 2 or |
|
||||
| greater should be synchronized |
|
||||
\*---------------------------------------------------------*/
|
||||
if(profile_version == 1)
|
||||
{
|
||||
if (profile_version == 1) {
|
||||
profile_version = 0;
|
||||
}
|
||||
|
||||
controller_offset += 16 + sizeof(unsigned int);
|
||||
controller_file.seekg(controller_offset);
|
||||
|
||||
if(strcmp(profile_string, OPENRGB_PROFILE_HEADER) == 0)
|
||||
{
|
||||
if(profile_version <= OPENRGB_PROFILE_VERSION)
|
||||
{
|
||||
if (strcmp(profile_string, OPENRGB_PROFILE_HEADER) == 0) {
|
||||
if (profile_version <= OPENRGB_PROFILE_VERSION) {
|
||||
/*---------------------------------------------------------*\
|
||||
| Read controller data from file until EOF |
|
||||
\*---------------------------------------------------------*/
|
||||
while(!(controller_file.peek() == EOF))
|
||||
{
|
||||
controller_file.read((char *)&controller_size, sizeof(controller_size));
|
||||
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);
|
||||
controller_file.read((char *) controller_data, controller_size);
|
||||
|
||||
RGBController_Dummy *temp_controller = new RGBController_Dummy();
|
||||
|
||||
@@ -224,20 +205,16 @@ std::vector<RGBController*> ProfileManager::LoadProfileToList
|
||||
}
|
||||
}
|
||||
|
||||
return(temp_controllers);
|
||||
return (temp_controllers);
|
||||
}
|
||||
|
||||
bool ProfileManager::LoadDeviceFromListWithOptions
|
||||
(
|
||||
std::vector<RGBController*>& temp_controllers,
|
||||
std::vector<bool>& temp_controller_used,
|
||||
RGBController* load_controller,
|
||||
bool load_size,
|
||||
bool load_settings
|
||||
)
|
||||
bool ProfileManager::LoadDeviceFromListWithOptions(std::vector<RGBController *> &temp_controllers,
|
||||
std::vector<bool> &temp_controller_used,
|
||||
RGBController *load_controller,
|
||||
bool load_size,
|
||||
bool load_settings)
|
||||
{
|
||||
for(std::size_t temp_index = 0; temp_index < temp_controllers.size(); temp_index++)
|
||||
{
|
||||
for (std::size_t temp_index = 0; temp_index < temp_controllers.size(); temp_index++) {
|
||||
RGBController *temp_controller = temp_controllers[temp_index];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -249,39 +226,29 @@ bool ProfileManager::LoadDeviceFromListWithOptions
|
||||
\*---------------------------------------------------------*/
|
||||
bool location_check;
|
||||
|
||||
if(load_controller->location.find("HID: ") == 0)
|
||||
{
|
||||
if (load_controller->location.find("HID: ") == 0) {
|
||||
location_check = true;
|
||||
}
|
||||
else if(load_controller->location.find("I2C: ") == 0)
|
||||
{
|
||||
} else if (load_controller->location.find("I2C: ") == 0) {
|
||||
std::size_t loc = load_controller->location.rfind(", ");
|
||||
if(loc == std::string::npos)
|
||||
{
|
||||
if (loc == std::string::npos) {
|
||||
location_check = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::string i2c_address = load_controller->location.substr(loc + 2);
|
||||
location_check = temp_controller->location.find(i2c_address) != std::string::npos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
location_check = temp_controller->location == load_controller->location;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Test if saved controller data matches this controller |
|
||||
\*---------------------------------------------------------*/
|
||||
if((temp_controller_used[temp_index] == false )
|
||||
&&(temp_controller->type == load_controller->type )
|
||||
&&(temp_controller->name == load_controller->name )
|
||||
&&(temp_controller->description == load_controller->description)
|
||||
&&(temp_controller->version == load_controller->version )
|
||||
&&(temp_controller->serial == load_controller->serial )
|
||||
&&(location_check == true ))
|
||||
{
|
||||
if ((temp_controller_used[temp_index] == false)
|
||||
&& (temp_controller->type == load_controller->type)
|
||||
&& (temp_controller->name == load_controller->name)
|
||||
&& (temp_controller->description == load_controller->description)
|
||||
&& (temp_controller->version == load_controller->version)
|
||||
&& (temp_controller->serial == load_controller->serial) && (location_check == true)) {
|
||||
/*---------------------------------------------------------*\
|
||||
| Set used flag for this temp device |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -290,29 +257,34 @@ bool ProfileManager::LoadDeviceFromListWithOptions
|
||||
/*---------------------------------------------------------*\
|
||||
| Update zone sizes if requested |
|
||||
\*---------------------------------------------------------*/
|
||||
if(load_size)
|
||||
{
|
||||
if(temp_controller->zones.size() == load_controller->zones.size())
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < temp_controller->zones.size(); zone_idx++)
|
||||
{
|
||||
if((temp_controller->zones[zone_idx].name == load_controller->zones[zone_idx].name )
|
||||
&&(temp_controller->zones[zone_idx].type == load_controller->zones[zone_idx].type )
|
||||
&&(temp_controller->zones[zone_idx].leds_min == load_controller->zones[zone_idx].leds_min )
|
||||
&&(temp_controller->zones[zone_idx].leds_max == load_controller->zones[zone_idx].leds_max ))
|
||||
{
|
||||
if(temp_controller->zones[zone_idx].leds_count != load_controller->zones[zone_idx].leds_count)
|
||||
{
|
||||
load_controller->ResizeZone((int)zone_idx, temp_controller->zones[zone_idx].leds_count);
|
||||
if (load_size) {
|
||||
if (temp_controller->zones.size() == load_controller->zones.size()) {
|
||||
for (std::size_t zone_idx = 0; zone_idx < temp_controller->zones.size();
|
||||
zone_idx++) {
|
||||
if ((temp_controller->zones[zone_idx].name
|
||||
== load_controller->zones[zone_idx].name)
|
||||
&& (temp_controller->zones[zone_idx].type
|
||||
== load_controller->zones[zone_idx].type)
|
||||
&& (temp_controller->zones[zone_idx].leds_min
|
||||
== load_controller->zones[zone_idx].leds_min)
|
||||
&& (temp_controller->zones[zone_idx].leds_max
|
||||
== load_controller->zones[zone_idx].leds_max)) {
|
||||
if (temp_controller->zones[zone_idx].leds_count
|
||||
!= load_controller->zones[zone_idx].leds_count) {
|
||||
load_controller
|
||||
->ResizeZone((int) zone_idx,
|
||||
temp_controller->zones[zone_idx].leds_count);
|
||||
}
|
||||
|
||||
if(temp_controller->zones[zone_idx].segments.size() != load_controller->zones[zone_idx].segments.size())
|
||||
{
|
||||
if (temp_controller->zones[zone_idx].segments.size()
|
||||
!= load_controller->zones[zone_idx].segments.size()) {
|
||||
load_controller->zones[zone_idx].segments.clear();
|
||||
|
||||
for(std::size_t segment_idx = 0; segment_idx < temp_controller->zones[zone_idx].segments.size(); segment_idx++)
|
||||
{
|
||||
load_controller->zones[zone_idx].segments.push_back(temp_controller->zones[zone_idx].segments[segment_idx]);
|
||||
for (std::size_t segment_idx = 0;
|
||||
segment_idx < temp_controller->zones[zone_idx].segments.size();
|
||||
segment_idx++) {
|
||||
load_controller->zones[zone_idx].segments.push_back(
|
||||
temp_controller->zones[zone_idx].segments[segment_idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,38 +295,48 @@ bool ProfileManager::LoadDeviceFromListWithOptions
|
||||
/*---------------------------------------------------------*\
|
||||
| Update settings if requested |
|
||||
\*---------------------------------------------------------*/
|
||||
if(load_settings)
|
||||
{
|
||||
if (load_settings) {
|
||||
/*---------------------------------------------------------*\
|
||||
| Update all modes |
|
||||
\*---------------------------------------------------------*/
|
||||
if(temp_controller->modes.size() == load_controller->modes.size())
|
||||
{
|
||||
for(std::size_t mode_index = 0; mode_index < temp_controller->modes.size(); mode_index++)
|
||||
{
|
||||
if((temp_controller->modes[mode_index].name == load_controller->modes[mode_index].name )
|
||||
&&(temp_controller->modes[mode_index].value == load_controller->modes[mode_index].value )
|
||||
&&(temp_controller->modes[mode_index].flags == load_controller->modes[mode_index].flags )
|
||||
&&(temp_controller->modes[mode_index].speed_min == load_controller->modes[mode_index].speed_min )
|
||||
&&(temp_controller->modes[mode_index].speed_max == load_controller->modes[mode_index].speed_max )
|
||||
//&&(temp_controller->modes[mode_index].brightness_min == load_controller->modes[mode_index].brightness_min)
|
||||
//&&(temp_controller->modes[mode_index].brightness_max == load_controller->modes[mode_index].brightness_max)
|
||||
&&(temp_controller->modes[mode_index].colors_min == load_controller->modes[mode_index].colors_min )
|
||||
&&(temp_controller->modes[mode_index].colors_max == load_controller->modes[mode_index].colors_max ))
|
||||
{
|
||||
load_controller->modes[mode_index].speed = temp_controller->modes[mode_index].speed;
|
||||
load_controller->modes[mode_index].brightness = temp_controller->modes[mode_index].brightness;
|
||||
load_controller->modes[mode_index].direction = temp_controller->modes[mode_index].direction;
|
||||
load_controller->modes[mode_index].color_mode = temp_controller->modes[mode_index].color_mode;
|
||||
if (temp_controller->modes.size() == load_controller->modes.size()) {
|
||||
for (std::size_t mode_index = 0; mode_index < temp_controller->modes.size();
|
||||
mode_index++) {
|
||||
if ((temp_controller->modes[mode_index].name
|
||||
== load_controller->modes[mode_index].name)
|
||||
&& (temp_controller->modes[mode_index].value
|
||||
== load_controller->modes[mode_index].value)
|
||||
&& (temp_controller->modes[mode_index].flags
|
||||
== load_controller->modes[mode_index].flags)
|
||||
&& (temp_controller->modes[mode_index].speed_min
|
||||
== load_controller->modes[mode_index].speed_min)
|
||||
&& (temp_controller->modes[mode_index].speed_max
|
||||
== load_controller->modes[mode_index].speed_max)
|
||||
//&&(temp_controller->modes[mode_index].brightness_min == load_controller->modes[mode_index].brightness_min)
|
||||
//&&(temp_controller->modes[mode_index].brightness_max == load_controller->modes[mode_index].brightness_max)
|
||||
&& (temp_controller->modes[mode_index].colors_min
|
||||
== load_controller->modes[mode_index].colors_min)
|
||||
&& (temp_controller->modes[mode_index].colors_max
|
||||
== load_controller->modes[mode_index].colors_max)) {
|
||||
load_controller->modes[mode_index].speed
|
||||
= temp_controller->modes[mode_index].speed;
|
||||
load_controller->modes[mode_index].brightness
|
||||
= temp_controller->modes[mode_index].brightness;
|
||||
load_controller->modes[mode_index].direction
|
||||
= temp_controller->modes[mode_index].direction;
|
||||
load_controller->modes[mode_index].color_mode
|
||||
= temp_controller->modes[mode_index].color_mode;
|
||||
|
||||
load_controller->modes[mode_index].colors.resize(temp_controller->modes[mode_index].colors.size());
|
||||
load_controller->modes[mode_index].colors.resize(
|
||||
temp_controller->modes[mode_index].colors.size());
|
||||
|
||||
for(std::size_t mode_color_index = 0; mode_color_index < temp_controller->modes[mode_index].colors.size(); mode_color_index++)
|
||||
{
|
||||
load_controller->modes[mode_index].colors[mode_color_index] = temp_controller->modes[mode_index].colors[mode_color_index];
|
||||
for (std::size_t mode_color_index = 0;
|
||||
mode_color_index < temp_controller->modes[mode_index].colors.size();
|
||||
mode_color_index++) {
|
||||
load_controller->modes[mode_index].colors[mode_color_index]
|
||||
= temp_controller->modes[mode_index].colors[mode_color_index];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
load_controller->active_mode = temp_controller->active_mode;
|
||||
@@ -363,32 +345,28 @@ bool ProfileManager::LoadDeviceFromListWithOptions
|
||||
/*---------------------------------------------------------*\
|
||||
| Update all colors |
|
||||
\*---------------------------------------------------------*/
|
||||
if(temp_controller->colors.size() == load_controller->colors.size())
|
||||
{
|
||||
for(std::size_t color_index = 0; color_index < temp_controller->colors.size(); color_index++)
|
||||
{
|
||||
if (temp_controller->colors.size() == load_controller->colors.size()) {
|
||||
for (std::size_t color_index = 0; color_index < temp_controller->colors.size();
|
||||
color_index++) {
|
||||
load_controller->colors[color_index] = temp_controller->colors[color_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool ProfileManager::LoadProfileWithOptions
|
||||
(
|
||||
std::string profile_name,
|
||||
bool load_size,
|
||||
bool load_settings
|
||||
)
|
||||
bool ProfileManager::LoadProfileWithOptions(std::string profile_name,
|
||||
bool load_size,
|
||||
bool load_settings)
|
||||
{
|
||||
std::vector<RGBController*> temp_controllers;
|
||||
std::vector<bool> temp_controller_used;
|
||||
bool ret_val = false;
|
||||
std::vector<RGBController *> temp_controllers;
|
||||
std::vector<bool> temp_controller_used;
|
||||
bool ret_val = false;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Get the list of controllers from the resource manager |
|
||||
@@ -405,8 +383,8 @@ bool ProfileManager::LoadProfileWithOptions
|
||||
\*---------------------------------------------------------*/
|
||||
temp_controller_used.resize(temp_controllers.size());
|
||||
|
||||
for(unsigned int controller_idx = 0; controller_idx < temp_controller_used.size(); controller_idx++)
|
||||
{
|
||||
for (unsigned int controller_idx = 0; controller_idx < temp_controller_used.size();
|
||||
controller_idx++) {
|
||||
temp_controller_used[controller_idx] = false;
|
||||
}
|
||||
|
||||
@@ -414,23 +392,30 @@ bool ProfileManager::LoadProfileWithOptions
|
||||
| Loop through all controllers. For each controller, search|
|
||||
| all saved controllers until a match is found |
|
||||
\*---------------------------------------------------------*/
|
||||
for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++)
|
||||
{
|
||||
bool temp_ret_val = LoadDeviceFromListWithOptions(temp_controllers, temp_controller_used, controllers[controller_index], load_size, load_settings);
|
||||
std::string current_name = controllers[controller_index]->name + " @ " + controllers[controller_index]->location;
|
||||
LOG_INFO("[ProfileManager] Profile loading: %s for %s", ( temp_ret_val ? "Succeeded" : "FAILED!" ), current_name.c_str());
|
||||
for (std::size_t controller_index = 0; controller_index < controllers.size();
|
||||
controller_index++) {
|
||||
bool temp_ret_val = LoadDeviceFromListWithOptions(temp_controllers,
|
||||
temp_controller_used,
|
||||
controllers[controller_index],
|
||||
load_size,
|
||||
load_settings);
|
||||
std::string current_name = controllers[controller_index]->name + " @ "
|
||||
+ controllers[controller_index]->location;
|
||||
LOG_INFO("[ProfileManager] Profile loading: %s for %s",
|
||||
(temp_ret_val ? "Succeeded" : "FAILED!"),
|
||||
current_name.c_str());
|
||||
ret_val |= temp_ret_val;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Delete all temporary controllers |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int controller_idx = 0; controller_idx < temp_controllers.size(); controller_idx++)
|
||||
{
|
||||
for (unsigned int controller_idx = 0; controller_idx < temp_controllers.size();
|
||||
controller_idx++) {
|
||||
delete temp_controllers[controller_idx];
|
||||
}
|
||||
|
||||
return(ret_val);
|
||||
return (ret_val);
|
||||
}
|
||||
|
||||
void ProfileManager::DeleteProfile(std::string profile_name)
|
||||
@@ -452,13 +437,12 @@ void ProfileManager::UpdateProfileList()
|
||||
/*---------------------------------------------------------*\
|
||||
| Load profiles by looking for .orp files in current dir |
|
||||
\*---------------------------------------------------------*/
|
||||
for(const auto & entry : filesystem::directory_iterator(configuration_directory))
|
||||
{
|
||||
for (const auto &entry : filesystem::directory_iterator(configuration_directory)) {
|
||||
std::string filename = entry.path().filename().string();
|
||||
|
||||
if(filename.find(".orp") != std::string::npos)
|
||||
{
|
||||
LOG_INFO("[ProfileManager] Found file: %s attempting to validate header", filename.c_str());
|
||||
if (filename.find(".orp") != std::string::npos) {
|
||||
LOG_INFO("[ProfileManager] Found file: %s attempting to validate header",
|
||||
filename.c_str());
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Open input file in binary mode |
|
||||
@@ -470,32 +454,33 @@ void ProfileManager::UpdateProfileList()
|
||||
/*---------------------------------------------------------*\
|
||||
| Read and verify file header |
|
||||
\*---------------------------------------------------------*/
|
||||
char profile_string[16];
|
||||
unsigned int profile_version;
|
||||
char profile_string[16];
|
||||
unsigned int profile_version;
|
||||
|
||||
profile_file.read(profile_string, 16);
|
||||
profile_file.read((char *)&profile_version, sizeof(unsigned int));
|
||||
profile_file.read((char *) &profile_version, sizeof(unsigned int));
|
||||
|
||||
if(strcmp(profile_string, OPENRGB_PROFILE_HEADER) == 0)
|
||||
{
|
||||
if(profile_version <= OPENRGB_PROFILE_VERSION)
|
||||
{
|
||||
if (strcmp(profile_string, OPENRGB_PROFILE_HEADER) == 0) {
|
||||
if (profile_version <= OPENRGB_PROFILE_VERSION) {
|
||||
/*---------------------------------------------------------*\
|
||||
| Add this profile to the list |
|
||||
\*---------------------------------------------------------*/
|
||||
filename.erase(filename.length() - 4);
|
||||
profile_list.push_back(filename);
|
||||
|
||||
LOG_INFO("[ProfileManager] Valid v%i profile found for %s", profile_version, filename.c_str());
|
||||
LOG_INFO("[ProfileManager] Valid v%i profile found for %s",
|
||||
profile_version,
|
||||
filename.c_str());
|
||||
} else {
|
||||
LOG_WARNING("[ProfileManager] Profile %s isn't valid for current version (v%i, "
|
||||
"expected v%i at most)",
|
||||
filename.c_str(),
|
||||
profile_version,
|
||||
OPENRGB_PROFILE_VERSION);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[ProfileManager] Profile %s isn't valid for current version (v%i, expected v%i at most)", filename.c_str(), profile_version, OPENRGB_PROFILE_VERSION);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("[ProfileManager] Profile %s isn't valid: header is missing", filename.c_str());
|
||||
} else {
|
||||
LOG_WARNING("[ProfileManager] Profile %s isn't valid: header is missing",
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
profile_file.close();
|
||||
@@ -503,7 +488,7 @@ void ProfileManager::UpdateProfileList()
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char * ProfileManager::GetProfileListDescription()
|
||||
unsigned char *ProfileManager::GetProfileListDescription()
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
@@ -511,15 +496,14 @@ unsigned char * ProfileManager::GetProfileListDescription()
|
||||
/*---------------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short num_profiles = (unsigned short)profile_list.size();
|
||||
unsigned short num_profiles = (unsigned short) profile_list.size();
|
||||
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(num_profiles);
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(num_profiles);
|
||||
|
||||
for(unsigned int i = 0; i < num_profiles; i++)
|
||||
{
|
||||
data_size += sizeof (unsigned short);
|
||||
data_size += (unsigned int)strlen(profile_list[i].c_str()) + 1;
|
||||
for (unsigned int i = 0; i < num_profiles; i++) {
|
||||
data_size += sizeof(unsigned short);
|
||||
data_size += (unsigned int) strlen(profile_list[i].c_str()) + 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
@@ -542,16 +526,15 @@ unsigned char * ProfileManager::GetProfileListDescription()
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in profile names (size+data) |
|
||||
\*---------------------------------------------------------*/
|
||||
for(unsigned int i = 0; i < num_profiles; i++)
|
||||
{
|
||||
unsigned short name_len = (unsigned short)strlen(profile_list[i].c_str()) + 1;
|
||||
for (unsigned int i = 0; i < num_profiles; i++) {
|
||||
unsigned short name_len = (unsigned short) strlen(profile_list[i].c_str()) + 1;
|
||||
|
||||
memcpy(&data_buf[data_ptr], &name_len, sizeof(name_len));
|
||||
data_ptr += sizeof(name_len);
|
||||
|
||||
strcpy((char *)&data_buf[data_ptr], profile_list[i].c_str());
|
||||
strcpy((char *) &data_buf[data_ptr], profile_list[i].c_str());
|
||||
data_ptr += name_len;
|
||||
}
|
||||
|
||||
return(data_buf);
|
||||
return (data_buf);
|
||||
}
|
||||
|
||||
@@ -15,81 +15,58 @@
|
||||
class ProfileManagerInterface
|
||||
{
|
||||
public:
|
||||
virtual bool SaveProfile
|
||||
(
|
||||
std::string profile_name,
|
||||
bool sizes = false
|
||||
) = 0;
|
||||
virtual bool LoadProfile(std::string profile_name) = 0;
|
||||
virtual bool LoadSizeFromProfile(std::string profile_name) = 0;
|
||||
virtual void DeleteProfile(std::string profile_name) = 0;
|
||||
virtual unsigned char * GetProfileListDescription() = 0;
|
||||
virtual bool SaveProfile(std::string profile_name, bool sizes = false) = 0;
|
||||
virtual bool LoadProfile(std::string profile_name) = 0;
|
||||
virtual bool LoadSizeFromProfile(std::string profile_name) = 0;
|
||||
virtual void DeleteProfile(std::string profile_name) = 0;
|
||||
virtual unsigned char *GetProfileListDescription() = 0;
|
||||
|
||||
std::vector<std::string> profile_list;
|
||||
|
||||
virtual bool LoadDeviceFromListWithOptions
|
||||
(
|
||||
std::vector<RGBController*>& temp_controllers,
|
||||
std::vector<bool>& temp_controller_used,
|
||||
RGBController* load_controller,
|
||||
bool load_size,
|
||||
bool load_settings
|
||||
) = 0;
|
||||
virtual bool LoadDeviceFromListWithOptions(std::vector<RGBController *> &temp_controllers,
|
||||
std::vector<bool> &temp_controller_used,
|
||||
RGBController *load_controller,
|
||||
bool load_size,
|
||||
bool load_settings)
|
||||
= 0;
|
||||
|
||||
virtual std::vector<RGBController*> LoadProfileToList
|
||||
(
|
||||
std::string profile_name,
|
||||
bool sizes = false
|
||||
) = 0;
|
||||
virtual std::vector<RGBController *> LoadProfileToList(std::string profile_name,
|
||||
bool sizes = false)
|
||||
= 0;
|
||||
|
||||
virtual void SetConfigurationDirectory(const filesystem::path &directory) = 0;
|
||||
|
||||
virtual void SetConfigurationDirectory(const filesystem::path& directory) = 0;
|
||||
protected:
|
||||
virtual ~ProfileManagerInterface() {};
|
||||
};
|
||||
|
||||
class ProfileManager: public ProfileManagerInterface
|
||||
class ProfileManager : public ProfileManagerInterface
|
||||
{
|
||||
public:
|
||||
ProfileManager(const filesystem::path& config_dir);
|
||||
ProfileManager(const filesystem::path &config_dir);
|
||||
~ProfileManager();
|
||||
|
||||
bool SaveProfile
|
||||
(
|
||||
std::string profile_name,
|
||||
bool sizes = false
|
||||
);
|
||||
bool SaveProfile(std::string profile_name, bool sizes = false);
|
||||
bool LoadProfile(std::string profile_name);
|
||||
bool LoadSizeFromProfile(std::string profile_name);
|
||||
void DeleteProfile(std::string profile_name);
|
||||
unsigned char * GetProfileListDescription();
|
||||
unsigned char *GetProfileListDescription();
|
||||
|
||||
std::vector<std::string> profile_list;
|
||||
|
||||
bool LoadDeviceFromListWithOptions
|
||||
(
|
||||
std::vector<RGBController*>& temp_controllers,
|
||||
std::vector<bool>& temp_controller_used,
|
||||
RGBController* load_controller,
|
||||
bool load_size,
|
||||
bool load_settings
|
||||
);
|
||||
bool LoadDeviceFromListWithOptions(std::vector<RGBController *> &temp_controllers,
|
||||
std::vector<bool> &temp_controller_used,
|
||||
RGBController *load_controller,
|
||||
bool load_size,
|
||||
bool load_settings);
|
||||
|
||||
std::vector<RGBController*> LoadProfileToList
|
||||
(
|
||||
std::string profile_name,
|
||||
bool sizes = false
|
||||
);
|
||||
std::vector<RGBController *> LoadProfileToList(std::string profile_name, bool sizes = false);
|
||||
|
||||
void SetConfigurationDirectory(const filesystem::path& directory);
|
||||
void SetConfigurationDirectory(const filesystem::path &directory);
|
||||
|
||||
private:
|
||||
filesystem::path configuration_directory;
|
||||
|
||||
void UpdateProfileList();
|
||||
bool LoadProfileWithOptions
|
||||
(
|
||||
std::string profile_name,
|
||||
bool load_size,
|
||||
bool load_settings
|
||||
);
|
||||
bool LoadProfileWithOptions(std::string profile_name, bool load_size, bool load_settings);
|
||||
};
|
||||
|
||||
1142
ResourceManager.cpp
1142
ResourceManager.cpp
File diff suppressed because it is too large
Load Diff
@@ -28,9 +28,9 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#define HID_INTERFACE_ANY -1
|
||||
#define HID_USAGE_ANY -1
|
||||
#define HID_USAGE_PAGE_ANY -1L
|
||||
#define HID_INTERFACE_ANY -1
|
||||
#define HID_USAGE_ANY -1
|
||||
#define HID_USAGE_PAGE_ANY -1L
|
||||
|
||||
#define CONTROLLER_LIST_HID 0
|
||||
|
||||
@@ -41,58 +41,61 @@ class ProfileManager;
|
||||
class RGBController;
|
||||
class SettingsManager;
|
||||
|
||||
typedef std::function<bool()> I2CBusDetectorFunction;
|
||||
typedef std::function<void()> DeviceDetectorFunction;
|
||||
typedef std::function<void(std::vector<i2c_smbus_interface*>&)> I2CDeviceDetectorFunction;
|
||||
typedef std::function<void(i2c_smbus_interface*, std::vector<SPDWrapper*>&)> I2CDIMMDeviceDetectorFunction;
|
||||
typedef std::function<void(i2c_smbus_interface*, uint8_t, const std::string&)> I2CPCIDeviceDetectorFunction;
|
||||
typedef std::function<void(hid_device_info*, const std::string&)> HIDDeviceDetectorFunction;
|
||||
typedef std::function<void(hidapi_wrapper wrapper, hid_device_info*, const std::string&)> HIDWrappedDeviceDetectorFunction;
|
||||
typedef std::function<void()> DynamicDetectorFunction;
|
||||
typedef std::function<void()> PreDetectionHookFunction;
|
||||
typedef std::function<bool()> I2CBusDetectorFunction;
|
||||
typedef std::function<void()> DeviceDetectorFunction;
|
||||
typedef std::function<void(std::vector<i2c_smbus_interface *> &)> I2CDeviceDetectorFunction;
|
||||
typedef std::function<void(i2c_smbus_interface *, std::vector<SPDWrapper *> &)>
|
||||
I2CDIMMDeviceDetectorFunction;
|
||||
typedef std::function<void(i2c_smbus_interface *, uint8_t, const std::string &)>
|
||||
I2CPCIDeviceDetectorFunction;
|
||||
typedef std::function<void(hid_device_info *, const std::string &)> HIDDeviceDetectorFunction;
|
||||
typedef std::function<void(hidapi_wrapper wrapper, hid_device_info *, const std::string &)>
|
||||
HIDWrappedDeviceDetectorFunction;
|
||||
typedef std::function<void()> DynamicDetectorFunction;
|
||||
typedef std::function<void()> PreDetectionHookFunction;
|
||||
|
||||
class BasicHIDBlock
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
uint16_t vid;
|
||||
uint16_t pid;
|
||||
int interface;
|
||||
int usage_page;
|
||||
int usage;
|
||||
std::string name;
|
||||
uint16_t vid;
|
||||
uint16_t pid;
|
||||
int interface;
|
||||
int usage_page;
|
||||
int usage;
|
||||
|
||||
bool compare(hid_device_info* info);
|
||||
bool compare(hid_device_info *info);
|
||||
};
|
||||
|
||||
class HIDDeviceDetectorBlock : public BasicHIDBlock
|
||||
{
|
||||
public:
|
||||
HIDDeviceDetectorFunction function;
|
||||
HIDDeviceDetectorFunction function;
|
||||
};
|
||||
|
||||
class HIDWrappedDeviceDetectorBlock : public BasicHIDBlock
|
||||
{
|
||||
public:
|
||||
HIDWrappedDeviceDetectorFunction function;
|
||||
HIDWrappedDeviceDetectorFunction function;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name;
|
||||
I2CPCIDeviceDetectorFunction function;
|
||||
uint16_t ven_id;
|
||||
uint16_t dev_id;
|
||||
uint16_t subven_id;
|
||||
uint16_t subdev_id;
|
||||
uint8_t i2c_addr;
|
||||
std::string name;
|
||||
I2CPCIDeviceDetectorFunction function;
|
||||
uint16_t ven_id;
|
||||
uint16_t dev_id;
|
||||
uint16_t subven_id;
|
||||
uint16_t subdev_id;
|
||||
uint8_t i2c_addr;
|
||||
} I2CPCIDeviceDetectorBlock;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name;
|
||||
I2CDIMMDeviceDetectorFunction function;
|
||||
uint16_t jedec_id;
|
||||
uint8_t dimm_type;
|
||||
std::string name;
|
||||
I2CDIMMDeviceDetectorFunction function;
|
||||
uint16_t jedec_id;
|
||||
uint8_t dimm_type;
|
||||
} I2CDIMMDeviceDetectorBlock;
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
@@ -100,12 +103,12 @@ typedef struct
|
||||
\*-------------------------------------------------------------------------*/
|
||||
#define QT_TRANSLATE_NOOP(scope, x) x
|
||||
|
||||
extern const char* I2C_ERR_WIN;
|
||||
extern const char* I2C_ERR_LINUX;
|
||||
extern const char* UDEV_MISSING;
|
||||
extern const char* UDEV_MULTI;
|
||||
extern const char *I2C_ERR_WIN;
|
||||
extern const char *I2C_ERR_LINUX;
|
||||
extern const char *UDEV_MISSING;
|
||||
extern const char *UDEV_MULTI;
|
||||
|
||||
class ResourceManager: public ResourceManagerInterface
|
||||
class ResourceManager : public ResourceManagerInterface
|
||||
{
|
||||
public:
|
||||
static ResourceManager *get();
|
||||
@@ -114,63 +117,75 @@ public:
|
||||
~ResourceManager();
|
||||
|
||||
void RegisterI2CBus(i2c_smbus_interface *);
|
||||
std::vector<i2c_smbus_interface*> & GetI2CBusses();
|
||||
std::vector<i2c_smbus_interface *> &GetI2CBusses();
|
||||
|
||||
void RegisterRGBController(RGBController *rgb_controller);
|
||||
void UnregisterRGBController(RGBController *rgb_controller);
|
||||
|
||||
std::vector<RGBController*> & GetRGBControllers();
|
||||
std::vector<RGBController *> &GetRGBControllers();
|
||||
|
||||
void RegisterI2CBusDetector (I2CBusDetectorFunction detector);
|
||||
void RegisterDeviceDetector (std::string name, DeviceDetectorFunction detector);
|
||||
void RegisterI2CDeviceDetector (std::string name, I2CDeviceDetectorFunction detector);
|
||||
void RegisterI2CDIMMDeviceDetector (std::string name, I2CDIMMDeviceDetectorFunction detector, uint16_t jedec_id, uint8_t dimm_type);
|
||||
void RegisterI2CPCIDeviceDetector (std::string name, I2CPCIDeviceDetectorFunction detector, uint16_t ven_id, uint16_t dev_id, uint16_t subven_id, uint16_t subdev_id, uint8_t i2c_addr);
|
||||
void RegisterHIDDeviceDetector (std::string name,
|
||||
HIDDeviceDetectorFunction detector,
|
||||
uint16_t vid,
|
||||
uint16_t pid,
|
||||
int interface = HID_INTERFACE_ANY,
|
||||
int usage_page = HID_USAGE_PAGE_ANY,
|
||||
int usage = HID_USAGE_ANY);
|
||||
void RegisterHIDWrappedDeviceDetector (std::string name,
|
||||
HIDWrappedDeviceDetectorFunction detector,
|
||||
uint16_t vid,
|
||||
uint16_t pid,
|
||||
int interface = HID_INTERFACE_ANY,
|
||||
int usage_page = HID_USAGE_PAGE_ANY,
|
||||
int usage = HID_USAGE_ANY);
|
||||
void RegisterDynamicDetector (std::string name, DynamicDetectorFunction detector);
|
||||
void RegisterPreDetectionHook (PreDetectionHookFunction hook);
|
||||
void RegisterI2CBusDetector(I2CBusDetectorFunction detector);
|
||||
void RegisterDeviceDetector(std::string name, DeviceDetectorFunction detector);
|
||||
void RegisterI2CDeviceDetector(std::string name, I2CDeviceDetectorFunction detector);
|
||||
void RegisterI2CDIMMDeviceDetector(std::string name,
|
||||
I2CDIMMDeviceDetectorFunction detector,
|
||||
uint16_t jedec_id,
|
||||
uint8_t dimm_type);
|
||||
void RegisterI2CPCIDeviceDetector(std::string name,
|
||||
I2CPCIDeviceDetectorFunction detector,
|
||||
uint16_t ven_id,
|
||||
uint16_t dev_id,
|
||||
uint16_t subven_id,
|
||||
uint16_t subdev_id,
|
||||
uint8_t i2c_addr);
|
||||
void RegisterHIDDeviceDetector(std::string name,
|
||||
HIDDeviceDetectorFunction detector,
|
||||
uint16_t vid,
|
||||
uint16_t pid,
|
||||
int interface = HID_INTERFACE_ANY,
|
||||
int usage_page = HID_USAGE_PAGE_ANY,
|
||||
int usage = HID_USAGE_ANY);
|
||||
void RegisterHIDWrappedDeviceDetector(std::string name,
|
||||
HIDWrappedDeviceDetectorFunction detector,
|
||||
uint16_t vid,
|
||||
uint16_t pid,
|
||||
int interface = HID_INTERFACE_ANY,
|
||||
int usage_page = HID_USAGE_PAGE_ANY,
|
||||
int usage = HID_USAGE_ANY);
|
||||
void RegisterDynamicDetector(std::string name, DynamicDetectorFunction detector);
|
||||
void RegisterPreDetectionHook(PreDetectionHookFunction hook);
|
||||
|
||||
void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg);
|
||||
void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void * new_callback_arg);
|
||||
void RegisterDetectionStartCallback(DetectionStartCallback new_callback, void * new_callback_arg);
|
||||
void RegisterDetectionEndCallback(DetectionEndCallback new_callback, void * new_callback_arg);
|
||||
void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback, void * new_callback_arg);
|
||||
void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback,
|
||||
void *new_callback_arg);
|
||||
void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback,
|
||||
void *new_callback_arg);
|
||||
void RegisterDetectionStartCallback(DetectionStartCallback new_callback, void *new_callback_arg);
|
||||
void RegisterDetectionEndCallback(DetectionEndCallback new_callback, void *new_callback_arg);
|
||||
void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback,
|
||||
void *new_callback_arg);
|
||||
|
||||
void UnregisterDeviceListChangeCallback(DeviceListChangeCallback callback, void * callback_arg);
|
||||
void UnregisterDeviceListChangeCallback(DeviceListChangeCallback callback, void *callback_arg);
|
||||
void UnregisterDetectionProgressCallback(DetectionProgressCallback callback, void *callback_arg);
|
||||
void UnregisterDetectionStartCallback(DetectionStartCallback callback, void *callback_arg);
|
||||
void UnregisterDetectionEndCallback(DetectionEndCallback callback, void *callback_arg);
|
||||
void UnregisterI2CBusListChangeCallback(I2CBusListChangeCallback callback, void * callback_arg);
|
||||
void UnregisterI2CBusListChangeCallback(I2CBusListChangeCallback callback, void *callback_arg);
|
||||
|
||||
bool GetDetectionEnabled();
|
||||
bool GetDetectionEnabled();
|
||||
unsigned int GetDetectionPercent();
|
||||
const char* GetDetectionString();
|
||||
const char *GetDetectionString();
|
||||
|
||||
filesystem::path GetConfigurationDirectory();
|
||||
filesystem::path GetConfigurationDirectory();
|
||||
|
||||
void RegisterNetworkClient(NetworkClient* new_client);
|
||||
void UnregisterNetworkClient(NetworkClient* network_client);
|
||||
void RegisterNetworkClient(NetworkClient *new_client);
|
||||
void UnregisterNetworkClient(NetworkClient *network_client);
|
||||
|
||||
std::vector<NetworkClient*>& GetClients();
|
||||
NetworkServer* GetServer();
|
||||
std::vector<NetworkClient *> &GetClients();
|
||||
NetworkServer *GetServer();
|
||||
|
||||
ProfileManager* GetProfileManager();
|
||||
SettingsManager* GetSettingsManager();
|
||||
ProfileManager *GetProfileManager();
|
||||
SettingsManager *GetSettingsManager();
|
||||
|
||||
void SetConfigurationDirectory(const filesystem::path &directory);
|
||||
void SetConfigurationDirectory(const filesystem::path &directory);
|
||||
|
||||
void ProcessPreDetectionHooks(); // Consider making private
|
||||
void ProcessDynamicDetectors(); // Consider making private
|
||||
@@ -213,125 +228,125 @@ private:
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Static pointer to shared instance of ResourceManager |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
static ResourceManager* instance;
|
||||
static ResourceManager *instance;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Auto connection permitting flag |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
bool tryAutoConnect;
|
||||
bool tryAutoConnect;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Detection enabled flag |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
bool detection_enabled;
|
||||
bool detection_enabled;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Auto connection permitting flag |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
bool start_server;
|
||||
bool start_server;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Auto connection permitting flag |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
bool apply_post_options;
|
||||
bool apply_post_options;
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Initialization completion flag |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::atomic<bool> init_finished;
|
||||
std::atomic<bool> init_finished;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Profile Manager |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
ProfileManager* profile_manager;
|
||||
ProfileManager *profile_manager;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Settings Manager |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
SettingsManager* settings_manager;
|
||||
SettingsManager *settings_manager;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| I2C/SMBus Interfaces |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::vector<i2c_smbus_interface*> busses;
|
||||
std::vector<i2c_smbus_interface *> busses;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| RGBControllers |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::vector<RGBController*> rgb_controllers_sizes;
|
||||
std::vector<RGBController*> rgb_controllers_hw;
|
||||
std::vector<RGBController*> rgb_controllers;
|
||||
std::vector<RGBController *> rgb_controllers_sizes;
|
||||
std::vector<RGBController *> rgb_controllers_hw;
|
||||
std::vector<RGBController *> rgb_controllers;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Network Server |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
NetworkServer* server;
|
||||
NetworkServer *server;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Network Clients |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::vector<NetworkClient*> clients;
|
||||
std::vector<NetworkClient *> clients;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Detectors |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::vector<DeviceDetectorFunction> device_detectors;
|
||||
std::vector<std::string> device_detector_strings;
|
||||
std::vector<I2CBusDetectorFunction> i2c_bus_detectors;
|
||||
std::vector<I2CDeviceDetectorFunction> i2c_device_detectors;
|
||||
std::vector<std::string> i2c_device_detector_strings;
|
||||
std::vector<I2CDIMMDeviceDetectorBlock> i2c_dimm_device_detectors;
|
||||
std::vector<I2CPCIDeviceDetectorBlock> i2c_pci_device_detectors;
|
||||
std::vector<HIDDeviceDetectorBlock> hid_device_detectors;
|
||||
std::vector<HIDWrappedDeviceDetectorBlock> hid_wrapped_device_detectors;
|
||||
std::vector<DynamicDetectorFunction> dynamic_detectors;
|
||||
std::vector<std::string> dynamic_detector_strings;
|
||||
std::vector<PreDetectionHookFunction> pre_detection_hooks;
|
||||
std::vector<DeviceDetectorFunction> device_detectors;
|
||||
std::vector<std::string> device_detector_strings;
|
||||
std::vector<I2CBusDetectorFunction> i2c_bus_detectors;
|
||||
std::vector<I2CDeviceDetectorFunction> i2c_device_detectors;
|
||||
std::vector<std::string> i2c_device_detector_strings;
|
||||
std::vector<I2CDIMMDeviceDetectorBlock> i2c_dimm_device_detectors;
|
||||
std::vector<I2CPCIDeviceDetectorBlock> i2c_pci_device_detectors;
|
||||
std::vector<HIDDeviceDetectorBlock> hid_device_detectors;
|
||||
std::vector<HIDWrappedDeviceDetectorBlock> hid_wrapped_device_detectors;
|
||||
std::vector<DynamicDetectorFunction> dynamic_detectors;
|
||||
std::vector<std::string> dynamic_detector_strings;
|
||||
std::vector<PreDetectionHookFunction> pre_detection_hooks;
|
||||
|
||||
bool dynamic_detectors_processed;
|
||||
bool dynamic_detectors_processed;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Detection Thread and Detection State |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::thread * DetectDevicesThread;
|
||||
std::mutex DetectDeviceMutex;
|
||||
std::function<void()> ScheduledBackgroundFunction;
|
||||
std::mutex BackgroundThreadStateMutex;
|
||||
std::condition_variable BackgroundFunctionStartTrigger; // NOTE: wakes up the background detection thread
|
||||
|
||||
std::atomic<bool> background_thread_running;
|
||||
std::atomic<bool> detection_is_required;
|
||||
std::atomic<unsigned int> detection_percent;
|
||||
std::atomic<unsigned int> detection_prev_size;
|
||||
std::vector<bool> detection_size_entry_used;
|
||||
const char* detection_string;
|
||||
std::thread *DetectDevicesThread;
|
||||
std::mutex DetectDeviceMutex;
|
||||
std::function<void()> ScheduledBackgroundFunction;
|
||||
std::mutex BackgroundThreadStateMutex;
|
||||
std::condition_variable
|
||||
BackgroundFunctionStartTrigger; // NOTE: wakes up the background detection thread
|
||||
|
||||
std::atomic<bool> background_thread_running;
|
||||
std::atomic<bool> detection_is_required;
|
||||
std::atomic<unsigned int> detection_percent;
|
||||
std::atomic<unsigned int> detection_prev_size;
|
||||
std::vector<bool> detection_size_entry_used;
|
||||
const char *detection_string;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Device List Changed Callback |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::mutex DeviceListChangeMutex;
|
||||
std::vector<DeviceListChangeCallback> DeviceListChangeCallbacks;
|
||||
std::vector<void *> DeviceListChangeCallbackArgs;
|
||||
std::mutex DeviceListChangeMutex;
|
||||
std::vector<DeviceListChangeCallback> DeviceListChangeCallbacks;
|
||||
std::vector<void *> DeviceListChangeCallbackArgs;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| Detection Progress, Start, and End Callbacks |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::mutex DetectionProgressMutex;
|
||||
std::vector<DetectionProgressCallback> DetectionProgressCallbacks;
|
||||
std::vector<void *> DetectionProgressCallbackArgs;
|
||||
std::mutex DetectionProgressMutex;
|
||||
std::vector<DetectionProgressCallback> DetectionProgressCallbacks;
|
||||
std::vector<void *> DetectionProgressCallbackArgs;
|
||||
|
||||
std::vector<DetectionStartCallback> DetectionStartCallbacks;
|
||||
std::vector<void *> DetectionStartCallbackArgs;
|
||||
std::vector<DetectionStartCallback> DetectionStartCallbacks;
|
||||
std::vector<void *> DetectionStartCallbackArgs;
|
||||
|
||||
std::vector<DetectionEndCallback> DetectionEndCallbacks;
|
||||
std::vector<void *> DetectionEndCallbackArgs;
|
||||
std::vector<DetectionEndCallback> DetectionEndCallbacks;
|
||||
std::vector<void *> DetectionEndCallbackArgs;
|
||||
|
||||
/*-------------------------------------------------------------------------------------*\
|
||||
| I2C/SMBus Adapter List Changed Callback |
|
||||
\*-------------------------------------------------------------------------------------*/
|
||||
std::mutex I2CBusListChangeMutex;
|
||||
std::vector<I2CBusListChangeCallback> I2CBusListChangeCallbacks;
|
||||
std::vector<void *> I2CBusListChangeCallbackArgs;
|
||||
std::mutex I2CBusListChangeMutex;
|
||||
std::vector<I2CBusListChangeCallback> I2CBusListChangeCallbacks;
|
||||
std::vector<void *> I2CBusListChangeCallbackArgs;
|
||||
|
||||
filesystem::path config_dir;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "i2c_smbus.h"
|
||||
#include "filesystem.h"
|
||||
#include "i2c_smbus.h"
|
||||
#include <vector>
|
||||
|
||||
class NetworkClient;
|
||||
class NetworkServer;
|
||||
@@ -19,38 +19,57 @@ typedef void (*I2CBusListChangeCallback)(void *);
|
||||
class ResourceManagerInterface
|
||||
{
|
||||
public:
|
||||
virtual std::vector<i2c_smbus_interface*> & GetI2CBusses() = 0;
|
||||
virtual std::vector<i2c_smbus_interface *> &GetI2CBusses() = 0;
|
||||
|
||||
virtual void RegisterRGBController(RGBController *rgb_controller) = 0;
|
||||
virtual void UnregisterRGBController(RGBController *rgb_controller) = 0;
|
||||
virtual void RegisterRGBController(RGBController *rgb_controller) = 0;
|
||||
virtual void UnregisterRGBController(RGBController *rgb_controller) = 0;
|
||||
|
||||
virtual void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg) = 0;
|
||||
virtual void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void * new_callback_arg) = 0;
|
||||
virtual void RegisterDetectionStartCallback(DetectionStartCallback new_callback, void * new_callback_arg) = 0;
|
||||
virtual void RegisterDetectionEndCallback(DetectionEndCallback new_callback, void * new_callback_arg) = 0;
|
||||
virtual void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback, void * new_callback_arg) = 0;
|
||||
virtual void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback,
|
||||
void *new_callback_arg)
|
||||
= 0;
|
||||
virtual void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback,
|
||||
void *new_callback_arg)
|
||||
= 0;
|
||||
virtual void RegisterDetectionStartCallback(DetectionStartCallback new_callback,
|
||||
void *new_callback_arg)
|
||||
= 0;
|
||||
virtual void RegisterDetectionEndCallback(DetectionEndCallback new_callback,
|
||||
void *new_callback_arg)
|
||||
= 0;
|
||||
virtual void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback,
|
||||
void *new_callback_arg)
|
||||
= 0;
|
||||
|
||||
virtual void UnregisterDeviceListChangeCallback(DeviceListChangeCallback callback, void * callback_arg) = 0;
|
||||
virtual void UnregisterDetectionProgressCallback(DetectionProgressCallback callback, void *callback_arg) = 0;
|
||||
virtual void UnregisterDetectionStartCallback(DetectionStartCallback callback, void *callback_arg) = 0;
|
||||
virtual void UnregisterDetectionEndCallback(DetectionEndCallback callback, void *callback_arg) = 0;
|
||||
virtual void UnregisterI2CBusListChangeCallback(I2CBusListChangeCallback callback, void * callback_arg) = 0;
|
||||
virtual void UnregisterDeviceListChangeCallback(DeviceListChangeCallback callback,
|
||||
void *callback_arg)
|
||||
= 0;
|
||||
virtual void UnregisterDetectionProgressCallback(DetectionProgressCallback callback,
|
||||
void *callback_arg)
|
||||
= 0;
|
||||
virtual void UnregisterDetectionStartCallback(DetectionStartCallback callback,
|
||||
void *callback_arg)
|
||||
= 0;
|
||||
virtual void UnregisterDetectionEndCallback(DetectionEndCallback callback, void *callback_arg)
|
||||
= 0;
|
||||
virtual void UnregisterI2CBusListChangeCallback(I2CBusListChangeCallback callback,
|
||||
void *callback_arg)
|
||||
= 0;
|
||||
|
||||
virtual std::vector<RGBController*> & GetRGBControllers() = 0;
|
||||
virtual std::vector<RGBController *> &GetRGBControllers() = 0;
|
||||
|
||||
virtual unsigned int GetDetectionPercent() = 0;
|
||||
virtual unsigned int GetDetectionPercent() = 0;
|
||||
|
||||
virtual filesystem::path GetConfigurationDirectory() = 0;
|
||||
virtual filesystem::path GetConfigurationDirectory() = 0;
|
||||
|
||||
virtual std::vector<NetworkClient*>& GetClients() = 0;
|
||||
virtual NetworkServer* GetServer() = 0;
|
||||
virtual std::vector<NetworkClient *> &GetClients() = 0;
|
||||
virtual NetworkServer *GetServer() = 0;
|
||||
|
||||
virtual ProfileManager* GetProfileManager() = 0;
|
||||
virtual SettingsManager* GetSettingsManager() = 0;
|
||||
virtual ProfileManager *GetProfileManager() = 0;
|
||||
virtual SettingsManager *GetSettingsManager() = 0;
|
||||
|
||||
virtual void UpdateDeviceList() = 0;
|
||||
virtual void WaitForDeviceDetection() = 0;
|
||||
virtual void UpdateDeviceList() = 0;
|
||||
virtual void WaitForDeviceDetection() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~ResourceManagerInterface() {};
|
||||
virtual ~ResourceManagerInterface() {};
|
||||
};
|
||||
|
||||
@@ -21,10 +21,7 @@ SettingsManager::SettingsManager()
|
||||
config_found = false;
|
||||
}
|
||||
|
||||
SettingsManager::~SettingsManager()
|
||||
{
|
||||
|
||||
}
|
||||
SettingsManager::~SettingsManager() {}
|
||||
|
||||
json SettingsManager::GetSettings(std::string settings_key)
|
||||
{
|
||||
@@ -37,8 +34,7 @@ json SettingsManager::GetSettings(std::string settings_key)
|
||||
json result;
|
||||
|
||||
mutex.lock();
|
||||
if(settings_data.contains(settings_key))
|
||||
{
|
||||
if (settings_data.contains(settings_key)) {
|
||||
result = settings_data[settings_key];
|
||||
}
|
||||
|
||||
@@ -54,7 +50,7 @@ void SettingsManager::SetSettings(std::string settings_key, json new_settings)
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void SettingsManager::LoadSettings(const filesystem::path& filename)
|
||||
void SettingsManager::LoadSettings(const filesystem::path &filename)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Clear any stored settings before loading |
|
||||
@@ -72,21 +68,16 @@ void SettingsManager::LoadSettings(const filesystem::path& filename)
|
||||
| Open input file in binary mode |
|
||||
\*---------------------------------------------------------*/
|
||||
config_found = filesystem::exists(filename);
|
||||
if(config_found)
|
||||
{
|
||||
if (config_found) {
|
||||
std::ifstream settings_file(settings_filename, std::ios::in | std::ios::binary);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Read settings into JSON store |
|
||||
\*---------------------------------------------------------*/
|
||||
if(settings_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (settings_file) {
|
||||
try {
|
||||
settings_file >> settings_data;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
} catch (const std::exception &e) {
|
||||
/*-------------------------------------------------*\
|
||||
| If an exception was caught, that means the JSON |
|
||||
| parsing failed. Clear out any data in the store |
|
||||
@@ -110,14 +101,10 @@ void SettingsManager::SaveSettings()
|
||||
mutex.lock();
|
||||
std::ofstream settings_file(settings_filename, std::ios::out | std::ios::binary);
|
||||
|
||||
if(settings_file)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (settings_file) {
|
||||
try {
|
||||
settings_file << settings_data.dump(4);
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
} catch (const std::exception &e) {
|
||||
LOG_ERROR("[SettingsManager] Cannot write to file: %s", e.what());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,17 @@ using json = nlohmann::json;
|
||||
class SettingsManagerInterface
|
||||
{
|
||||
public:
|
||||
virtual json GetSettings(std::string settings_key) = 0;
|
||||
virtual void SetSettings(std::string settings_key, json new_settings) = 0;
|
||||
virtual json GetSettings(std::string settings_key) = 0;
|
||||
virtual void SetSettings(std::string settings_key, json new_settings) = 0;
|
||||
|
||||
virtual void LoadSettings(const filesystem::path& filename) = 0;
|
||||
virtual void SaveSettings() = 0;
|
||||
virtual void LoadSettings(const filesystem::path &filename) = 0;
|
||||
virtual void SaveSettings() = 0;
|
||||
|
||||
protected:
|
||||
virtual ~SettingsManagerInterface() {};
|
||||
};
|
||||
|
||||
class SettingsManager: public SettingsManagerInterface
|
||||
class SettingsManager : public SettingsManagerInterface
|
||||
{
|
||||
public:
|
||||
SettingsManager();
|
||||
@@ -41,13 +41,13 @@ public:
|
||||
json GetSettings(std::string settings_key) override;
|
||||
void SetSettings(std::string settings_key, json new_settings) override;
|
||||
|
||||
void LoadSettings(const filesystem::path& filename) override;
|
||||
void LoadSettings(const filesystem::path &filename) override;
|
||||
void SaveSettings() override;
|
||||
|
||||
private:
|
||||
json settings_data;
|
||||
json settings_prototype;
|
||||
json settings_data;
|
||||
json settings_prototype;
|
||||
filesystem::path settings_filename;
|
||||
std::mutex mutex;
|
||||
bool config_found;
|
||||
std::mutex mutex;
|
||||
bool config_found;
|
||||
};
|
||||
|
||||
@@ -12,36 +12,32 @@
|
||||
#include <string>
|
||||
#include "StringUtils.h"
|
||||
|
||||
const char* StringUtils::wchar_to_char(const wchar_t* pwchar)
|
||||
const char *StringUtils::wchar_to_char(const wchar_t *pwchar)
|
||||
{
|
||||
if (pwchar == nullptr)
|
||||
{
|
||||
if (pwchar == nullptr) {
|
||||
return "";
|
||||
}
|
||||
// get the number of characters in the string.
|
||||
int currentCharIndex = 0;
|
||||
char currentChar = (char)pwchar[currentCharIndex];
|
||||
char currentChar = (char) pwchar[currentCharIndex];
|
||||
|
||||
while (currentChar != '\0')
|
||||
{
|
||||
while (currentChar != '\0') {
|
||||
currentCharIndex++;
|
||||
currentChar = (char)pwchar[currentCharIndex];
|
||||
currentChar = (char) pwchar[currentCharIndex];
|
||||
}
|
||||
|
||||
const int charCount = currentCharIndex + 1;
|
||||
|
||||
// allocate a new block of memory size char (1 byte) instead of wide char (2 bytes)
|
||||
char* filePathC = (char*)malloc(sizeof(char) * charCount);
|
||||
char *filePathC = (char *) malloc(sizeof(char) * charCount);
|
||||
|
||||
for (int i = 0; i < charCount; i++)
|
||||
{
|
||||
for (int i = 0; i < charCount; i++) {
|
||||
// convert to char (1 byte)
|
||||
char character = (char)pwchar[i];
|
||||
char character = (char) pwchar[i];
|
||||
|
||||
*filePathC = character;
|
||||
|
||||
filePathC += sizeof(char);
|
||||
|
||||
}
|
||||
filePathC += '\0';
|
||||
|
||||
@@ -54,23 +50,21 @@ std::string StringUtils::wstring_to_string(const std::wstring wstring)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
|
||||
|
||||
return(converter.to_bytes(wstring));
|
||||
return (converter.to_bytes(wstring));
|
||||
}
|
||||
|
||||
std::string StringUtils::u16string_to_string(const std::u16string wstring)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> converter;
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
|
||||
|
||||
return(converter.to_bytes(wstring));
|
||||
return (converter.to_bytes(wstring));
|
||||
}
|
||||
|
||||
const std::string StringUtils::remove_null_terminating_chars(std::string input)
|
||||
{
|
||||
while (!input.empty() && input.back() == 0)
|
||||
{
|
||||
while (!input.empty() && input.back() == 0) {
|
||||
input.pop_back();
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
class StringUtils
|
||||
{
|
||||
public:
|
||||
static const char* wchar_to_char(const wchar_t* pwchar);
|
||||
static const char *wchar_to_char(const wchar_t *pwchar);
|
||||
static std::string wstring_to_string(const std::wstring wstring);
|
||||
static std::string u16string_to_string(const std::u16string wstring);
|
||||
static const std::string remove_null_terminating_chars(std::string input);
|
||||
|
||||
19
cli.h
19
cli.h
@@ -1,19 +1,18 @@
|
||||
#ifndef CLI_H
|
||||
#define CLI_H
|
||||
|
||||
unsigned int cli_pre_detection(int argc, char* argv[]);
|
||||
unsigned int cli_pre_detection(int argc, char *argv[]);
|
||||
unsigned int cli_post_detection();
|
||||
|
||||
enum
|
||||
{
|
||||
RET_FLAG_PRINT_HELP = 1,
|
||||
RET_FLAG_START_GUI = 2,
|
||||
RET_FLAG_I2C_TOOLS = 4,
|
||||
RET_FLAG_START_MINIMIZED = 8,
|
||||
RET_FLAG_NO_DETECT = 16,
|
||||
enum {
|
||||
RET_FLAG_PRINT_HELP = 1,
|
||||
RET_FLAG_START_GUI = 2,
|
||||
RET_FLAG_I2C_TOOLS = 4,
|
||||
RET_FLAG_START_MINIMIZED = 8,
|
||||
RET_FLAG_NO_DETECT = 16,
|
||||
RET_FLAG_CLI_POST_DETECTION = 32,
|
||||
RET_FLAG_START_SERVER = 64,
|
||||
RET_FLAG_NO_AUTO_CONNECT = 128,
|
||||
RET_FLAG_START_SERVER = 64,
|
||||
RET_FLAG_NO_AUTO_CONNECT = 128,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
// Debian 10 provides the header, but does not enable the feature, so we additionally check for the feature test macro
|
||||
// MSVC below 2017 does not provide feature test macros, so we leave an exception for them
|
||||
#if defined(__cpp_lib_filesystem) || defined (_MSC_VER)
|
||||
#if defined(__cpp_lib_filesystem) || defined(_MSC_VER)
|
||||
namespace filesystem = std::filesystem;
|
||||
#define STD_FILESYSTEM_FOUND
|
||||
#endif
|
||||
|
||||
157
main.cpp
157
main.cpp
@@ -47,28 +47,33 @@ using namespace std::chrono_literals;
|
||||
void InitializeTimerResolution()
|
||||
{
|
||||
HMODULE ntdll = LoadLibrary("ntdll.dll");
|
||||
if(ntdll != NULL)
|
||||
{
|
||||
typedef LONG (*NTSETTIMERRESOLUTION)(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);
|
||||
if (ntdll != NULL) {
|
||||
typedef LONG (*NTSETTIMERRESOLUTION)(ULONG DesiredResolution,
|
||||
BOOLEAN SetResolution,
|
||||
PULONG CurrentResolution);
|
||||
ULONG CurrentResolution;
|
||||
NTSETTIMERRESOLUTION NtSetTimerResolution = (NTSETTIMERRESOLUTION)GetProcAddress(ntdll, "NtSetTimerResolution");
|
||||
if(NtSetTimerResolution != NULL)
|
||||
{
|
||||
NTSETTIMERRESOLUTION NtSetTimerResolution = (NTSETTIMERRESOLUTION)
|
||||
GetProcAddress(ntdll, "NtSetTimerResolution");
|
||||
if (NtSetTimerResolution != NULL) {
|
||||
NtSetTimerResolution(1000, TRUE, &CurrentResolution);
|
||||
}
|
||||
}
|
||||
|
||||
// PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION = 4, isn't defined in Win10 headers
|
||||
PROCESS_POWER_THROTTLING_STATE PowerThrottlingState { PROCESS_POWER_THROTTLING_CURRENT_VERSION, 4, 0 };
|
||||
PROCESS_POWER_THROTTLING_STATE PowerThrottlingState{PROCESS_POWER_THROTTLING_CURRENT_VERSION,
|
||||
4,
|
||||
0};
|
||||
// take care of the slowdown on Windows 11
|
||||
SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &PowerThrottlingState, sizeof(PowerThrottlingState));
|
||||
SetProcessInformation(GetCurrentProcess(),
|
||||
ProcessPowerThrottling,
|
||||
&PowerThrottlingState,
|
||||
sizeof(PowerThrottlingState));
|
||||
}
|
||||
#endif
|
||||
|
||||
void WaitWhileServerOnline(NetworkServer* srv)
|
||||
void WaitWhileServerOnline(NetworkServer *srv)
|
||||
{
|
||||
while (srv->GetOnline())
|
||||
{
|
||||
while (srv->GetOnline()) {
|
||||
std::this_thread::sleep_for(1s);
|
||||
};
|
||||
}
|
||||
@@ -81,65 +86,67 @@ void WaitWhileServerOnline(NetworkServer* srv)
|
||||
#ifdef _WIN32
|
||||
void InstallWinRing0()
|
||||
{
|
||||
TCHAR winring0_install_location[MAX_PATH]; // driver final location usually C:\windows\system32\drivers\WinRing0x64.sys
|
||||
TCHAR winring0_install_location
|
||||
[MAX_PATH]; // driver final location usually C:\windows\system32\drivers\WinRing0x64.sys
|
||||
uint system_path_length = GetSystemDirectory(winring0_install_location, MAX_PATH);
|
||||
std::string winring0_filename = "WinRing0.sys";
|
||||
BOOL bIsWow64 = false;
|
||||
#if _WIN64
|
||||
winring0_filename = "WinRing0x64.sys";
|
||||
#else
|
||||
BOOL (*fnIsWow64Process)(HANDLE, PBOOL) = (BOOL (__cdecl *)(HANDLE, PBOOL))GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
|
||||
if (fnIsWow64Process)
|
||||
{
|
||||
fnIsWow64Process(GetCurrentProcess(),&bIsWow64);
|
||||
BOOL (*fnIsWow64Process)(HANDLE, PBOOL) = (BOOL(__cdecl *)(HANDLE, PBOOL))
|
||||
GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
|
||||
if (fnIsWow64Process) {
|
||||
fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
|
||||
}
|
||||
if(bIsWow64)
|
||||
{
|
||||
if (bIsWow64) {
|
||||
winring0_filename = "WinRing0x64.sys";
|
||||
}
|
||||
#endif
|
||||
std::strncat(winring0_install_location, "\\drivers\\", MAX_PATH - system_path_length - 1);
|
||||
std::strncat(winring0_install_location, winring0_filename.c_str(), MAX_PATH - system_path_length - 10);
|
||||
std::strncat(winring0_install_location,
|
||||
winring0_filename.c_str(),
|
||||
MAX_PATH - system_path_length - 10);
|
||||
|
||||
std::string driver_name = winring0_filename.substr(0, winring0_filename.size() - 4); // driver name: WinRing0 or WinRing0x64
|
||||
std::string driver_name = winring0_filename
|
||||
.substr(0,
|
||||
winring0_filename.size()
|
||||
- 4); // driver name: WinRing0 or WinRing0x64
|
||||
SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if (manager)
|
||||
{
|
||||
if (manager) {
|
||||
PVOID wow64_fsredirection_OldValue = NULL;
|
||||
if(bIsWow64)
|
||||
{
|
||||
if (bIsWow64) {
|
||||
Wow64DisableWow64FsRedirection(&wow64_fsredirection_OldValue);
|
||||
}
|
||||
if(INVALID_FILE_ATTRIBUTES == GetFileAttributes(winring0_install_location) && GetLastError()==ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(winring0_install_location)
|
||||
&& GetLastError() == ERROR_FILE_NOT_FOUND) {
|
||||
char module_path_buffer[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, module_path_buffer, MAX_PATH);
|
||||
std::string::size_type exe_loc = std::string(module_path_buffer).find_last_of("\\/");
|
||||
std::string driver_source_path = std::string(module_path_buffer).substr(0, exe_loc + 1) + winring0_filename;
|
||||
std::string driver_source_path = std::string(module_path_buffer).substr(0, exe_loc + 1)
|
||||
+ winring0_filename;
|
||||
CopyFile(driver_source_path.c_str(), winring0_install_location, true);
|
||||
}
|
||||
if(bIsWow64)
|
||||
{
|
||||
if (bIsWow64) {
|
||||
Wow64RevertWow64FsRedirection(wow64_fsredirection_OldValue);
|
||||
}
|
||||
|
||||
SC_HANDLE service = OpenService(manager, driver_name.c_str(), SERVICE_ALL_ACCESS);
|
||||
if(!service)
|
||||
{
|
||||
if (!service) {
|
||||
std::string service_sys_path = "System32\\Drivers\\" + winring0_filename;
|
||||
service = CreateService(manager,
|
||||
driver_name.c_str(),
|
||||
driver_name.c_str(),
|
||||
SERVICE_ALL_ACCESS,
|
||||
SERVICE_KERNEL_DRIVER,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL,
|
||||
service_sys_path.c_str(),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
driver_name.c_str(),
|
||||
driver_name.c_str(),
|
||||
SERVICE_ALL_ACCESS,
|
||||
SERVICE_KERNEL_DRIVER,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL,
|
||||
service_sys_path.c_str(),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
CloseServiceHandle(service);
|
||||
CloseServiceHandle(manager);
|
||||
@@ -155,20 +162,19 @@ void InstallWinRing0()
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int exitval = EXIT_SUCCESS;
|
||||
#ifdef _WIN32
|
||||
/*---------------------------------------------------------*\
|
||||
| Windows only - Attach console output |
|
||||
\*---------------------------------------------------------*/
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||
{
|
||||
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
|
||||
/*---------------------------------------------------------*\
|
||||
| We are running under some terminal context; otherwise |
|
||||
| leave the GUI and CRT alone |
|
||||
\*---------------------------------------------------------*/
|
||||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
}
|
||||
@@ -196,35 +202,34 @@ int main(int argc, char* argv[])
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned int ret_flags = cli_pre_detection(argc, argv);
|
||||
|
||||
ResourceManager::get()->Initialize(
|
||||
!(ret_flags & RET_FLAG_NO_AUTO_CONNECT),
|
||||
!(ret_flags & RET_FLAG_NO_DETECT),
|
||||
ret_flags & RET_FLAG_START_SERVER,
|
||||
ret_flags & RET_FLAG_CLI_POST_DETECTION);
|
||||
ResourceManager::get()->Initialize(!(ret_flags & RET_FLAG_NO_AUTO_CONNECT),
|
||||
!(ret_flags & RET_FLAG_NO_DETECT),
|
||||
ret_flags & RET_FLAG_START_SERVER,
|
||||
ret_flags & RET_FLAG_CLI_POST_DETECTION);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| If the command line parser indicates that the GUI should |
|
||||
| run, or if there were no command line arguments, start the|
|
||||
| GUI. |
|
||||
\*---------------------------------------------------------*/
|
||||
if(ret_flags & RET_FLAG_START_GUI)
|
||||
{
|
||||
if (ret_flags & RET_FLAG_START_GUI) {
|
||||
LOG_TRACE("[main] initializing GUI");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
/*-----------------------------------------------------*\
|
||||
| Enable high DPI scaling support |
|
||||
\*-----------------------------------------------------*/
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
/*-----------------------------------------------------*\
|
||||
| Enable high DPI fractional scaling support on Windows |
|
||||
\*-----------------------------------------------------*/
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) && defined(Q_OS_WIN)
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) && defined(Q_OS_WIN)
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
|
||||
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
|
||||
QApplication a(argc, argv);
|
||||
QGuiApplication::setDesktopFileName("org.openrgb.OpenRGB");
|
||||
@@ -236,15 +241,13 @@ int main(int argc, char* argv[])
|
||||
Ui::OpenRGBDialog dlg;
|
||||
LOG_TRACE("[main] Dialog created");
|
||||
|
||||
if(ret_flags & RET_FLAG_I2C_TOOLS)
|
||||
{
|
||||
if (ret_flags & RET_FLAG_I2C_TOOLS) {
|
||||
dlg.AddI2CToolsPage();
|
||||
}
|
||||
|
||||
dlg.AddClientTab();
|
||||
|
||||
if(ret_flags & RET_FLAG_START_MINIMIZED)
|
||||
{
|
||||
if (ret_flags & RET_FLAG_START_MINIMIZED) {
|
||||
#ifdef _WIN32
|
||||
/*---------------------------------------------------------*\
|
||||
| Show the window always, even if it will immediately be |
|
||||
@@ -258,17 +261,13 @@ int main(int argc, char* argv[])
|
||||
MacUtils::ToggleApplicationDocklessState(false);
|
||||
#endif
|
||||
dlg.hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
LOG_TRACE("[main] Ready to exec() the dialog");
|
||||
exitval = a.exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/*---------------------------------------------------------*\
|
||||
| If no GUI is needed, we let the background threads run |
|
||||
| as long as they need, but we need to AT LEAST wait for |
|
||||
@@ -276,16 +275,12 @@ int main(int argc, char* argv[])
|
||||
\*---------------------------------------------------------*/
|
||||
ResourceManager::get()->WaitForInitialization();
|
||||
|
||||
if(ret_flags & RET_FLAG_START_SERVER)
|
||||
{
|
||||
NetworkServer* server = ResourceManager::get()->GetServer();
|
||||
if (ret_flags & RET_FLAG_START_SERVER) {
|
||||
NetworkServer *server = ResourceManager::get()->GetServer();
|
||||
|
||||
if(!server->GetOnline())
|
||||
{
|
||||
if (!server->GetOnline()) {
|
||||
exitval = EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
WaitWhileServerOnline(server);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user