-
-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathManliGPUController.cpp
More file actions
125 lines (110 loc) · 3.76 KB
/
ManliGPUController.cpp
File metadata and controls
125 lines (110 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*---------------------------------------------------------*\
| ManliGPUController.cpp |
| |
| Driver for Manli GPU RGB controllers |
| |
| Based on ZotacV2GPUController |
| Adapted for Manli RTX 4090 Gallardo |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "ManliGPUController.h"
ManliGPUController::ManliGPUController(i2c_smbus_interface* bus, u8 dev, std::string dev_name)
{
this->bus = bus;
this->dev = dev;
this->name = dev_name;
if(dev)
{
ReadVersion();
}
}
ManliGPUController::~ManliGPUController()
{
}
std::string ManliGPUController::GetDeviceLocation()
{
std::string return_string(bus->device_name);
char addr[5];
snprintf(addr, 5, "0x%02X", dev);
return_string.append(", address ");
return_string.append(addr);
return ("I2C: " + return_string);
}
std::string ManliGPUController::GetName()
{
return(name);
}
std::string ManliGPUController::GetVersion()
{
return(version);
}
bool ManliGPUController::ReadVersion()
{
u8 data_pkt[] = { MANLI_GPU_REG_RGB, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
if(bus->i2c_write_block(dev, sizeof(data_pkt), data_pkt) < 0)
{
return false;
}
u8 rdata_pkt[I2C_SMBUS_BLOCK_MAX] = { 0x00 };
int rdata_len = sizeof(rdata_pkt);
if(bus->i2c_read_block(dev, &rdata_len, rdata_pkt) < 0)
{
return false;
}
version = std::string((char*)rdata_pkt);
return true;
}
bool ManliGPUController::TurnOnOff(bool on)
{
ManliGPUZone zoneConfig;
return SendCommand(on, zoneConfig);
}
bool ManliGPUController::SetMode(ManliGPUZone zoneConfig)
{
return SendCommand(true, zoneConfig);
}
bool ManliGPUController::SendCommand(bool on, ManliGPUZone zoneConfig)
{
/*---------------------------------------------------------*\
| Color Cycle: Uses breathing mode (0x01) with flag 0x07 |
| This cycles through colors with brightness and speed |
\*---------------------------------------------------------*/
if(zoneConfig.mode == MANLI_GPU_MODE_COLOR_CYCLE)
{
u8 data_pkt[30] = { 0x00 };
data_pkt[0] = on ? (u8)0x01 : (u8)0x00;
data_pkt[6] = 0x01; // mode = breathing
data_pkt[7] = 0x00; // R
data_pkt[8] = 0x00; // G
data_pkt[9] = 0x00; // B
data_pkt[10] = (u8)zoneConfig.speed;
data_pkt[11] = (u8)zoneConfig.brightness;
data_pkt[13] = 0x07; // color cycle flag
if(bus->i2c_smbus_write_i2c_block_data(dev, MANLI_GPU_REG_RGB, sizeof(data_pkt), data_pkt) < 0)
{
return false;
}
return true;
}
/*---------------------------------------------------------*\
| Standard modes (Static, Breathing, Wave, Strobing, Rainbow)|
\*---------------------------------------------------------*/
else
{
u8 data_pkt[30] = { 0x00 };
data_pkt[0] = on ? (u8)0x01 : (u8)0x00;
data_pkt[6] = (u8)zoneConfig.mode;
data_pkt[7] = (u8)RGBGetRValue(zoneConfig.color1);
data_pkt[8] = (u8)RGBGetGValue(zoneConfig.color1);
data_pkt[9] = (u8)RGBGetBValue(zoneConfig.color1);
data_pkt[10] = (u8)zoneConfig.speed;
data_pkt[11] = (u8)zoneConfig.brightness;
if(bus->i2c_smbus_write_i2c_block_data(dev, MANLI_GPU_REG_RGB, sizeof(data_pkt), data_pkt) < 0)
{
return false;
}
return true;
}
}