17 pthread_mutex_t 
usbmutex = PTHREAD_MUTEX_INITIALIZER;
 
  137     int kbfifo = kb->
infifo - 1;
 
  153         pthread_mutex_unlock(
dmutex(kb));
 
  156         int lines = 
readlines(kbfifo, linectx, &line);
 
  157         pthread_mutex_lock(
dmutex(kb));
 
  179     pthread_mutex_unlock(
dmutex(kb));
 
  298     vt->allocprofile(kb);
 
  309     vt->updateindicators(kb, 1);
 
  314     pthread_mutex_unlock(
imutex(kb));
 
  373     pthread_mutex_unlock(
imutex(kb));
 
  376     pthread_mutex_unlock(
dmutex(kb));
 
  387     pthread_mutex_lock(
imutex(kb));
 
  389         ckb_err(
"Failed to create USB thread\n");
 
  436     if(kb->
vtable->updatergb(kb, 1) != 0)
 
  478     ckb_err(
"Reset failed. Disconnecting.\n");
 
  534     for(
int i = 0; i < count; i++){
 
  537             pthread_mutex_lock(
mmutex(kb)); 
 
  540             pthread_mutex_unlock(
mmutex(kb));
 
  603     for (
int try = 0; 
try < 5; 
try++) {
 
  605         pthread_mutex_lock(
mmutex(kb)); 
 
  607         int res = 
os_usbsend(kb, out_msg, 1, file, line);
 
  608         pthread_mutex_unlock(
mmutex(kb));
 
  611         else if (res == -1) {
 
  630     ckb_err_fn(
"Too many send/recv failures. Dropping.\n", file, line);
 
  678     pthread_mutex_lock(
imutex(kb));
 
  691     pthread_mutex_unlock(
imutex(kb));
 
  692     pthread_mutex_unlock(
dmutex(kb));
 
  693     pthread_join(kb->
thread, 0);
 
  694     pthread_mutex_lock(
dmutex(kb));
 
  699     kb->
vtable->freeprofile(kb);
 
#define nk95cmd(kb, command)
nk95cmd() macro is used to wrap _nk95cmd() with debugging information (file and lineno). the command structure is different:   Just the bits 23..16 are used as bits 7..0 for bRequest   Bits 15..0 are used as wValue 
 
static void * devmain(usbdevice *kb)
brief . 
 
void setupusb(usbdevice *kb)
 
int usb_tryreset(usbdevice *kb)
 
#define DELAY_MEDIUM(kb)
the medium delay is used after sending a command before waiting for the answer. 
 
int readcmd(usbdevice *kb, const char *line)
 
const char * vendor_str(short vendor)
brief . 
 
unsigned readlines(int fd, readlines_ctx ctx, const char **input)
 
#define DELAY_SHORT(kb)
USB delays for when the keyboards get picky about timing That was the original comment, but it is used anytime. The short delay is used before any send or receive. 
 
#define DELAY_LONG(kb)
The longest delay takes place where something went wrong (eg when resetting the device) ...
 
int mkdevpath(usbdevice *kb)
Create a dev path for the keyboard at index. Returns 0 on success. 
 
#define ckb_err(fmt, args...)
 
#define IS_RGB(vendor, product)
RGB vs non-RGB test (note: non-RGB Strafe is still considered "RGB" in that it shares the same protoc...
 
usbdevice keyboard[9]
remember all usb devices. Needed for closeusb(). 
 
int os_resetusb(usbdevice *kb, const char *file, int line)
os_resetusb is the os specific implementation for resetting usb 
 
void * os_inputmain(void *context)
os_inputmain is run in a separate thread and will be detached from the main thread, so it needs to clean up its own resources. 
 
void os_closeusb(usbdevice *kb)
os_closeusb unclaim it, destroy the udev device and clear data structures at kb 
 
int os_usbrecv(usbdevice *kb, uchar *in_msg, const char *file, int line)
os_usbrecv receives a max MSGSIZE long buffer from usb device 
 
int os_setupusb(usbdevice *kb)
os_setupusb OS-specific setup for a specific usb device. 
 
const devcmd vtable_mouse
 
#define IS_MONOCHROME(vendor, product)
The difference between non RGB and monochrome is, that monochrome has lights, but just in one color...
 
int _usbrecv(usbdevice *kb, const uchar *out_msg, uchar *in_msg, const char *file, int line)
 
volatile int reset_stop
brief . 
 
#define IS_MOUSE(vendor, product)
Mouse vs keyboard test. 
 
#define NK95_HWON
Hardware playback on. 
 
int hwload_mode
hwload_mode is defined in device.c 
 
static const devcmd * get_vtable(short vendor, short product)
brief . 
 
void readlines_ctx_init(readlines_ctx *ctx)
 
const char *const devpath
 
#define ckb_info(fmt, args...)
 
int _resetusb(usbdevice *kb, const char *file, int line)
 
static void * _setupusb(void *context)
brief . 
 
#define INDEX_OF(entry, array)
 
#define USB_DELAY_DEFAULT
This constant is used to initialize kb->usbdelay. It is used in many places (see macros above) but of...
 
int _usbsend(usbdevice *kb, const uchar *messages, int count, const char *file, int line)
 
#define NEEDS_FW_UPDATE(kb)
 
const char * product_str(short product)
brief . 
 
const union devcmd * vtable
 
int closeusb(usbdevice *kb)
 
pthread_mutex_t usbmutex
brief . 
 
#define HAS_FEATURES(kb, feat)
 
Definitions for using USB interface. 
 
#define V_CORSAIR
For the following Defines please see "Detailed Description". 
 
#define resetusb(kb)
resetusb() is just a macro to call _resetusb() with debuggin constants (file, lineno) ...
 
const devcmd vtable_keyboard
RGB keyboard vtable holds functions for each device type. 
 
int os_usbsend(usbdevice *kb, const uchar *out_msg, int is_recv, const char *file, int line)
os_usbsend sends a data packet (MSG_SIZE = 64) Bytes long 
 
void readlines_ctx_free(readlines_ctx ctx)
 
int rmdevpath(usbdevice *kb)
Remove the dev path for the keyboard at index. Returns 0 on success. 
 
#define ckb_err_fn(fmt, file, line, args...)
 
void updateconnected()
Update the list of connected devices. 
 
int revertusb(usbdevice *kb)
 
const devcmd vtable_keyboard_nonrgb
 
#define setactive(kb, makeactive)
setactive() calls via the corresponding kb->vtable either the active() or the idle() function...