Skip to content

Commit 45755c7

Browse files
letdievarCalcProgrammer1
authored andcommitted
Add support for Patriot Viper Steel Direct mode
1 parent 2f72061 commit 45755c7

File tree

6 files changed

+350
-0
lines changed

6 files changed

+350
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*-----------------------------------------*\
2+
| PatriotViperSteelController.cpp |
3+
| |
4+
| Definitions and types for Patriot Viper |
5+
| Steel RGB RAM lighting controller |
6+
\*-----------------------------------------*/
7+
8+
#include "PatriotViperSteelController.h"
9+
#include <cstring>
10+
11+
PatriotViperSteelController::PatriotViperSteelController(i2c_smbus_interface *bus, viper_dev_id dev)
12+
{
13+
this->bus = bus;
14+
this->dev = dev;
15+
16+
strcpy(device_name, "Patriot Viper Steel RGB");
17+
18+
led_count = 5;
19+
}
20+
21+
PatriotViperSteelController::~PatriotViperSteelController()
22+
{
23+
}
24+
25+
std::string PatriotViperSteelController::GetDeviceName()
26+
{
27+
return(device_name);
28+
}
29+
30+
std::string PatriotViperSteelController::GetDeviceLocation()
31+
{
32+
std::string return_string(bus->device_name);
33+
char addr[5];
34+
snprintf(addr, 5, "0x%02X", dev);
35+
return_string.append(", address ");
36+
return_string.append(addr);
37+
return("I2C: " + return_string);
38+
}
39+
40+
unsigned int PatriotViperSteelController::GetLEDCount()
41+
{
42+
return(led_count);
43+
}
44+
45+
unsigned int PatriotViperSteelController::GetSlotCount()
46+
{
47+
unsigned int slot_count = 0;
48+
49+
for(int slot = 0; slot < 4; slot++)
50+
{
51+
if((slots_valid & (1 << slot)) != 0)
52+
{
53+
slot_count++;
54+
}
55+
}
56+
57+
return(slot_count);
58+
}
59+
60+
unsigned int PatriotViperSteelController::GetMode()
61+
{
62+
return(mode);
63+
}
64+
65+
void PatriotViperSteelController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue)
66+
{
67+
ViperRegisterWrite(VIPER_STEEL_REG_LED0_DIRECT_COLOR, red, blue, green);
68+
ViperRegisterWrite(VIPER_STEEL_REG_LED1_DIRECT_COLOR, red, blue, green);
69+
ViperRegisterWrite(VIPER_STEEL_REG_LED2_DIRECT_COLOR, red, blue, green);
70+
ViperRegisterWrite(VIPER_STEEL_REG_LED3_DIRECT_COLOR, red, blue, green);
71+
ViperRegisterWrite(VIPER_STEEL_REG_LED4_DIRECT_COLOR, red, blue, green);
72+
}
73+
74+
void PatriotViperSteelController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
75+
{
76+
ViperRegisterWrite(VIPER_STEEL_REG_LED0_DIRECT_COLOR + led, red, blue, green);
77+
}
78+
79+
void PatriotViperSteelController::SetLEDColor(unsigned int /*slot*/, unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
80+
{
81+
ViperRegisterWrite(VIPER_STEEL_REG_LED0_DIRECT_COLOR + led, red, blue, green);
82+
}
83+
84+
void PatriotViperSteelController::ViperRegisterWrite(viper_register reg, unsigned char val0, unsigned char val1, unsigned char val2)
85+
{
86+
bus->i2c_smbus_write_byte_data(dev, reg, val0);
87+
bus->i2c_smbus_write_byte_data(dev, val2, val1);
88+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*-----------------------------------------*\
2+
| PatriotViperController.h |
3+
| |
4+
| Definitions and types for Patriot Viper |
5+
| RGB RAM lighting controller |
6+
\*-----------------------------------------*/
7+
8+
#include <string>
9+
#include "i2c_smbus.h"
10+
11+
#pragma once
12+
13+
typedef unsigned char viper_dev_id;
14+
typedef unsigned short viper_register;
15+
16+
enum
17+
{
18+
VIPER_STEEL_REG_LED0_DIRECT_COLOR = 0x17, /* LED 0 Color (R, B, G) */
19+
VIPER_STEEL_REG_LED1_DIRECT_COLOR = 0x18, /* LED 1 Color (R, B, G) */
20+
VIPER_STEEL_REG_LED2_DIRECT_COLOR = 0x19, /* LED 2 Color (R, B, G) */
21+
VIPER_STEEL_REG_LED3_DIRECT_COLOR = 0x1a, /* LED 3 Color (R, B, G) */
22+
VIPER_STEEL_REG_LED4_DIRECT_COLOR = 0x1b, /* LED 4 Color (R, B, G) */
23+
};
24+
25+
class PatriotViperSteelController
26+
{
27+
public:
28+
PatriotViperSteelController(i2c_smbus_interface *bus, viper_dev_id dev);
29+
~PatriotViperSteelController();
30+
31+
std::string GetDeviceName();
32+
std::string GetDeviceLocation();
33+
unsigned int GetLEDCount();
34+
unsigned int GetSlotCount();
35+
unsigned int GetMode();
36+
37+
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);
38+
void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
39+
void SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
40+
41+
void ViperRegisterWrite(viper_register reg, unsigned char val0, unsigned char val1, unsigned char val2);
42+
bool direct;
43+
44+
private:
45+
char device_name[32];
46+
unsigned int led_count;
47+
unsigned char slots_valid;
48+
i2c_smbus_interface *bus;
49+
viper_dev_id dev;
50+
unsigned char mode;
51+
unsigned char speed;
52+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "Detector.h"
2+
#include "PatriotViperSteelController.h"
3+
#include "LogManager.h"
4+
#include "RGBController.h"
5+
#include "RGBController_PatriotViperSteel.h"
6+
#include "i2c_smbus.h"
7+
#include "pci_ids.h"
8+
#include <vector>
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
12+
using namespace std::chrono_literals;
13+
#define PATRIOT_CONTROLLER_NAME "Patriot Viper Steel"
14+
15+
/******************************************************************************************\
16+
* *
17+
* DetectPatriotViperSteelControllers *
18+
* *
19+
* Detect Patriot Viper Steel RGB controllers on the enumerated I2C busses. *
20+
* *
21+
* bus - pointer to i2c_smbus_interface where Aura device is connected *
22+
* dev - I2C address of Aura device *
23+
* *
24+
\******************************************************************************************/
25+
26+
void DetectPatriotViperSteelControllers(std::vector<i2c_smbus_interface *> &busses)
27+
{
28+
PatriotViperSteelController *new_viper;
29+
RGBController_PatriotViperSteel *new_controller;
30+
31+
for(unsigned int bus = 0; bus < busses.size(); bus++)
32+
{
33+
34+
IF_DRAM_SMBUS(busses[bus]->pci_vendor, busses[bus]->pci_device)
35+
{
36+
int res = busses[bus]->i2c_smbus_read_byte_data(0x20, 0x1D);
37+
38+
std::this_thread::sleep_for(1ms);
39+
40+
if((busses[bus]->i2c_smbus_read_byte_data(0x20, 0x1D) == 0x0F)
41+
&&(busses[bus]->i2c_smbus_read_byte_data(0x20, 0x1E) == 0x0C)
42+
&&(busses[bus]->i2c_smbus_read_byte_data(0x20, 0x39) == 0x0F)
43+
&&(busses[bus]->i2c_smbus_read_byte_data(0x20, 0x3A) == 0x0C))
44+
{
45+
new_viper = new PatriotViperSteelController(busses[bus], 0x77);
46+
new_controller = new RGBController_PatriotViperSteel(new_viper);
47+
ResourceManager::get()->RegisterRGBController(new_controller);
48+
}
49+
}
50+
}
51+
52+
} /* DetectPatriotViperSteelControllers() */
53+
54+
REGISTER_I2C_DETECTOR(PATRIOT_CONTROLLER_NAME, DetectPatriotViperSteelControllers);
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*-----------------------------------------*\
2+
| RGBController_PatriotViperSteel.cpp |
3+
| |
4+
| Generic RGB Interface for OpenRGB |
5+
| Patriot Viper Steel RGB interface |
6+
\*-----------------------------------------*/
7+
8+
#include "RGBController_PatriotViperSteel.h"
9+
10+
/**------------------------------------------------------------------*\
11+
@name Patriot Viper Steel
12+
@type I2C
13+
@save :x:
14+
@direct :white_check_mark:
15+
@effects :white_check_mark:
16+
@detectors DetectPatriotViperSteelControllers
17+
@comment
18+
\*-------------------------------------------------------------------*/
19+
20+
RGBController_PatriotViperSteel::RGBController_PatriotViperSteel(PatriotViperSteelController *viper_ptr)
21+
{
22+
controller = viper_ptr;
23+
24+
name = controller->GetDeviceName();
25+
vendor = "Patriot";
26+
type = DEVICE_TYPE_DRAM;
27+
description = "Patriot Viper Steel Device";
28+
location = controller->GetDeviceLocation();
29+
30+
mode Direct;
31+
Direct.name = "Direct";
32+
Direct.value = 0xFFFF;
33+
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
34+
Direct.speed_min = 0;
35+
Direct.speed_max = 0;
36+
Direct.color_mode = MODE_COLORS_PER_LED;
37+
Direct.speed = 0;
38+
modes.push_back(Direct);
39+
40+
SetupZones();
41+
}
42+
43+
RGBController_PatriotViperSteel::~RGBController_PatriotViperSteel()
44+
{
45+
delete controller;
46+
}
47+
48+
void RGBController_PatriotViperSteel::SetupZones()
49+
{
50+
/*---------------------------------------------------------*\
51+
| Set up zones |
52+
\*---------------------------------------------------------*/
53+
zone *new_zone = new zone;
54+
new_zone->name = "Patriot Viper Steel RGB";
55+
new_zone->type = ZONE_TYPE_LINEAR;
56+
new_zone->leds_min = 5;
57+
new_zone->leds_max = 5;
58+
new_zone->leds_count = 5;
59+
new_zone->matrix_map = NULL;
60+
zones.push_back(*new_zone);
61+
62+
/*---------------------------------------------------------*\
63+
| Set up LEDs |
64+
\*---------------------------------------------------------*/
65+
for(std::size_t led_idx = 0; led_idx < zones[0].leds_count; led_idx++)
66+
{
67+
led *new_led = new led();
68+
69+
new_led->name = "Patriot Viper RGB LED ";
70+
new_led->name.append(std::to_string(led_idx + 1));
71+
leds.push_back(*new_led);
72+
}
73+
74+
SetupColors();
75+
}
76+
77+
void RGBController_PatriotViperSteel::ResizeZone(int /*zone*/, int /*new_size*/)
78+
{
79+
/*---------------------------------------------------------*\
80+
| This device does not support resizing zones |
81+
\*---------------------------------------------------------*/
82+
}
83+
84+
void RGBController_PatriotViperSteel::DeviceUpdateLEDs()
85+
{
86+
for(int led = 0; led < 5; led++)
87+
{
88+
RGBColor color = colors[led];
89+
unsigned char red = RGBGetRValue(color);
90+
unsigned char grn = RGBGetGValue(color);
91+
unsigned char blu = RGBGetBValue(color);
92+
93+
controller->SetLEDColor(led, red, grn, blu);
94+
}
95+
}
96+
97+
void RGBController_PatriotViperSteel::UpdateZoneLEDs(int /*zone*/)
98+
{
99+
DeviceUpdateLEDs();
100+
}
101+
102+
void RGBController_PatriotViperSteel::UpdateSingleLED(int led)
103+
{
104+
RGBColor color = colors[led];
105+
unsigned char red = RGBGetRValue(color);
106+
unsigned char grn = RGBGetGValue(color);
107+
unsigned char blu = RGBGetBValue(color);
108+
109+
controller->SetLEDColor(led, red, grn, blu);
110+
}
111+
112+
void RGBController_PatriotViperSteel::SetCustomMode()
113+
{
114+
}
115+
116+
void RGBController_PatriotViperSteel::DeviceUpdateMode()
117+
{
118+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*---------------------------------------------*\
2+
| RGBController_PatriotViperSteel.h |
3+
| |
4+
| Generic RGB Interface for OpenRGB |
5+
| Patriot Viper Steel RGB interface |
6+
\*---------------------------------------------*/
7+
8+
#pragma once
9+
10+
#include "RGBController.h"
11+
#include "PatriotViperSteelController.h"
12+
13+
class RGBController_PatriotViperSteel : public RGBController
14+
{
15+
public:
16+
RGBController_PatriotViperSteel(PatriotViperSteelController *controller_ptr);
17+
~RGBController_PatriotViperSteel();
18+
19+
void SetupZones();
20+
21+
void ResizeZone(int zone, int new_size);
22+
23+
void DeviceUpdateLEDs();
24+
void UpdateZoneLEDs(int zone);
25+
void UpdateSingleLED(int led);
26+
27+
void SetCustomMode();
28+
void DeviceUpdateMode();
29+
30+
private:
31+
PatriotViperSteelController *controller;
32+
};

OpenRGB.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ INCLUDEPATH +=
135135
Controllers/NZXTKrakenController/ \
136136
Controllers/OpenRazerController/ \
137137
Controllers/PatriotViperController/ \
138+
Controllers/PatriotViperSteelController/ \
138139
Controllers/PhilipsHueController/ \
139140
Controllers/PhilipsWizController/ \
140141
Controllers/PNYGPUController/ \
@@ -445,6 +446,8 @@ HEADERS +=
445446
Controllers/OpenRazerController/OpenRazerDevices.h \
446447
Controllers/PatriotViperController/PatriotViperController.h \
447448
Controllers/PatriotViperController/RGBController_PatriotViper.h \
449+
Controllers/PatriotViperSteelController/PatriotViperSteelController.h \
450+
Controllers/PatriotViperSteelController/RGBController_PatriotViperSteel.h \
448451
Controllers/PhilipsHueController/PhilipsHueController.h \
449452
Controllers/PhilipsHueController/RGBController_PhilipsHue.h \
450453
Controllers/PhilipsWizController/PhilipsWizController.h \
@@ -919,6 +922,9 @@ SOURCES +=
919922
Controllers/PatriotViperController/PatriotViperController.cpp \
920923
Controllers/PatriotViperController/PatriotViperControllerDetect.cpp \
921924
Controllers/PatriotViperController/RGBController_PatriotViper.cpp \
925+
Controllers/PatriotViperSteelController/PatriotViperSteelController.cpp \
926+
Controllers/PatriotViperSteelController/PatriotViperSteelControllerDetect.cpp \
927+
Controllers/PatriotViperSteelController/RGBController_PatriotViperSteel.cpp \
922928
Controllers/PhilipsHueController/PhilipsHueController.cpp \
923929
Controllers/PhilipsHueController/PhilipsHueControllerDetect.cpp \
924930
Controllers/PhilipsHueController/PhilipsHueEntertainmentController.cpp \

0 commit comments

Comments
 (0)