added support for ViewSonic XG270QC
parent
b6673965e2
commit
769d433373
@ -0,0 +1,169 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_XG270QC.cpp |
|
||||
| |
|
||||
| RGBController for ViewSonic XG270QC |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include "RGBController_XG270QC.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Viewsonic Monitor
|
||||
@category Accessory
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :x:
|
||||
@effects :white_check_mark:
|
||||
@detectors DetectViewSonic
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_XG270QC::RGBController_XG270QC(VS_XG270QC_Controller* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetName();
|
||||
vendor = "ViewSonic";
|
||||
type = DEVICE_TYPE_MONITOR;
|
||||
description = "ViewSonic Monitor Device";
|
||||
location = controller->GetLocation();
|
||||
serial = controller->GetSerial();
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = VS_XG270QC_Controller::VS_MODE_OFF;
|
||||
Off.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = VS_XG270QC_Controller::VS_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Static.colors_min = 2;
|
||||
Static.colors_max = 2;
|
||||
Static.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = VS_XG270QC_Controller::VS_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Breathing.colors_min = 2;
|
||||
Breathing.colors_max = 2;
|
||||
Breathing.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode Rainbow;
|
||||
Rainbow.name = "Rainbow";
|
||||
Rainbow.value = VS_XG270QC_Controller::VS_MODE_RAINBOW;
|
||||
Rainbow.flags = MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Rainbow.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Rainbow);
|
||||
|
||||
mode WarpSpeed;
|
||||
WarpSpeed.name = "Warp Speed";
|
||||
WarpSpeed.value = VS_XG270QC_Controller::VS_MODE_WARP_SPEED;
|
||||
WarpSpeed.flags = MODE_FLAG_AUTOMATIC_SAVE;
|
||||
WarpSpeed.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(WarpSpeed);
|
||||
|
||||
mode Stack;
|
||||
Stack.name = "Stack";
|
||||
Stack.value = VS_XG270QC_Controller::VS_MODE_STACK;
|
||||
Stack.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
|
||||
Stack.colors_min = 2;
|
||||
Stack.colors_max = 2;
|
||||
Stack.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Stack);
|
||||
|
||||
//The modes Music and MusicPulse are not supported
|
||||
|
||||
RGBController_XG270QC::SetupZones();
|
||||
}
|
||||
|
||||
void RGBController_XG270QC::SetupZones()
|
||||
{
|
||||
zone base;
|
||||
base.name = "Base";
|
||||
base.type = ZONE_TYPE_SINGLE;
|
||||
base.leds_min = 1;
|
||||
base.leds_max = 1;
|
||||
base.leds_count = 1;
|
||||
base.matrix_map = NULL;
|
||||
zones.push_back(base);
|
||||
|
||||
zone rear;
|
||||
rear.name = "Rear";
|
||||
rear.type = ZONE_TYPE_SINGLE;
|
||||
rear.leds_min = 1;
|
||||
rear.leds_max = 1;
|
||||
rear.leds_count = 1;
|
||||
rear.matrix_map = NULL;
|
||||
zones.push_back(rear);
|
||||
|
||||
led d;
|
||||
d.name = "Base";
|
||||
d.value = 0x00;
|
||||
leds.push_back(d);
|
||||
|
||||
led back;
|
||||
back.name = "Rear";
|
||||
back.value = 0x01;
|
||||
leds.push_back(back);
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_XG270QC::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_XG270QC::DeviceUpdateLEDs()
|
||||
{
|
||||
DeviceUpdateMode();
|
||||
}
|
||||
|
||||
void RGBController_XG270QC::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_XG270QC::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_XG270QC::DeviceUpdateMode()
|
||||
{
|
||||
uint8_t r1 = 0;
|
||||
uint8_t g1 = 0;
|
||||
uint8_t b1 = 0;
|
||||
uint8_t r2 = 0;
|
||||
uint8_t g2 = 0;
|
||||
uint8_t b2 = 0;
|
||||
|
||||
if(modes[active_mode].flags & MODE_FLAG_HAS_MODE_SPECIFIC_COLOR)
|
||||
{
|
||||
r1 = r2 = RGBGetRValue(modes[active_mode].colors[0]);
|
||||
g1 = g2 = RGBGetGValue(modes[active_mode].colors[0]);
|
||||
b1 = b2 = RGBGetBValue(modes[active_mode].colors[0]);
|
||||
}
|
||||
else if (modes[active_mode].flags & MODE_FLAG_HAS_PER_LED_COLOR)
|
||||
{
|
||||
r1 = RGBGetRValue(colors[0]);
|
||||
g1 = RGBGetGValue(colors[0]);
|
||||
b1 = RGBGetBValue(colors[0]);
|
||||
|
||||
r2 = RGBGetRValue(colors[1]);
|
||||
g2 = RGBGetGValue(colors[1]);
|
||||
b2 = RGBGetBValue(colors[1]);
|
||||
}
|
||||
|
||||
controller->SetMode(modes[active_mode].value, r1, g1, b1, modes[active_mode].value, r2, g2, b2);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_XG270QC.h |
|
||||
| |
|
||||
| RGBController for ViewSonic XG270QC |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VS_XG270QC_Controller.h"
|
||||
#include "RGBController.h"
|
||||
|
||||
class RGBController_XG270QC : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_XG270QC(VS_XG270QC_Controller* controller_ptr);
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
VS_XG270QC_Controller* controller;
|
||||
};
|
||||
@ -0,0 +1,110 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| VS_XG270QC_Controller.cpp |
|
||||
| |
|
||||
| Driver for ViewSonic XG270QC |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include "StringUtils.h"
|
||||
#include "VS_XG270QC_Controller.h"
|
||||
|
||||
VS_XG270QC_Controller::VS_XG270QC_Controller(hid_device* device, const char* path, std::string dev_name)
|
||||
{
|
||||
dev = device;
|
||||
location = path;
|
||||
name = dev_name;
|
||||
}
|
||||
|
||||
VS_XG270QC_Controller::~VS_XG270QC_Controller()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string VS_XG270QC_Controller::GetLocation()
|
||||
{
|
||||
return(location);
|
||||
}
|
||||
|
||||
std::string VS_XG270QC_Controller::GetName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
std::string VS_XG270QC_Controller::GetSerial()
|
||||
{
|
||||
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 VS_XG270QC_Controller::SetMode(uint8_t mode1, uint8_t r1, uint8_t g1, uint8_t b1, uint8_t mode2, uint8_t r2, uint8_t g2, uint8_t b2)
|
||||
{
|
||||
// Music modes use different values for zone 2
|
||||
// Music: zone1=0x12 (VS_MODE_MUSIC), zone2=0x13 (VS_MODE_MUSIC_Z2)
|
||||
// Music Pulse: zone1=0x12 (VS_MODE_MUSIC_PULSE), zone2=0x14 (VS_MODE_MUSIC_PULSE_Z2)
|
||||
|
||||
uint8_t actual_mode2 = mode2;
|
||||
|
||||
// Map zone 1 music modes to their zone 2 equivalents
|
||||
if(mode1 == VS_MODE_MUSIC && mode2 == VS_MODE_MUSIC)
|
||||
{
|
||||
actual_mode2 = VS_MODE_MUSIC_Z2; // 0x13
|
||||
}
|
||||
else if(mode1 == VS_MODE_MUSIC_PULSE && mode2 == VS_MODE_MUSIC_PULSE)
|
||||
{
|
||||
actual_mode2 = VS_MODE_MUSIC_PULSE_Z2; // 0x14
|
||||
}
|
||||
|
||||
SendModeComplete(mode1, r1, g1, b1, actual_mode2, r2, g2, b2);
|
||||
}
|
||||
|
||||
void VS_XG270QC_Controller::SendModeComplete
|
||||
(
|
||||
uint8_t mode1, uint8_t r1, uint8_t g1, uint8_t b1,
|
||||
uint8_t mode2, uint8_t r2, uint8_t g2, uint8_t b2
|
||||
)
|
||||
{
|
||||
uint8_t data[167] = {0};
|
||||
|
||||
// Header byte
|
||||
data[0x00] = 0x02;
|
||||
|
||||
// Zone 1 (Downward facing LEDs)
|
||||
data[0x01] = mode1;
|
||||
data[0x02] = r1;
|
||||
data[0x03] = g1;
|
||||
data[0x04] = b1;
|
||||
data[0x05] = 0x00;
|
||||
data[0x06] = 0x0A;
|
||||
data[0x07] = 0x00;
|
||||
|
||||
// Zone 2 (Back facing LEDs)
|
||||
data[0x08] = mode2;
|
||||
data[0x09] = r2;
|
||||
data[0x0A] = g2;
|
||||
data[0x0B] = b2;
|
||||
data[0x0C] = 0x00;
|
||||
data[0x0D] = 0x0A;
|
||||
data[0x0E] = 0x00;
|
||||
|
||||
// End marker
|
||||
data[0x0F] = 0x01;
|
||||
|
||||
// Rest of the array is already zeroed by initialization
|
||||
|
||||
SendCommand(data, 167);
|
||||
}
|
||||
|
||||
void VS_XG270QC_Controller::SendCommand(uint8_t *data, size_t length)
|
||||
{
|
||||
hid_send_feature_report(dev, data, length);
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| VS_XG270QC_Controller.h |
|
||||
| |
|
||||
| Driver for ViewSonic XG270QC |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
|
||||
class VS_XG270QC_Controller
|
||||
{
|
||||
public:
|
||||
enum ModeValues
|
||||
{
|
||||
VS_MODE_OFF = 0x00,
|
||||
VS_MODE_STATIC = 0x01,
|
||||
VS_MODE_BREATHING = 0x02,
|
||||
VS_MODE_WARP_SPEED = 0x06,
|
||||
VS_MODE_RAINBOW = 0x07,
|
||||
VS_MODE_STACK = 0x09,
|
||||
VS_MODE_MUSIC = 0x12,
|
||||
VS_MODE_MUSIC_Z2 = 0x13, // Zone 2 value for Music mode
|
||||
VS_MODE_MUSIC_PULSE = 0x12, // Same as Music for zone 1
|
||||
VS_MODE_MUSIC_PULSE_Z2 = 0x14, // Zone 2 value for Music Pulse mode
|
||||
};
|
||||
|
||||
VS_XG270QC_Controller(hid_device* device, const char* path, std::string dev_name);
|
||||
~VS_XG270QC_Controller();
|
||||
|
||||
std::string GetLocation();
|
||||
std::string GetName();
|
||||
std::string GetSerial();
|
||||
|
||||
void SetMode(uint8_t mode1, uint8_t r1, uint8_t g1, uint8_t b1,
|
||||
uint8_t mode2, uint8_t r2, uint8_t g2, uint8_t b2);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
std::string name;
|
||||
std::string serial;
|
||||
|
||||
void SendModeComplete
|
||||
(
|
||||
uint8_t mode1, uint8_t r1, uint8_t g1, uint8_t b1,
|
||||
uint8_t mode2, uint8_t r2, uint8_t g2, uint8_t b2
|
||||
);
|
||||
void SendCommand(uint8_t *config, size_t length);
|
||||
};
|
||||
Loading…
Reference in New Issue