MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / SetMode

Method SetMode

Controllers/CougarController/CougarKeyboardController.cpp:103–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103void CougarKeyboardController::SetMode(uint8_t mode, uint8_t speed, uint8_t brightness, uint8_t direction, std::vector<RGBColor> colours, bool random_colours)
104{
105 uint8_t buffer[COUGARKEYBOARDCONTROLLER_WRITE_PACKET_SIZE] = { 0x00, 0x14, 0x2C };
106
107 buffer[COUGARKEYBOARDCONTROLLER_MODE_BYTE] = mode;
108 buffer[COUGARKEYBOARDCONTROLLER_SPEED_BYTE] = speed;
109 buffer[COUGARKEYBOARDCONTROLLER_BRIGHTNESS_BYTE] = brightness;
110 buffer[COUGARKEYBOARDCONTROLLER_RANDOM_BYTE] = (random_colours) ? 1 : 0;
111 buffer[COUGARKEYBOARDCONTROLLER_DIRECTION_BYTE] = direction;
112
113 switch(mode)
114 {
115 /*-----------------------------------------------------*\
116 | Off mode does not need any further settings & should |
117 | skip the default case to avoid an indexing error |
118 \*-----------------------------------------------------*/
119 case COUGARKEYBOARDCONTROLLER_MODE_OFF:
120 break;
121
122 /*-----------------------------------------------------*\
123 | Spectrum Cycle mode (Circle) always sets random |
124 \*-----------------------------------------------------*/
125 case COUGARKEYBOARDCONTROLLER_MODE_CIRCLE:
126 buffer[COUGARKEYBOARDCONTROLLER_RANDOM_BYTE] = 1;
127 break;
128
129 /*-----------------------------------------------------*\
130 | Wave mode does not have a true "random" colour and |
131 | needs to set the "rainbow" mode (val = 2) instead |
132 \*-----------------------------------------------------*/
133 case COUGARKEYBOARDCONTROLLER_MODE_WAVE:
134 buffer[COUGARKEYBOARDCONTROLLER_RANDOM_BYTE] = (random_colours) ? 2 : 0;
135 buffer[COUGARKEYBOARDCONTROLLER_DATA_BYTE] = 2;
136
137 case COUGARKEYBOARDCONTROLLER_MODE_RIPPLE:
138 case COUGARKEYBOARDCONTROLLER_MODE_SCAN:
139 {
140 uint8_t count = colours.size();
141 uint8_t timer = 100 / count;
142 buffer[COUGARKEYBOARDCONTROLLER_DATA_BYTE + 1] = count;
143
144 for(size_t i = 0; i < count; i++)
145 {
146 uint8_t offset = 11 + (i * 4);
147
148 buffer[offset] = (i + 1) * timer;
149 buffer[offset + 1] = RGBGetRValue(colours[i]);
150 buffer[offset + 2] = RGBGetGValue(colours[i]);
151 buffer[offset + 3] = RGBGetBValue(colours[i]);
152 }
153 }
154 break;
155
156 case COUGARKEYBOARDCONTROLLER_MODE_RHYTHM:
157 buffer[COUGARKEYBOARDCONTROLLER_RANDOM_BYTE] = (random_colours) ? 2 : 0;
158
159 default:
160 buffer[COUGARKEYBOARDCONTROLLER_DATA_BYTE + 1] = RGBGetRValue(colours[0]);

Callers 1

DeviceUpdateModeMethod · 0.45

Calls 2

hid_writeFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected