@@ -50,7 +50,7 @@ void CMMonitorController::SetMode(uint8_t mode_value, const RGBColor& color, uin
50
50
{
51
51
if (software_mode_enabled)
52
52
{
53
- DisableSoftwareMode ( );
53
+ SetSoftwareModeEnabled ( false );
54
54
}
55
55
56
56
uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
@@ -61,7 +61,7 @@ void CMMonitorController::SetMode(uint8_t mode_value, const RGBColor& color, uin
61
61
usb_buf[3 ] = 0x02 ;
62
62
usb_buf[4 ] = 0x02 ;
63
63
usb_buf[5 ] = mode_value;
64
- usb_buf[6 ] = (mode_value == CM_MONITOR_OFF_MODE) ? 0x00 : 0x08 ;;
64
+ usb_buf[6 ] = (mode_value == CM_MONITOR_OFF_MODE) ? 0x00 : 0x08 ;
65
65
usb_buf[7 ] = speed;
66
66
usb_buf[8 ] = brightness;
67
67
usb_buf[9 ] = RGBGetRValue (color);
@@ -75,7 +75,7 @@ void CMMonitorController::SetCustomMode(const std::vector<RGBColor>& colors, uin
75
75
{
76
76
if (software_mode_enabled)
77
77
{
78
- DisableSoftwareMode ( );
78
+ SetSoftwareModeEnabled ( false );
79
79
}
80
80
81
81
/* ---------------------------------------------------------*\
@@ -94,7 +94,7 @@ void CMMonitorController::SetCustomMode(const std::vector<RGBColor>& colors, uin
94
94
}
95
95
96
96
/* ---------------------------------------------------------*\
97
- | Sends the 8 sequence packets |
97
+ | Sends the 7 sequence packets |
98
98
\*---------------------------------------------------------*/
99
99
uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
100
100
@@ -118,12 +118,12 @@ void CMMonitorController::SetCustomMode(const std::vector<RGBColor>& colors, uin
118
118
usb_buf[6 ] = brightnesss;
119
119
120
120
memcpy (&usb_buf[7 ], &color_data[offset], CM_MONITOR_PACKET_LENGTH - 7 );
121
- offset += 58 ;
121
+ offset += CM_MONITOR_PACKET_LENGTH - 7 ;
122
122
}
123
123
else
124
124
{
125
125
memcpy (&usb_buf[2 ], &color_data[offset], CM_MONITOR_PACKET_LENGTH - 2 );
126
- offset += (CM_MONITOR_PACKET_LENGTH -2 );
126
+ offset += (CM_MONITOR_PACKET_LENGTH - 2 );
127
127
}
128
128
129
129
hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
@@ -134,7 +134,7 @@ void CMMonitorController::SendDirect(const std::vector<RGBColor>& colors)
134
134
{
135
135
if (!software_mode_enabled)
136
136
{
137
- EnableSoftwareMode ( );
137
+ SetSoftwareModeEnabled ( true );
138
138
}
139
139
140
140
/* ---------------------------------------------------------*\
@@ -153,105 +153,52 @@ void CMMonitorController::SendDirect(const std::vector<RGBColor>& colors)
153
153
}
154
154
155
155
/* ---------------------------------------------------------*\
156
- | Sends the 14 sequence packets |
156
+ | Sends the 7 sequence packets |
157
157
\*---------------------------------------------------------*/
158
158
uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
159
159
160
- for (unsigned int p = 0 ; p < 2 ; p++)
161
- {
162
- offset = 0 ;
163
-
164
- for (unsigned int i = 0 ; i < 7 ; i++)
165
- {
166
- memset (usb_buf, 0x00 , CM_MONITOR_PACKET_LENGTH);
167
-
168
- usb_buf[1 ] = i < 6 ? i : 0x86 ;
169
-
170
- if (i == 0 )
171
- {
172
- usb_buf[2 ] = 0x07 ;
173
- usb_buf[3 ] = 0x02 ;
174
- usb_buf[4 ] = p + 1 ;
175
- usb_buf[5 ] = 0x01 ;
176
- usb_buf[6 ] = 0x80 ;
177
-
178
- memcpy (&usb_buf[7 ], &color_data[offset], CM_MONITOR_PACKET_LENGTH - 7 );
179
- offset += CM_MONITOR_PACKET_LENGTH - 7 ;
180
- }
181
- else
182
- {
183
- memcpy (&usb_buf[2 ], &color_data[offset], CM_MONITOR_PACKET_LENGTH - 2 );
184
- offset += (CM_MONITOR_PACKET_LENGTH -2 );
185
- }
186
-
187
- hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
188
- }
189
- }
190
- }
191
-
192
- void CMMonitorController::EnableSoftwareMode ()
193
- {
194
- uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
195
- memset (usb_buf, 0x00 , CM_MONITOR_PACKET_LENGTH);
160
+ offset = 0 ;
196
161
197
- usb_buf[1 ] = 0x80 ;
198
- usb_buf[2 ] = 0x07 ;
199
- usb_buf[3 ] = 0x02 ;
200
- usb_buf[4 ] = 0x01 ;
201
- usb_buf[6 ] = 0x01 ;
202
- hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
162
+ for (unsigned int i = 0 ; i < 7 ; i++)
163
+ {
164
+ memset (usb_buf, 0x00 , CM_MONITOR_PACKET_LENGTH);
203
165
204
- usb_buf[4 ] = 0x02 ;
205
- hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
166
+ usb_buf[1 ] = i < 6 ? i : 0x86 ;
206
167
207
- uint8_t read_buf[CM_MONITOR_PACKET_LENGTH];
168
+ if (i == 0 )
169
+ {
170
+ usb_buf[2 ] = 0x07 ;
171
+ usb_buf[3 ] = 0x02 ;
172
+ usb_buf[4 ] = 0x02 ;
173
+ usb_buf[5 ] = 0x01 ;
174
+ usb_buf[6 ] = 0x80 ;
208
175
209
- /* ---------------------------------------------------------*\
210
- | We have to send a few black packets, with some read ones |
211
- \*---------------------------------------------------------*/
212
- for (unsigned int p = 0 ; p < 4 ; p++)
213
- {
214
- for (unsigned int i = 0 ; i < 7 ; i++)
176
+ memcpy (&usb_buf[7 ], &color_data[offset], CM_MONITOR_PACKET_LENGTH - 7 );
177
+ offset += CM_MONITOR_PACKET_LENGTH - 7 ;
178
+ }
179
+ else
215
180
{
216
- memset (usb_buf, 0x00 , CM_MONITOR_PACKET_LENGTH);
217
-
218
- usb_buf[1 ] = i < 6 ? i : 0x86 ;
219
-
220
- if (i == 0 )
221
- {
222
- usb_buf[2 ] = 0x07 ;
223
- usb_buf[3 ] = 0x02 ;
224
- usb_buf[4 ] = (p == 0 || p == 0 ) ? 0x01 : 0x02 ;
225
- usb_buf[5 ] = 0x01 ;
226
- usb_buf[6 ] = 0x80 ;
227
- }
228
-
229
- hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
230
-
231
- if (p ==0 && (i == 2 || i == 4 ))
232
- {
233
- memset (read_buf, 0x00 , CM_MONITOR_PACKET_LENGTH);
234
- hid_read (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
235
- }
181
+ memcpy (&usb_buf[2 ], &color_data[offset], CM_MONITOR_PACKET_LENGTH - 2 );
182
+ offset += (CM_MONITOR_PACKET_LENGTH - 2 );
236
183
}
184
+
185
+ hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
237
186
}
238
187
239
- software_mode_enabled = true ;
240
188
}
241
189
242
- void CMMonitorController::DisableSoftwareMode ( )
190
+ void CMMonitorController::SetSoftwareModeEnabled ( bool value )
243
191
{
244
192
uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
245
193
memset (usb_buf, 0x00 , CM_MONITOR_PACKET_LENGTH);
246
194
247
195
usb_buf[1 ] = 0x80 ;
248
196
usb_buf[2 ] = 0x07 ;
249
197
usb_buf[3 ] = 0x02 ;
250
- usb_buf[4 ] = 0x01 ;
251
- hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
252
-
253
198
usb_buf[4 ] = 0x02 ;
199
+ usb_buf[6 ] = value;
200
+
254
201
hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
255
202
256
- software_mode_enabled = false ;
203
+ software_mode_enabled = value ;
257
204
}
0 commit comments