Skip to content

Commit

Permalink
Firmware v1.20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ccMSC committed Apr 25, 2015
2 parents edf84bc + 8bef88b commit 8849753
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 209 deletions.
28 changes: 9 additions & 19 deletions src/ckb-daemon/devnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ unsigned readlines(int fd, const char** input){

void readcmd(usbdevice* kb, const char* line){
usbdevice* kb0 = kb;
if(IS_CONNECTED(kb))
pthread_mutex_lock(&kb->mutex);
char* word = malloc(strlen(line) + 1);
int wordlen;
const char* newline = 0;
Expand Down Expand Up @@ -350,10 +348,6 @@ void readcmd(usbdevice* kb, const char* line){
// Send the RGB command to the last device if its colors changed
if(kb != prevkb){
updatergb(prevkb, 0);
if(IS_CONNECTED(prevkb))
pthread_mutex_unlock(&prevkb->mutex);
if(IS_CONNECTED(kb))
pthread_mutex_lock(&kb->mutex);
}
}
// Check for a command word
Expand Down Expand Up @@ -504,10 +498,6 @@ void readcmd(usbdevice* kb, const char* line){
// Send the RGB command to the last device if its colors changed
if(kb != prevkb){
updatergb(prevkb, 0);
if(IS_CONNECTED(prevkb))
pthread_mutex_unlock(&prevkb->mutex);
if(IS_CONNECTED(kb))
pthread_mutex_lock(&kb->mutex);
}
}
continue;
Expand Down Expand Up @@ -620,7 +610,7 @@ void readcmd(usbdevice* kb, const char* line){
continue;
case NAME: case IOFF: case ION: case IAUTO: case INOTIFY:
// All of the above just parse the whole word
handler(mode, keymap, notifynumber, 0, word);
handler(kb, mode, keymap, notifynumber, 0, word);
continue;
case PROFILENAME:
// Profile name is the same, but takes a different parameter
Expand All @@ -642,20 +632,20 @@ void readcmd(usbdevice* kb, const char* line){
// RGB command has a special response for "on", "off", and a hex constant
int r, g, b;
if(!strcmp(word, "on")){
cmd_rgbon(mode);
cmd_rgbon(kb, mode);
continue;
} else if(!strcmp(word, "off")){
cmd_rgboff(mode);
cmd_rgboff(kb, mode);
continue;
} else if(sscanf(word, "%02x%02x%02x", &r, &g, &b) == 3){
for(int i = 0; i < N_KEYS; i++)
cmd_rgb(mode, keymap, notifynumber, i, word);
cmd_rgb(kb, mode, keymap, notifynumber, i, word);
continue;
}
} case MACRO:
if(!strcmp(word, "clear")){
// Macro has a special clear command
cmd_macroclear(mode);
cmd_macroclear(kb, mode);
continue;
}
break;
Expand All @@ -682,7 +672,7 @@ void readcmd(usbdevice* kb, const char* line){
// Macros have a separate left-side handler
if(command == MACRO){
word[left] = 0;
cmd_macro(mode, keymap, word, right);
cmd_macro(kb, mode, keymap, word, right);
continue;
}
// Scan the left side for key names and run the request command
Expand All @@ -693,16 +683,16 @@ void readcmd(usbdevice* kb, const char* line){
if(!strcmp(keyname, "all")){
// Set all keys
for(int i = 0; i < N_KEYS; i++)
handler(mode, keymap, notifynumber, i, right);
handler(kb, mode, keymap, notifynumber, i, right);
} else if((sscanf(keyname, "#%d", &keycode) && keycode >= 0 && keycode < N_KEYS)
|| (sscanf(keyname, "#x%x", &keycode) && keycode >= 0 && keycode < N_KEYS)){
// Set a key numerically
handler(mode, keymap, notifynumber, keycode, right);
handler(kb, mode, keymap, notifynumber, keycode, right);
} else {
// Find this key in the keymap
for(unsigned i = 0; i < N_KEYS; i++){
if(keymap[i].name && !strcmp(keyname, keymap[i].name)){
handler(mode, keymap, notifynumber, i, right);
handler(kb, mode, keymap, notifynumber, i, right);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ckb-daemon/devnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef enum {

FWUPDATE
} cmd;
typedef void (*cmdhandler)(usbmode*, const key*, int, int, const char*);
typedef void (*cmdhandler)(usbdevice*, usbmode*, const key*, int, int, const char*);

// Reads input from the command FIFO
void readcmd(usbdevice* kb, const char* line);
Expand Down
6 changes: 5 additions & 1 deletion src/ckb-daemon/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ int getfwversion(usbdevice* kb){
// Wait for the response
DELAY_SHORT;
uchar in_pkt[MSG_SIZE];
if(!usbinput(kb, in_pkt) || in_pkt[0] != 0x0e || in_pkt[1] != 0x01)
if(!usbinput(kb, in_pkt))
return -1;
if(in_pkt[0] != 0x0e || in_pkt[1] != 0x01){
printf("Error: %s:%d: Bad input header\n", __FILE_NOPATH__, __LINE__);
return -1;
}
short vendor, product, version, bootloader;
// Copy the vendor ID, product ID, version, and poll rate from the firmware data
memcpy(&version, in_pkt + 8, 2);
Expand Down
10 changes: 5 additions & 5 deletions src/ckb-daemon/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void closebind(keybind* bind){
memset(bind, 0, sizeof(*bind));
}

void cmd_bind(usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to){
void cmd_bind(usbdevice* kb, usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to){
// Find the key to bind to
int tocode = 0;
if(sscanf(to, "#x%ux", &tocode) != 1 && sscanf(to, "#%u", &tocode) == 1){
Expand All @@ -170,15 +170,15 @@ void cmd_bind(usbmode* mode, const key* keymap, int dummy, int keyindex, const c
}
}

void cmd_unbind(usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to){
void cmd_unbind(usbdevice* kb, usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to){
mode->bind.base[keyindex] = KEY_UNBOUND;
}

void cmd_rebind(usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to){
void cmd_rebind(usbdevice* kb, usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to){
mode->bind.base[keyindex] = keymap[keyindex].scan;
}

void cmd_macro(usbmode* mode, const key* keymap, const char* keys, const char* assignment){
void cmd_macro(usbdevice* kb, usbmode* mode, const key* keymap, const char* keys, const char* assignment){
keybind* bind = &mode->bind;
if(bind->macrocount >= MACRO_MAX)
return;
Expand Down Expand Up @@ -277,7 +277,7 @@ void cmd_macro(usbmode* mode, const key* keymap, const char* keys, const char* a
bind->macros = realloc(bind->macros, (bind->macrocap += 16) * sizeof(keymacro));
}

void cmd_macroclear(usbmode* mode){
void cmd_macroclear(usbdevice* kb, usbmode* mode){
keybind* bind = &mode->bind;
for(int i = 0; i < bind->macrocount; i++)
free(bind->macros[i].actions);
Expand Down
10 changes: 5 additions & 5 deletions src/ckb-daemon/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ void initbind(keybind* bind, const key* keymap);
void closebind(keybind* bind);

// Binds a key
void cmd_bind(usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to);
void cmd_bind(usbdevice* kb, usbmode* mode, const key* keymap, int dummy, int keyindex, const char* to);
// Unbinds a key
void cmd_unbind(usbmode* mode, const key* keymap, int dummy, int keyindex, const char* ignored);
void cmd_unbind(usbdevice* kb, usbmode* mode, const key* keymap, int dummy, int keyindex, const char* ignored);
// Resets a key binding
void cmd_rebind(usbmode* mode, const key* keymap, int dummy, int keyindex, const char* ignored);
void cmd_rebind(usbdevice* kb, usbmode* mode, const key* keymap, int dummy, int keyindex, const char* ignored);
// Creates or updates a macro
void cmd_macro(usbmode* mode, const key* keymap, const char* keys, const char* assignment);
void cmd_macro(usbdevice* kb, usbmode* mode, const key* keymap, const char* keys, const char* assignment);
// Clears all macros
void cmd_macroclear(usbmode* mode);
void cmd_macroclear(usbdevice* kb, usbmode* mode);

#ifdef OS_LINUX
// Is a key a modifier?
Expand Down
2 changes: 1 addition & 1 deletion src/ckb-daemon/input_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void os_updateindicators(usbdevice* kb, int force){
ileds = (ileds & ~mode->ioff) | mode->ion;
if(force || ileds != kb->ileds){
kb->ileds = ileds;
struct usbdevfs_ctrltransfer transfer = { 0x21, 0x09, 0x0200, 0x00, 1, 500, &kb->ileds };
struct usbdevfs_ctrltransfer transfer = { 0x21, 0x09, 0x0200, 0x00, 1, 5000, &kb->ileds };
ioctl(kb->handle, USBDEVFS_CONTROL, &transfer);
}
}
Expand Down
Loading

0 comments on commit 8849753

Please sign in to comment.