diff --git a/Controllers/ViewSonicController/ViewSonicControllerDetect.cpp b/Controllers/ViewSonicController/ViewSonicControllerDetect.cpp index 94432c116..3ede6db51 100644 --- a/Controllers/ViewSonicController/ViewSonicControllerDetect.cpp +++ b/Controllers/ViewSonicController/ViewSonicControllerDetect.cpp @@ -1,7 +1,7 @@ /*---------------------------------------------------------*\ | ViewSonicControllerDetect.cpp | | | -| Detector for ViewSonic XG270QG | +| Detector for ViewSonic XG270QG and XG270QC | | | | Lanzaa 23 Jan 2022 | | | @@ -13,13 +13,16 @@ #include "Detector.h" #include "VS_XG270QG_Controller.h" #include "RGBController_XG270QG.h" +#include "VS_XG270QC_Controller.h" +#include "RGBController_XG270QC.h" #define WINBOND_VID 0x0416 #define VIEWSONIC_VID 0x0543 #define VS_XG270QG_PID 0x5020 #define VS_XG271QG_PID 0xA004 +#define VS_XG270QC_PID 0xA002 -void DetectViewSonic(hid_device_info* info, const std::string& name) +void DetectViewSonicQG(hid_device_info* info, const std::string& name) { hid_device* dev = hid_open_path(info->path); @@ -32,5 +35,19 @@ void DetectViewSonic(hid_device_info* info, const std::string& name) } } -REGISTER_HID_DETECTOR_IPU("ViewSonic Monitor XG270QG", DetectViewSonic, WINBOND_VID, VS_XG270QG_PID, 0, 0xFF00, 1); -REGISTER_HID_DETECTOR_IP( "ViewSonic Monitor XG271QG", DetectViewSonic, VIEWSONIC_VID, VS_XG271QG_PID, 0, 0x0001); +void DetectViewSonicQC(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + VS_XG270QC_Controller* controller = new VS_XG270QC_Controller(dev, info->path, name); + RGBController_XG270QC* rgb_controller = new RGBController_XG270QC(controller); + + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} + +REGISTER_HID_DETECTOR_IPU("ViewSonic Monitor XG270QG", DetectViewSonicQG, WINBOND_VID, VS_XG270QG_PID, 0, 0xFF00, 1); +REGISTER_HID_DETECTOR_IP( "ViewSonic Monitor XG271QG", DetectViewSonicQG, VIEWSONIC_VID, VS_XG271QG_PID, 0, 0x0001); +REGISTER_HID_DETECTOR_IPU("ViewSonic Monitor XG270QC", DetectViewSonicQC, VIEWSONIC_VID, VS_XG270QC_PID, 0, 0x0001, 0); diff --git a/Controllers/ViewSonicController/XG270QC/RGBController_XG270QC.cpp b/Controllers/ViewSonicController/XG270QC/RGBController_XG270QC.cpp new file mode 100644 index 000000000..8457a4708 --- /dev/null +++ b/Controllers/ViewSonicController/XG270QC/RGBController_XG270QC.cpp @@ -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 +#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); +} diff --git a/Controllers/ViewSonicController/XG270QC/RGBController_XG270QC.h b/Controllers/ViewSonicController/XG270QC/RGBController_XG270QC.h new file mode 100644 index 000000000..60adc768f --- /dev/null +++ b/Controllers/ViewSonicController/XG270QC/RGBController_XG270QC.h @@ -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; +}; diff --git a/Controllers/ViewSonicController/XG270QC/VS_XG270QC_Controller.cpp b/Controllers/ViewSonicController/XG270QC/VS_XG270QC_Controller.cpp new file mode 100644 index 000000000..b232f0d12 --- /dev/null +++ b/Controllers/ViewSonicController/XG270QC/VS_XG270QC_Controller.cpp @@ -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 +#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); +} diff --git a/Controllers/ViewSonicController/XG270QC/VS_XG270QC_Controller.h b/Controllers/ViewSonicController/XG270QC/VS_XG270QC_Controller.h new file mode 100644 index 000000000..3b67876e2 --- /dev/null +++ b/Controllers/ViewSonicController/XG270QC/VS_XG270QC_Controller.h @@ -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 +#include +#include +#include +#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); +}; diff --git a/Controllers/ViewSonicController/RGBController_XG270QG.cpp b/Controllers/ViewSonicController/XG270QG/RGBController_XG270QG.cpp similarity index 92% rename from Controllers/ViewSonicController/RGBController_XG270QG.cpp rename to Controllers/ViewSonicController/XG270QG/RGBController_XG270QG.cpp index aaa982ac6..c88a09fee 100644 --- a/Controllers/ViewSonicController/RGBController_XG270QG.cpp +++ b/Controllers/ViewSonicController/XG270QG/RGBController_XG270QG.cpp @@ -1,189 +1,189 @@ -/*---------------------------------------------------------*\ -| RGBController_XG270QG.cpp | -| | -| RGBController for ViewSonic XG270QG | -| | -| Lanzaa 23 Jan 2022 | -| | -| This file is part of the OpenRGB project | -| SPDX-License-Identifier: GPL-2.0-or-later | -\*---------------------------------------------------------*/ - -#include -#include "RGBController_XG270QG.h" - -/**------------------------------------------------------------------*\ - @name Viewsonic Monitor - @category Accessory - @type USB - @save :x: - @direct :x: - @effects :white_check_mark: - @detectors DetectViewSonic - @comment -\*-------------------------------------------------------------------*/ - -RGBController_XG270QG::RGBController_XG270QG(VS_XG270QG_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_MODE_OFF; - Off.color_mode = MODE_COLORS_NONE; - modes.push_back(Off); - - mode Custom; - Custom.name = "Custom"; - Custom.value = VS_MODE_STATIC; - Custom.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE; - Custom.colors_min = 1; - Custom.colors_max = 1; - Custom.color_mode = MODE_COLORS_PER_LED; - Custom.colors.resize(1); - modes.push_back(Custom); - - mode Rainbow; - Rainbow.name = "Rainbow Wave"; - Rainbow.value = VS_MODE_RAINBOW; - Rainbow.flags = MODE_FLAG_AUTOMATIC_SAVE; - Rainbow.color_mode = MODE_COLORS_NONE; - modes.push_back(Rainbow); - - mode Breath; - Breath.name = "Breathing"; - Breath.value = VS_MODE_BREATHING; - Breath.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE; - Breath.colors_min = 1; - Breath.colors_max = 1; - Breath.color_mode = MODE_COLORS_PER_LED; - Breath.colors.resize(1); - modes.push_back(Breath); - - mode Waterfall; - Waterfall.name = "Waterfall"; - Waterfall.value = VS_MODE_WATERFALL; - Waterfall.flags = MODE_FLAG_AUTOMATIC_SAVE; - Waterfall.color_mode = MODE_COLORS_NONE; - modes.push_back(Waterfall); - - mode Elite; - Elite.name = "Elite"; - Elite.value = VS_MODE_ELITE; - Elite.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE; - Elite.colors_min = 1; - Elite.colors_max = 1; - Elite.color_mode = MODE_COLORS_PER_LED; - Elite.colors.resize(1); - modes.push_back(Elite); - - //mode Jazz; - //Jazz.name = "Jazz Wave (Audio Reactive)"; - //Jazz.value = VS_MODE_JAZZ; - ////Jazz.color_mode = MODE_COLORS_NONE; // might have color - //Jazz.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_AUTOMATIC_SAVE; - //Jazz.colors_min = 1; - //Jazz.colors_max = 1; - //Jazz.color_mode = MODE_COLORS_MODE_SPECIFIC; - //Jazz.colors.resize(1); - //modes.push_back(Jazz); - - //mode EliteGlobal; - //EliteGlobal.name = "Elite Global (Audio Reactive)"; - //EliteGlobal.value = VS_MODE_ELITEGLOBAL; - //EliteGlobal.flags = MODE_FLAG_AUTOMATIC_SAVE; - //EliteGlobal.color_mode = MODE_COLORS_NONE; - //modes.push_back(EliteGlobal); - - RGBController_XG270QG::SetupZones(); -} - -void RGBController_XG270QG::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_XG270QG::ResizeZone(int /*zone*/, int /*new_size*/) -{ - /*---------------------------------------------------------*\ - | This device does not support resizing zones | - \*---------------------------------------------------------*/ -} - -void RGBController_XG270QG::DeviceUpdateLEDs() -{ - DeviceUpdateMode(); -} - -void RGBController_XG270QG::UpdateZoneLEDs(int /*zone*/) -{ - DeviceUpdateLEDs(); -} - -void RGBController_XG270QG::UpdateSingleLED(int /*led*/) -{ - DeviceUpdateLEDs(); -} - -void RGBController_XG270QG::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); -} +/*---------------------------------------------------------*\ +| RGBController_XG270QG.cpp | +| | +| RGBController for ViewSonic XG270QG | +| | +| Lanzaa 23 Jan 2022 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-or-later | +\*---------------------------------------------------------*/ + +#include +#include "RGBController_XG270QG.h" + +/**------------------------------------------------------------------*\ + @name Viewsonic Monitor + @category Accessory + @type USB + @save :x: + @direct :x: + @effects :white_check_mark: + @detectors DetectViewSonic + @comment +\*-------------------------------------------------------------------*/ + +RGBController_XG270QG::RGBController_XG270QG(VS_XG270QG_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_XG270QG_Controller::VS_MODE_OFF; + Off.color_mode = MODE_COLORS_NONE; + modes.push_back(Off); + + mode Custom; + Custom.name = "Custom"; + Custom.value = VS_XG270QG_Controller::VS_MODE_STATIC; + Custom.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE; + Custom.colors_min = 1; + Custom.colors_max = 1; + Custom.color_mode = MODE_COLORS_PER_LED; + Custom.colors.resize(1); + modes.push_back(Custom); + + mode Rainbow; + Rainbow.name = "Rainbow Wave"; + Rainbow.value = VS_XG270QG_Controller::VS_MODE_RAINBOW; + Rainbow.flags = MODE_FLAG_AUTOMATIC_SAVE; + Rainbow.color_mode = MODE_COLORS_NONE; + modes.push_back(Rainbow); + + mode Breath; + Breath.name = "Breathing"; + Breath.value = VS_XG270QG_Controller::VS_MODE_BREATHING; + Breath.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE; + Breath.colors_min = 1; + Breath.colors_max = 1; + Breath.color_mode = MODE_COLORS_PER_LED; + Breath.colors.resize(1); + modes.push_back(Breath); + + mode Waterfall; + Waterfall.name = "Waterfall"; + Waterfall.value = VS_XG270QG_Controller::VS_MODE_WATERFALL; + Waterfall.flags = MODE_FLAG_AUTOMATIC_SAVE; + Waterfall.color_mode = MODE_COLORS_NONE; + modes.push_back(Waterfall); + + mode Elite; + Elite.name = "Elite"; + Elite.value = VS_XG270QG_Controller::VS_MODE_ELITE; + Elite.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE; + Elite.colors_min = 1; + Elite.colors_max = 1; + Elite.color_mode = MODE_COLORS_PER_LED; + Elite.colors.resize(1); + modes.push_back(Elite); + + //mode Jazz; + //Jazz.name = "Jazz Wave (Audio Reactive)"; + //Jazz.value = VS_MODE_JAZZ; + ////Jazz.color_mode = MODE_COLORS_NONE; // might have color + //Jazz.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_AUTOMATIC_SAVE; + //Jazz.colors_min = 1; + //Jazz.colors_max = 1; + //Jazz.color_mode = MODE_COLORS_MODE_SPECIFIC; + //Jazz.colors.resize(1); + //modes.push_back(Jazz); + + //mode EliteGlobal; + //EliteGlobal.name = "Elite Global (Audio Reactive)"; + //EliteGlobal.value = VS_MODE_ELITEGLOBAL; + //EliteGlobal.flags = MODE_FLAG_AUTOMATIC_SAVE; + //EliteGlobal.color_mode = MODE_COLORS_NONE; + //modes.push_back(EliteGlobal); + + RGBController_XG270QG::SetupZones(); +} + +void RGBController_XG270QG::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_XG270QG::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*---------------------------------------------------------*\ + | This device does not support resizing zones | + \*---------------------------------------------------------*/ +} + +void RGBController_XG270QG::DeviceUpdateLEDs() +{ + DeviceUpdateMode(); +} + +void RGBController_XG270QG::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_XG270QG::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_XG270QG::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); +} diff --git a/Controllers/ViewSonicController/RGBController_XG270QG.h b/Controllers/ViewSonicController/XG270QG/RGBController_XG270QG.h similarity index 97% rename from Controllers/ViewSonicController/RGBController_XG270QG.h rename to Controllers/ViewSonicController/XG270QG/RGBController_XG270QG.h index 2c8343516..a9e21ffc2 100644 --- a/Controllers/ViewSonicController/RGBController_XG270QG.h +++ b/Controllers/ViewSonicController/XG270QG/RGBController_XG270QG.h @@ -1,33 +1,33 @@ -/*---------------------------------------------------------*\ -| RGBController_XG270QG.h | -| | -| RGBController for ViewSonic XG270QG | -| | -| Lanzaa 23 Jan 2022 | -| | -| This file is part of the OpenRGB project | -| SPDX-License-Identifier: GPL-2.0-or-later | -\*---------------------------------------------------------*/ - -#pragma once - -#include "VS_XG270QG_Controller.h" -#include "RGBController.h" - -class RGBController_XG270QG : public RGBController -{ -public: - RGBController_XG270QG(VS_XG270QG_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_XG270QG_Controller* controller; -}; +/*---------------------------------------------------------*\ +| RGBController_XG270QG.h | +| | +| RGBController for ViewSonic XG270QG | +| | +| Lanzaa 23 Jan 2022 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-or-later | +\*---------------------------------------------------------*/ + +#pragma once + +#include "VS_XG270QG_Controller.h" +#include "RGBController.h" + +class RGBController_XG270QG : public RGBController +{ +public: + RGBController_XG270QG(VS_XG270QG_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_XG270QG_Controller* controller; +}; diff --git a/Controllers/ViewSonicController/VS_XG270QG_Controller.cpp b/Controllers/ViewSonicController/XG270QG/VS_XG270QG_Controller.cpp similarity index 100% rename from Controllers/ViewSonicController/VS_XG270QG_Controller.cpp rename to Controllers/ViewSonicController/XG270QG/VS_XG270QG_Controller.cpp diff --git a/Controllers/ViewSonicController/VS_XG270QG_Controller.h b/Controllers/ViewSonicController/XG270QG/VS_XG270QG_Controller.h similarity index 82% rename from Controllers/ViewSonicController/VS_XG270QG_Controller.h rename to Controllers/ViewSonicController/XG270QG/VS_XG270QG_Controller.h index 30d3a3063..e005e6d77 100644 --- a/Controllers/ViewSonicController/VS_XG270QG_Controller.h +++ b/Controllers/ViewSonicController/XG270QG/VS_XG270QG_Controller.h @@ -17,21 +17,21 @@ #include #include "RGBController.h" -enum -{ - VS_MODE_OFF = 0x00, - VS_MODE_STATIC = 0x01, - VS_MODE_BREATHING = 0x02, - VS_MODE_RAINBOW = 0x07, - VS_MODE_ELITE = 0x0A, - VS_MODE_JAZZ = 0x0C, - VS_MODE_WATERFALL = 0x12, - VS_MODE_ELITEGLOBAL = 0x13, -}; - class VS_XG270QG_Controller { public: + enum ModeValues + { + VS_MODE_OFF = 0x00, + VS_MODE_STATIC = 0x01, + VS_MODE_BREATHING = 0x02, + VS_MODE_RAINBOW = 0x07, + VS_MODE_ELITE = 0x0A, + VS_MODE_JAZZ = 0x0C, + VS_MODE_WATERFALL = 0x12, + VS_MODE_ELITEGLOBAL = 0x13, + }; + VS_XG270QG_Controller(hid_device* device, const char* path, std::string dev_name); ~VS_XG270QG_Controller();