@@ -50,7 +50,7 @@ void CMMonitorController::SetMode(uint8_t mode_value, const RGBColor& color, uin
5050{
5151 if (software_mode_enabled)
5252 {
53- DisableSoftwareMode ( );
53+ SetSoftwareModeEnabled ( false );
5454 }
5555
5656 uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
@@ -61,7 +61,7 @@ void CMMonitorController::SetMode(uint8_t mode_value, const RGBColor& color, uin
6161 usb_buf[3 ] = 0x02 ;
6262 usb_buf[4 ] = 0x02 ;
6363 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 ;
6565 usb_buf[7 ] = speed;
6666 usb_buf[8 ] = brightness;
6767 usb_buf[9 ] = RGBGetRValue (color);
@@ -75,7 +75,7 @@ void CMMonitorController::SetCustomMode(const std::vector<RGBColor>& colors, uin
7575{
7676 if (software_mode_enabled)
7777 {
78- DisableSoftwareMode ( );
78+ SetSoftwareModeEnabled ( false );
7979 }
8080
8181 /* ---------------------------------------------------------*\
@@ -94,7 +94,7 @@ void CMMonitorController::SetCustomMode(const std::vector<RGBColor>& colors, uin
9494 }
9595
9696 /* ---------------------------------------------------------*\
97- | Sends the 8 sequence packets |
97+ | Sends the 7 sequence packets |
9898 \*---------------------------------------------------------*/
9999 uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
100100
@@ -118,12 +118,12 @@ void CMMonitorController::SetCustomMode(const std::vector<RGBColor>& colors, uin
118118 usb_buf[6 ] = brightnesss;
119119
120120 memcpy (&usb_buf[7 ], &color_data[offset], CM_MONITOR_PACKET_LENGTH - 7 );
121- offset += 58 ;
121+ offset += CM_MONITOR_PACKET_LENGTH - 7 ;
122122 }
123123 else
124124 {
125125 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 );
127127 }
128128
129129 hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
@@ -134,7 +134,7 @@ void CMMonitorController::SendDirect(const std::vector<RGBColor>& colors)
134134{
135135 if (!software_mode_enabled)
136136 {
137- EnableSoftwareMode ( );
137+ SetSoftwareModeEnabled ( true );
138138 }
139139
140140 /* ---------------------------------------------------------*\
@@ -153,105 +153,52 @@ void CMMonitorController::SendDirect(const std::vector<RGBColor>& colors)
153153 }
154154
155155 /* ---------------------------------------------------------*\
156- | Sends the 14 sequence packets |
156+ | Sends the 7 sequence packets |
157157 \*---------------------------------------------------------*/
158158 uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
159159
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 ;
196161
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);
203165
204- usb_buf[4 ] = 0x02 ;
205- hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
166+ usb_buf[1 ] = i < 6 ? i : 0x86 ;
206167
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 ;
208175
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
215180 {
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 );
236183 }
184+
185+ hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
237186 }
238187
239- software_mode_enabled = true ;
240188}
241189
242- void CMMonitorController::DisableSoftwareMode ( )
190+ void CMMonitorController::SetSoftwareModeEnabled ( bool value )
243191{
244192 uint8_t usb_buf[CM_MONITOR_PACKET_LENGTH];
245193 memset (usb_buf, 0x00 , CM_MONITOR_PACKET_LENGTH);
246194
247195 usb_buf[1 ] = 0x80 ;
248196 usb_buf[2 ] = 0x07 ;
249197 usb_buf[3 ] = 0x02 ;
250- usb_buf[4 ] = 0x01 ;
251- hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
252-
253198 usb_buf[4 ] = 0x02 ;
199+ usb_buf[6 ] = value;
200+
254201 hid_write (dev, usb_buf, CM_MONITOR_PACKET_LENGTH);
255202
256- software_mode_enabled = false ;
203+ software_mode_enabled = value ;
257204}
0 commit comments