int updatergb_mouse(usbdevice* kb, int force){ if(!kb->active) return 0; lighting* lastlight = &kb->profile->lastlight; lighting* newlight = &kb->profile->currentmode->light; // Don't do anything if the lighting hasn't changed if(!force && !lastlight->forceupdate && !newlight->forceupdate && !rgbcmp(lastlight, newlight)) return 0; lastlight->forceupdate = newlight->forceupdate = 0; // Prevent writing to DPI LEDs or non-existent LED zones for the Glaive. int num_zones = IS_GLAIVE(kb) ? 3 : N_MOUSE_ZONES; // Send the RGB values for each zone to the mouse uchar data_pkt[2][MSG_SIZE] = { { 0x07, 0x22, num_zones, 0x01, 0 }, // RGB colors { 0x07, 0x05, 0x02, 0 } // Lighting on/off }; uchar* rgb_data = &data_pkt[0][4]; for(int i = 0; i < N_MOUSE_ZONES; i++){ if (IS_GLAIVE(kb) && i != 0 && i != 1 && i != 5) continue; *rgb_data++ = i + 1; *rgb_data++ = newlight->r[LED_MOUSE + i]; *rgb_data++ = newlight->g[LED_MOUSE + i]; *rgb_data++ = newlight->b[LED_MOUSE + i]; } // Send RGB data if(!usbsend(kb, data_pkt[0], 1)) return -1; int was_black = isblack(kb, lastlight), is_black = isblack(kb, newlight); if(is_black){ // If the lighting is black, send the deactivation packet (M65 only) if(!usbsend(kb, data_pkt[1], 1)) return -1; } else if(was_black || force){ // If the lighting WAS black, or if we're on forced update, send the activation packet data_pkt[1][4] = 1; if(!usbsend(kb, data_pkt[1], 1)) return -1; } memcpy(lastlight, newlight, sizeof(lighting)); return 0; }
int updatergb_mouse(usbdevice* kb, int force){ if(!kb->active) return 0; lighting* lastlight = &kb->profile->lastlight; lighting* newlight = &kb->profile->currentmode->light; // Don't do anything if the lighting hasn't changed if(!force && !lastlight->forceupdate && !newlight->forceupdate && !rgbcmp(lastlight, newlight)) return 0; lastlight->forceupdate = newlight->forceupdate = 0; // Send the RGB values for each zone to the mouse uchar data_pkt[2][MSG_SIZE] = { { 0x07, 0x22, 0x04, 0x01, 0 }, // RGB colors { 0x07, 0x05, 0x02, 0 } // Lighting on/off }; uchar* rgb_data = &data_pkt[0][4]; for(int i = 0; i < N_MOUSE_ZONES; i++){ *rgb_data++ = i + 1; *rgb_data++ = newlight->r[LED_MOUSE + i]; *rgb_data++ = newlight->g[LED_MOUSE + i]; *rgb_data++ = newlight->b[LED_MOUSE + i]; } int was_black = isblack(lastlight), is_black = isblack(newlight); // Send RGB data if(!usbsend(kb, data_pkt[0], 1)) return -1; if(is_black){ // If the lighting is black, send the deactivation packet if(!usbsend(kb, data_pkt[1], 1)) return -1; } else if(was_black || force){ // If the lighting WAS black, send the activation packet data_pkt[1][4] = 1; if(!usbsend(kb, data_pkt[1], 1)) return -1; } memcpy(lastlight, newlight, sizeof(lighting)); return 0; }