int loadrgb_mouse(usbdevice* kb, lighting* light, int mode){ uchar data_pkt[MSG_SIZE] = { 0x0e, 0x13, 0x10, 1, 0 }; uchar in_pkt[MSG_SIZE] = { 0 }; // Zone 1 if(!usbrecv(kb, data_pkt, in_pkt)) return -1; if(memcmp(in_pkt, data_pkt, 4)){ ckb_err("Bad input header\n"); return -2; } // Copy data light->r[LED_MOUSE] = in_pkt[4]; light->g[LED_MOUSE] = in_pkt[5]; light->b[LED_MOUSE] = in_pkt[6]; // Zone 2 data_pkt[2]++; if(!usbrecv(kb, data_pkt, in_pkt)) return -1; if(memcmp(in_pkt, data_pkt, 4)){ ckb_err("Bad input header\n"); return -2; } // Copy data light->r[LED_MOUSE + 1] = in_pkt[4]; light->g[LED_MOUSE + 1] = in_pkt[5]; light->b[LED_MOUSE + 1] = in_pkt[6]; // TODO: zone 4 for Sabre? return 0; }
int loadrgb_mouse(usbdevice* kb, lighting* light, int mode){ (void)mode; uchar data_pkt[MSG_SIZE] = { 0x0e, 0x13, 0x10, 1, 0 }; uchar in_pkt[MSG_SIZE] = { 0 }; // Load each RGB zone int zonecount = IS_SCIMITAR(kb) ? 4 : IS_SABRE(kb) ? 3 : 2; for(int i = 0; i < zonecount; i++){ if(!usbrecv(kb, data_pkt, in_pkt)) return -1; if(memcmp(in_pkt, data_pkt, 4)){ ckb_err("Bad input header\n"); return -2; } // Copy data int led = LED_MOUSE + i; if(led >= LED_DPI) led++; // Skip DPI light light->r[led] = in_pkt[4]; light->g[led] = in_pkt[5]; light->b[led] = in_pkt[6]; // Set packet for next zone data_pkt[2]++; } return 0; }
int cmd_hwload_mouse(usbdevice* kb, usbmode* dummy1, int dummy2, int apply, const char* dummy3){ DELAY_LONG(kb); hwprofile* hw = calloc(1, sizeof(hwprofile)); // Ask for profile and mode IDs uchar data_pkt[2][MSG_SIZE] = { { 0x0e, 0x15, 0x01, 0 }, { 0x0e, 0x16, 0x01, 0 } }; uchar in_pkt[MSG_SIZE]; for(int i = 0; i <= 1; i++){ data_pkt[0][3] = i; if(!usbrecv(kb, data_pkt[0], in_pkt)){ free(hw); return -1; } memcpy(hw->id + i, in_pkt + 4, sizeof(usbid)); } // Ask for profile and mode names for(int i = 0; i <= 1; i++){ data_pkt[1][3] = i; if(!usbrecv(kb, data_pkt[1],in_pkt)){ free(hw); return -1; } memcpy(hw->name[i], in_pkt + 4, PR_NAME_LEN * 2); } // Load the RGB and DPI settings if(loadrgb_mouse(kb, hw->light, 0) || loaddpi(kb, hw->dpi, hw->light)){ free(hw); return -1; } // Make the profile active (if requested) if(apply) hwtonative(kb->profile, hw, 1); // Free the existing profile (if any) free(kb->hw); kb->hw = hw; DELAY_LONG(kb); return 0; }