void cmd_notify(usbdevice* kb, usbmode* mode, int nnumber, int keyindex, const char* toggle){ if(keyindex >= N_KEYS_INPUT) return; pthread_mutex_lock(imutex(kb)); if(!strcmp(toggle, "on") || *toggle == 0) SET_KEYBIT(mode->notify[nnumber], keyindex); else if(!strcmp(toggle, "off")) CLEAR_KEYBIT(mode->notify[nnumber], keyindex); pthread_mutex_unlock(imutex(kb)); }
void hid_kb_translate(unsigned char* kbinput, int endpoint, int length, const unsigned char* urbinput){ if(length < 1) return; // LUT for HID -> Corsair scancodes (-1 for no scan code, -2 for currently unsupported) // Modified from Linux drivers/hid/usbhid/usbkbd.c, key codes replaced with array indices and K95 keys added static const short hid_codes[256] = { -1, -1, -1, -1, 37, 54, 52, 39, 27, 40, 41, 42, 32, 43, 44, 45, 56, 55, 33, 34, 25, 28, 38, 29, 31, 53, 26, 51, 30, 50, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 82, 0, 86, 24, 64, 23, 84, 35, 79, 80, 81, 46, 47, 12, 57, 58, 59, 36, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 72, 73, 74, 75, 76, 77, 78, 87, 88, 89, 95, 93, 94, 92, 102, 103, 104, 105, 106, 107, 115, 116, 117, 112, 113, 114, 108, 109, 110, 118, 119, 49, 69, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 98, -2, -2, -2, -2, -2, -2, 97, 130, 131, -1, -1, -1, -2, -1, -2, -2, -2, -2, -2, -2, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3, -1, -1, -1, // <- -3 = non-RGB program key 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 136, 137, 138, 139, 140, 141, 60, 48, 62, 61, 91, 90, 67, 68, 142, 143, 99, 101, -2, 130, 131, 97, -2, 133, 134, 135, -2, 96, -2, 132, -2, -2, 71, 71, 71, 71, -1, -1, }; switch(endpoint){ case 1: case -1: // EP 1: 6KRO input (RGB and non-RGB) // Clear previous input for(int i = 0; i < 256; i++){ if(hid_codes[i] >= 0) CLEAR_KEYBIT(kbinput, hid_codes[i]); } // Set new input for(int i = 0; i < 8; i++){ if((urbinput[0] >> i) & 1) SET_KEYBIT(kbinput, hid_codes[i + 224]); } for(int i = 2; i < length; i++){ if(urbinput[i] > 3){ int scan = hid_codes[urbinput[i]]; if(scan >= 0) SET_KEYBIT(kbinput, scan); else ckb_warn("Got unknown key press %d on EP 1\n", urbinput[i]); } } break; case -2: // EP 2 RGB: NKRO input if(urbinput[0] == 1){ // Type 1: standard key if(length != 21) return; for(int bit = 0; bit < 8; bit++){ if((urbinput[1] >> bit) & 1) SET_KEYBIT(kbinput, hid_codes[bit + 224]); else CLEAR_KEYBIT(kbinput, hid_codes[bit + 224]); } for(int byte = 0; byte < 19; byte++){ char input = urbinput[byte + 2]; for(int bit = 0; bit < 8; bit++){ int keybit = byte * 8 + bit; int scan = hid_codes[keybit]; if((input >> bit) & 1){ if(scan >= 0) SET_KEYBIT(kbinput, hid_codes[keybit]); else ckb_warn("Got unknown key press %d on EP 2\n", keybit); } else if(scan >= 0) CLEAR_KEYBIT(kbinput, hid_codes[keybit]); } } break; } else if(urbinput[0] == 2)
void cmd_notify(usbmode* mode, const key* keymap, int nnumber, int keyindex, const char* toggle){ if(!strcmp(toggle, "on") || *toggle == 0) SET_KEYBIT(mode->notify[nnumber], keyindex); else if(!strcmp(toggle, "off")) CLEAR_KEYBIT(mode->notify[nnumber], keyindex); }