Skip to content

Commit 6672b53

Browse files
karvanitisCalcProgrammer1
authored andcommitted
Add suport for brightness to Glorious Model O
1 parent 6e3271f commit 6672b53

3 files changed

Lines changed: 83 additions & 100 deletions

File tree

Controllers/SinowealthController/SinowealthController/RGBController_Sinowealth.cpp

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ RGBController_Sinowealth::RGBController_Sinowealth(SinowealthController* control
3434
version = controller->GetFirmwareVersion();
3535

3636
mode Static;
37-
Static.name = "Static";
38-
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
37+
Static.name = "Custom";
38+
Static.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_AUTOMATIC_SAVE;
39+
Static.brightness_min = GLORIOUS_BRIGHTNESS_LOW;
40+
Static.brightness = GLORIOUS_BRIGHTNESS_NORMAL;
41+
Static.brightness_max = GLORIOUS_BRIGHTNESS_HIGH;
3942
Static.color_mode = MODE_COLORS_PER_LED;
4043
Static.value = GLORIOUS_MODE_STATIC;
4144
modes.push_back(Static);
@@ -48,7 +51,7 @@ RGBController_Sinowealth::RGBController_Sinowealth(SinowealthController* control
4851
modes.push_back(Off);
4952

5053
mode Rainbow;
51-
Rainbow.name = "Glorious Mode";
54+
Rainbow.name = "Rainbow";
5255
Rainbow.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_UD | MODE_FLAG_AUTOMATIC_SAVE;
5356
Rainbow.speed_min = GLORIOUS_SPEED_SLOW;
5457
Rainbow.speed = GLORIOUS_SPEED_NORMAL;
@@ -73,10 +76,13 @@ RGBController_Sinowealth::RGBController_Sinowealth(SinowealthController* control
7376

7477
mode Chase;
7578
Chase.name = "Tail";
76-
Chase.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_AUTOMATIC_SAVE;
79+
Chase.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_AUTOMATIC_SAVE;
7780
Chase.speed_min = GLORIOUS_SPEED_SLOW;
7881
Chase.speed = GLORIOUS_SPEED_NORMAL;
7982
Chase.speed_max = GLORIOUS_SPEED_FAST;
83+
Chase.brightness_min = GLORIOUS_BRIGHTNESS_LOW;
84+
Chase.brightness = GLORIOUS_BRIGHTNESS_NORMAL;
85+
Chase.brightness_max = GLORIOUS_BRIGHTNESS_HIGH;
8086
Chase.color_mode = MODE_COLORS_NONE;
8187
Chase.value = GLORIOUS_MODE_TAIL;
8288
modes.push_back(Chase);
@@ -93,10 +99,13 @@ RGBController_Sinowealth::RGBController_Sinowealth(SinowealthController* control
9399

94100
mode Flashing;
95101
Flashing.name = "Rave";
96-
Flashing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
102+
Flashing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
97103
Flashing.speed_min = GLORIOUS_SPEED_SLOW;
98104
Flashing.speed = GLORIOUS_SPEED_NORMAL;
99105
Flashing.speed_max = GLORIOUS_SPEED_FAST;
106+
Flashing.brightness_min = GLORIOUS_BRIGHTNESS_LOW;
107+
Flashing.brightness = GLORIOUS_BRIGHTNESS_NORMAL;
108+
Flashing.brightness_max = GLORIOUS_BRIGHTNESS_HIGH;
100109
Flashing.colors_min = 2;
101110
Flashing.colors_max = 2;
102111
Flashing.color_mode = MODE_COLORS_MODE_SPECIFIC;
@@ -111,22 +120,25 @@ RGBController_Sinowealth::RGBController_Sinowealth(SinowealthController* control
111120
Epilepsy.value = GLORIOUS_MODE_EPILEPSY;
112121
modes.push_back(Epilepsy);
113122

114-
mode RainbowSlow;
115-
RainbowSlow.name = "Wave";
116-
RainbowSlow.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_AUTOMATIC_SAVE;
117-
RainbowSlow.speed_min = GLORIOUS_SPEED_SLOW;
118-
RainbowSlow.speed = GLORIOUS_SPEED_NORMAL;
119-
RainbowSlow.speed_max = GLORIOUS_SPEED_FAST;
120-
RainbowSlow.color_mode = MODE_COLORS_NONE;
121-
RainbowSlow.value = GLORIOUS_MODE_WAVE;
122-
modes.push_back(RainbowSlow);
123+
mode Wave;
124+
Wave.name = "Wave";
125+
Wave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_AUTOMATIC_SAVE;
126+
Wave.speed_min = GLORIOUS_SPEED_SLOW;
127+
Wave.speed = GLORIOUS_SPEED_NORMAL;
128+
Wave.speed_max = GLORIOUS_SPEED_FAST;
129+
Wave.brightness_min = GLORIOUS_BRIGHTNESS_LOW;
130+
Wave.brightness = GLORIOUS_BRIGHTNESS_NORMAL;
131+
Wave.brightness_max = GLORIOUS_BRIGHTNESS_HIGH;
132+
Wave.color_mode = MODE_COLORS_NONE;
133+
Wave.value = GLORIOUS_MODE_WAVE;
134+
modes.push_back(Wave);
123135

124136
mode Breathing;
125137
Breathing.name = "Breathing";
126138
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_AUTOMATIC_SAVE;
127-
Breathing.speed_min = GLORIOUS_MODE_BREATING_SLOW;
128-
Breathing.speed = GLORIOUS_MODE_BREATING_NORMAL;
129-
Breathing.speed_max = GLORIOUS_MODE_BREATING_FAST;
139+
Breathing.speed_min = GLORIOUS_SPEED_SLOW;
140+
Breathing.speed = GLORIOUS_SPEED_NORMAL;
141+
Breathing.speed_max = GLORIOUS_SPEED_FAST;
130142
Breathing.colors_min = 1;
131143
Breathing.colors_max = 1;
132144
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
@@ -178,7 +190,7 @@ void RGBController_Sinowealth::ResizeZone(int /*zone*/, int /*new_size*/)
178190

179191
void RGBController_Sinowealth::DeviceUpdateLEDs()
180192
{
181-
controller->SetLEDColor(&colors[0]);
193+
DeviceUpdateMode();
182194
}
183195

184196
void RGBController_Sinowealth::UpdateZoneLEDs(int /*zone*/)
@@ -194,51 +206,44 @@ void RGBController_Sinowealth::UpdateSingleLED(int /*led*/)
194206
void RGBController_Sinowealth::DeviceUpdateMode()
195207
{
196208
unsigned int direction = 0;
197-
unsigned int speed = GLORIOUS_SPEED_NORMAL;
209+
unsigned int speed = GLORIOUS_SPEED_FAST;
210+
unsigned int brightness = GLORIOUS_BRIGHTNESS_HIGH;
198211

199-
if (modes[active_mode].value == GLORIOUS_MODE_STATIC)
212+
if (modes[active_mode].flags & MODE_FLAG_HAS_SPEED)
200213
{
214+
speed = modes[active_mode].speed;
215+
}
201216

217+
if (modes[active_mode].flags & MODE_FLAG_HAS_BRIGHTNESS)
218+
{
219+
brightness = modes[active_mode].brightness;
202220
}
203-
else
221+
222+
if ((modes[active_mode].flags & MODE_FLAG_HAS_DIRECTION_LR) ||
223+
(modes[active_mode].flags & MODE_FLAG_HAS_DIRECTION_UD) ||
224+
(modes[active_mode].flags & MODE_FLAG_HAS_DIRECTION_HV))
204225
{
205226
if (modes[active_mode].direction == MODE_DIRECTION_UP)
206-
{
207-
direction = GLORIOUS_DIRECTION_DOWN;
208-
}
209-
else
210227
{
211228
direction = GLORIOUS_DIRECTION_UP;
212229
}
213-
214-
if ((modes[active_mode].speed == GLORIOUS_SPEED_FAST) ||
215-
(modes[active_mode].speed == GLORIOUS_SPEED_SLOW) ||
216-
(modes[active_mode].speed == GLORIOUS_SPEED_NORMAL))
217-
{
218-
speed = modes[active_mode].speed;
219-
}
220230
else
221231
{
222-
if ((modes[active_mode].speed == GLORIOUS_MODE_BREATING_FAST) ||
223-
(modes[active_mode].speed == GLORIOUS_MODE_BREATING_SLOW) ||
224-
(modes[active_mode].speed == GLORIOUS_MODE_BREATING_NORMAL))
225-
{
226-
speed = modes[active_mode].speed;
227-
}
228-
else
229-
{
230-
speed = GLORIOUS_SPEED_NORMAL;
231-
}
232+
direction = GLORIOUS_DIRECTION_DOWN;
232233
}
234+
}
233235

234-
if (modes[active_mode].color_mode == MODE_COLORS_NONE)
235-
{
236-
controller->SetMode(modes[active_mode].value, speed, direction, 0);
237-
}
238-
else
239-
{
240-
controller->SetMode(modes[active_mode].value, speed, direction, &modes[active_mode].colors[0]);
241-
}
236+
if (modes[active_mode].color_mode == MODE_COLORS_NONE)
237+
{
238+
controller->SetMode(modes[active_mode].value, speed, brightness, direction, 0);
239+
}
240+
else if (modes[active_mode].color_mode == MODE_COLORS_PER_LED)
241+
{
242+
controller->SetMode(modes[active_mode].value, speed, brightness, direction, &colors[0]);
243+
}
244+
else
245+
{
246+
controller->SetMode(modes[active_mode].value, speed, brightness, direction, &modes[active_mode].colors[0]);
242247
}
243248
}
244249

Controllers/SinowealthController/SinowealthController/SinowealthController.cpp

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ SinowealthController::SinowealthController(hid_device* dev_data_handle, hid_devi
2222
name = dev_name;
2323

2424
led_count = 1;
25-
26-
current_mode = GLORIOUS_MODE_STATIC;
27-
current_speed = GLORIOUS_SPEED_NORMAL;
28-
current_direction = GLORIOUS_DIRECTION_UP;
2925
}
3026

3127
SinowealthController::~SinowealthController()
@@ -88,32 +84,11 @@ std::string SinowealthController::GetFirmwareVersion()
8884
return std::string(reinterpret_cast<char*>(usb_buf) + 2); // Skip report and command byte
8985
}
9086

91-
void SinowealthController::SetLEDColor
92-
(
93-
RGBColor* color_buf
94-
)
95-
{
96-
if (GetProfile() < SINOWEALTH_CONFIG_SIZE_MIN) return;
97-
98-
unsigned char usb_buf[SINOWEALTH_CONFIG_REPORT_SIZE];
99-
memcpy(usb_buf, device_configuration, SINOWEALTH_CONFIG_SIZE); // Yes, we only copy 167 bytes back, for now - if anything weird starts happening use SINOWEALTH_CONFIG_REPORT_SIZE
100-
101-
usb_buf[0x03] = 0x7B; //write to device
102-
usb_buf[0x06] = 0x00;
103-
104-
usb_buf[0x35] = GLORIOUS_MODE_STATIC;
105-
usb_buf[0x38] = 0x40; //max brightness
106-
usb_buf[0x39] = RGBGetRValue(color_buf[0]);
107-
usb_buf[0x3A] = RGBGetBValue(color_buf[0]);
108-
usb_buf[0x3B] = RGBGetGValue(color_buf[0]);
109-
110-
hid_send_feature_report(dev_data, usb_buf, SINOWEALTH_CONFIG_REPORT_SIZE);
111-
}
112-
11387
void SinowealthController::SetMode
11488
(
11589
unsigned char mode,
11690
unsigned char speed,
91+
unsigned char brightness,
11792
unsigned char direction,
11893
RGBColor* color_buf
11994
)
@@ -130,16 +105,19 @@ void SinowealthController::SetMode
130105

131106
switch (mode)
132107
{
133-
case GLORIOUS_MODE_OFF:
134-
usb_buf[0x81] = 0x00; //mode 0 either 0x00 or 0x03
135-
break;
136108
case GLORIOUS_MODE_RAINBOW:
137-
usb_buf[0x36] = speed;
109+
usb_buf[0x36] = ((brightness & 0xF) << 4) | (speed & 0xF);
138110
usb_buf[0x37] = direction;
139111
break;
112+
case GLORIOUS_MODE_STATIC:
113+
usb_buf[0x38] = ((brightness & 0xF) << 4);
114+
usb_buf[0x39] = RGBGetRValue(color_buf[0]);
115+
usb_buf[0x3A] = RGBGetBValue(color_buf[0]);
116+
usb_buf[0x3B] = RGBGetGValue(color_buf[0]);
117+
break;
140118
case GLORIOUS_MODE_SPECTRUM_BREATING:
141119
//colours not yet researched
142-
usb_buf[0x3C] = speed; //speed for mode 3
120+
usb_buf[0x3C] = ((brightness & 0xF) << 4) | (speed & 0xF);
143121
usb_buf[0x3D] = 0x07; //maybe some kind of bank change?+
144122
//usb_buf[0x3D] = 0x06;
145123
usb_buf[0x3E] = RGBGetRValue(color_buf[0]); //mode 3 red 1
@@ -165,13 +143,13 @@ void SinowealthController::SetMode
165143
usb_buf[0x52] = RGBGetGValue(color_buf[6]); //mode 3 green 7
166144
break;
167145
case GLORIOUS_MODE_TAIL:
168-
usb_buf[0x53] = speed; //Speed for mode 4
146+
usb_buf[0x53] = ((brightness & 0xF) << 4) | (speed & 0xF);
169147
break;
170148
case GLORIOUS_MODE_SPECTRUM_CYCLE:
171-
usb_buf[0x54] = speed; //Speed for mode 1,2,5
149+
usb_buf[0x54] = ((brightness & 0xF) << 4) | (speed & 0xF);
172150
break;
173151
case GLORIOUS_MODE_RAVE:
174-
usb_buf[0x74] = speed; //Speed for mode 7
152+
usb_buf[0x74] = ((brightness & 0xF) << 4) | (speed & 0xF);
175153
usb_buf[0x75] = RGBGetRValue(color_buf[0]); //mode 7 red 1
176154
usb_buf[0x76] = RGBGetBValue(color_buf[0]); //mode 7 blue 1
177155
usb_buf[0x77] = RGBGetGValue(color_buf[0]); //mode 7 green 1
@@ -180,13 +158,16 @@ void SinowealthController::SetMode
180158
usb_buf[0x7A] = RGBGetGValue(color_buf[1]); //mode 7 green 2
181159
break;
182160
case GLORIOUS_MODE_WAVE:
183-
usb_buf[0x7C] = speed; //Speed for mode 9
161+
usb_buf[0x7C] = ((brightness & 0xF) << 4) | (speed & 0xF);
184162
break;
185163
case GLORIOUS_MODE_BREATHING:
186-
usb_buf[0x7D] = speed;
164+
usb_buf[0x7D] = ((brightness & 0xF) << 4) | (speed & 0xF);
187165
usb_buf[0x7E] = RGBGetRValue(color_buf[0]); //mode 0a red
188166
usb_buf[0x7F] = RGBGetBValue(color_buf[0]); //mode 0a blue
189167
usb_buf[0x80] = RGBGetGValue(color_buf[0]); //mode 0a green
168+
case GLORIOUS_MODE_OFF:
169+
usb_buf[0x81] = 0x00; //mode 0 either 0x00 or 0x03
170+
break;
190171
default:
191172
break;
192173
}

Controllers/SinowealthController/SinowealthController/SinowealthController.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ enum
3131
GLORIOUS_MODE_RAVE = 0x07,
3232
GLORIOUS_MODE_EPILEPSY = 0x08, //not in the official software
3333
GLORIOUS_MODE_WAVE = 0x09,
34-
GLORIOUS_MODE_BREATHING = 0x0a,
34+
GLORIOUS_MODE_BREATHING = 0x0A,
3535
};
3636

3737
enum
3838
{
39-
GLORIOUS_SPEED_SLOW = 0x41,
40-
GLORIOUS_SPEED_NORMAL = 0x42,
41-
GLORIOUS_SPEED_FAST = 0x43,
39+
GLORIOUS_SPEED_SLOW = 0x01,
40+
GLORIOUS_SPEED_NORMAL = 0x02,
41+
GLORIOUS_SPEED_FAST = 0x03,
4242
};
4343

4444
enum
4545
{
46-
GLORIOUS_DIRECTION_UP = 0x00,
47-
GLORIOUS_DIRECTION_DOWN = 0x01,
46+
GLORIOUS_BRIGHTNESS_LOW = 0x01,
47+
GLORIOUS_BRIGHTNESS_NORMAL = 0x02,
48+
GLORIOUS_BRIGHTNESS_HIGH = 0x04,
4849
};
4950

5051
enum
5152
{
52-
GLORIOUS_MODE_BREATING_SLOW = 0x01,
53-
GLORIOUS_MODE_BREATING_NORMAL = 0x02,
54-
GLORIOUS_MODE_BREATING_FAST = 0x03,
53+
GLORIOUS_DIRECTION_DOWN = 0x00,
54+
GLORIOUS_DIRECTION_UP = 0x01,
5555
};
5656

5757
class SinowealthController
@@ -66,16 +66,13 @@ class SinowealthController
6666
std::string GetSerialString();
6767
std::string GetFirmwareVersion();
6868

69-
void SetLEDColor(RGBColor* color_buf);
70-
void SetMode(unsigned char mode, unsigned char speed, unsigned char direction, RGBColor* color_buf);
69+
void SetMode(unsigned char mode, unsigned char speed, unsigned char brightness, unsigned char direction, RGBColor* color_buf);
7170
int GetProfile();
71+
7272
private:
7373
hid_device* dev_cmd;
7474
hid_device* dev_data;
7575
unsigned int led_count;
76-
unsigned char current_mode;
77-
unsigned char current_speed;
78-
unsigned char current_direction;
7976
unsigned char device_configuration[SINOWEALTH_CONFIG_REPORT_SIZE];
8077
std::string location;
8178
std::string name;

0 commit comments

Comments
 (0)