From dfacdf579e96373fb8762d9069aac0d64fe67035 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Thu, 11 Aug 2016 18:52:24 -0400 Subject: [PATCH 01/16] change long macro delay to introduce a fixed 5ms delay on all macros. --- src/ckb-daemon/input.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ckb-daemon/input.c b/src/ckb-daemon/input.c index 78a5c39..4a3d8d2 100644 --- a/src/ckb-daemon/input.c +++ b/src/ckb-daemon/input.c @@ -36,8 +36,7 @@ static void inputupdate_keys(usbdevice* kb){ else { os_keypress(kb, action->scan, action->down); if (kb->delay) { - if (a > 200) usleep (100); - else if (a > 20) usleep(30); + usleep(5000); // fixed 5ms delay } } } From 0358f717ec2d96122e5476937b7ad3f71b7858ef Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Thu, 11 Aug 2016 18:55:49 -0400 Subject: [PATCH 02/16] Reflect the changes this fork introduces in README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 354ca9c..16c7418 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +This `macro-delay` version introduces a fixed 5ms delay for macro playback when `delay` is active. + ckb: RGB Driver for Linux and OS X ================================== From 47fddda6ab7f9c376737dc0d0fa0ddf2e4c1bf51 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Fri, 12 Aug 2016 19:14:36 -0400 Subject: [PATCH 03/16] Implement setting fixed delay with daemon's command followed by delay time in microseconds. --- src/ckb-daemon/command.c | 15 +++++++++++++-- src/ckb-daemon/input.c | 2 +- src/ckb-daemon/structures.h | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ckb-daemon/command.c b/src/ckb-daemon/command.c index 9acffe7..d8df4d3 100644 --- a/src/ckb-daemon/command.c +++ b/src/ckb-daemon/command.c @@ -198,9 +198,20 @@ int readcmd(usbdevice* kb, const char* line){ } continue; } - case DELAY: - kb->delay = (!strcmp (word, "on")); // independendant from parameter to handle false commands like "delay off" + case DELAY: { + uint delay; + if(sscanf(word, "%u", &delay) == 1) { + // Add delay of `newdelay` microseconds to macro playback + kb->delay = delay; + } else if(strcmp(word, "on") == 0) { + // allow previous syntax, `delay on` means 30us delay + kb->delay = 30; + } else { + // bad parameter to handle false commands like "delay off" + kb->delay = 0; // No delay. + } continue; + } default:; } diff --git a/src/ckb-daemon/input.c b/src/ckb-daemon/input.c index 4a3d8d2..b7a06f9 100644 --- a/src/ckb-daemon/input.c +++ b/src/ckb-daemon/input.c @@ -36,7 +36,7 @@ static void inputupdate_keys(usbdevice* kb){ else { os_keypress(kb, action->scan, action->down); if (kb->delay) { - usleep(5000); // fixed 5ms delay + usleep(kb->delay); } } } diff --git a/src/ckb-daemon/structures.h b/src/ckb-daemon/structures.h index 0a284e5..382ab7b 100644 --- a/src/ckb-daemon/structures.h +++ b/src/ckb-daemon/structures.h @@ -247,7 +247,7 @@ typedef struct { // Color dithering in use char dither; // Flag to check, if large macros should be sent delayed - char delay; + uint delay; } usbdevice; #endif // STRUCTURES_H From 09e8ff60101e1a59b8ba96498599a4f033881862 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Fri, 12 Aug 2016 19:21:09 -0400 Subject: [PATCH 04/16] Update README.md to match what the code does. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 16c7418..2d1f908 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -This `macro-delay` version introduces a fixed 5ms delay for macro playback when `delay` is active. +This `macro-delay` version implements a delay between macro actions. +The delay is set with the ckb-daemon's `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. This also has a delay after the last action (still to be determined if that's a bug or a feature.) ckb: RGB Driver for Linux and OS X ================================== From a5fd2057d08626a88f2cc53384b153f3e3130a3d Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Fri, 12 Aug 2016 20:17:35 -0400 Subject: [PATCH 05/16] add delay to macro actions and handling of local delay in macro playback --- README.md | 39 +++++++++++++++++++++++++++++++++++++ src/ckb-daemon/command.c | 5 +++-- src/ckb-daemon/input.c | 12 +++++++++++- src/ckb-daemon/structures.h | 1 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2d1f908..48b3c32 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,45 @@ +ckb: RGB Driver for Linux and OS X with Macro Delay +=================================================== + This `macro-delay` version implements a delay between macro actions. The delay is set with the ckb-daemon's `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. This also has a delay after the last action (still to be determined if that's a bug or a feature.) +Examples: +```` + delay 1000 # delay 1,000us between action playback + delay on # delay 30us between action playback + # should be (how it worked before): + # 30us for 'short' macros (<200 actions) + # 100us for 'long' macros (>=200 acitions) + delay off # no delay + delay 0 # no delay + delay spearmint-potato # no delay +```` + +Macro Delay (specification) +-------- + +Allow each macro action to have a post-action delay associated with it. +If no delay is specified, then the global `delay` (above) is used. All +delay values are in microsecods (us). + +Example; define a macro for `g5` with a 5,000us delay between the `e` +down and `e` up actions. A 1,000us delay between `l` up and `a` down. +And a delay of one second (1,000,000us) after `y` up and before `enter`. + +```` + macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter +```` + +Example; use default delay between `d` down and `d` up and no delay (0us) +after `d` up. +```` + macro g5:+d,-d=0 +```` + +NOTE: Delays are limited to just over 1 hour (4,294,967,294us, 4,294 seconds, +71 minutes, 1.19 hours). + ckb: RGB Driver for Linux and OS X ================================== diff --git a/src/ckb-daemon/command.c b/src/ckb-daemon/command.c index d8df4d3..a61bfc5 100644 --- a/src/ckb-daemon/command.c +++ b/src/ckb-daemon/command.c @@ -204,8 +204,9 @@ int readcmd(usbdevice* kb, const char* line){ // Add delay of `newdelay` microseconds to macro playback kb->delay = delay; } else if(strcmp(word, "on") == 0) { - // allow previous syntax, `delay on` means 30us delay - kb->delay = 30; + // allow previous syntax, `delay on` means use old long macro delay + // 30us for short macros (<200 actions) and 100us for long macros (>=200 actions) + kb->delay = UINT_MAX; } else { // bad parameter to handle false commands like "delay off" kb->delay = 0; // No delay. diff --git a/src/ckb-daemon/input.c b/src/ckb-daemon/input.c index b7a06f9..abf01fb 100644 --- a/src/ckb-daemon/input.c +++ b/src/ckb-daemon/input.c @@ -35,8 +35,16 @@ static void inputupdate_keys(usbdevice* kb){ os_mousemove(kb, action->rel_x, action->rel_y); else { os_keypress(kb, action->scan, action->down); - if (kb->delay) { + if (action->delay != UINT_MAX) { // local delay set + usleep(action->delay); + } else if (kb->delay != UINT_MAX) { // use default global delay usleep(kb->delay); + } else { // use old long macro delay code + if (a > 200) { + usleep (100); + } else if (a > 20) { + usleep(30); + } } } } @@ -286,6 +294,7 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment){ // Set a key numerically macro.actions[macro.actioncount].scan = keymap[keycode].scan; macro.actions[macro.actioncount].down = down; + macro.actions[macro.actioncount].delay = UINT_MAX; macro.actioncount++; } else { // Find this key in the keymap @@ -293,6 +302,7 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment){ if(keymap[i].name && !strcmp(keyname + 1, keymap[i].name)){ macro.actions[macro.actioncount].scan = keymap[i].scan; macro.actions[macro.actioncount].down = down; + macro.actions[macro.actioncount].delay = UINT_MAX; macro.actioncount++; break; } diff --git a/src/ckb-daemon/structures.h b/src/ckb-daemon/structures.h index 382ab7b..e145a07 100644 --- a/src/ckb-daemon/structures.h +++ b/src/ckb-daemon/structures.h @@ -28,6 +28,7 @@ typedef struct { short scan; // Key scancode, OR short rel_x, rel_y; // Mouse movement char down; // 0 for keyup, 1 for keydown (ignored if rel_x != 0 || rel_y != 0) + uint delay; // us delay after action; UINT_MAX for use global delay } macroaction; // Key macro From e2fcb1321827fcac1d5d2a81950e3c055cdada5f Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Fri, 12 Aug 2016 22:13:44 -0400 Subject: [PATCH 06/16] Implement local, per action delay, for macro playback. --- src/ckb-daemon/input.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ckb-daemon/input.c b/src/ckb-daemon/input.c index abf01fb..69c9f67 100644 --- a/src/ckb-daemon/input.c +++ b/src/ckb-daemon/input.c @@ -248,7 +248,7 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment){ int empty = 1; int left = strlen(keys), right = strlen(assignment); int position = 0, field = 0; - char keyname[12]; + char keyname[24]; while(position < left && sscanf(keys + position, "%10[^+]%n", keyname, &field) == 1){ int keycode; if((sscanf(keyname, "#%d", &keycode) && keycode >= 0 && keycode < N_KEYS_INPUT) @@ -283,9 +283,23 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment){ // Scan the actions position = 0; field = 0; - while(position < right && sscanf(assignment + position, "%11[^,]%n", keyname, &field) == 1){ + // max action = old 11 chars plus 12 chars which is the max 32-bit int 4294967295 size + while(position < right && sscanf(assignment + position, "%23[^,]%n", keyname, &field) == 1){ if(!strcmp(keyname, "clear")) break; + + // Check for local key delay of the form '[+-]=' + long int long_delay; // scanned delay value, used to keep delay in range. + unsigned int delay = UINT_MAX; // computed delay value. UINT_MAX means use global delay value. + char real_keyname[12]; // temp to hold the left side (key) of the = + int scan_matches = sscanf(keyname, "%11[^=]=%ld", real_keyname, &long_delay); + if (scan_matches == 2) { + if (0 <= long_delay && long_delay < UINT_MAX) { + delay = (unsigned int)long_delay; + strcpy(keyname, real_keyname); // keyname[24], real_keyname[12] + } + } + int down = (keyname[0] == '+'); if(down || keyname[0] == '-'){ int keycode; @@ -294,7 +308,7 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment){ // Set a key numerically macro.actions[macro.actioncount].scan = keymap[keycode].scan; macro.actions[macro.actioncount].down = down; - macro.actions[macro.actioncount].delay = UINT_MAX; + macro.actions[macro.actioncount].delay = delay; macro.actioncount++; } else { // Find this key in the keymap @@ -302,7 +316,7 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment){ if(keymap[i].name && !strcmp(keyname + 1, keymap[i].name)){ macro.actions[macro.actioncount].scan = keymap[i].scan; macro.actions[macro.actioncount].down = down; - macro.actions[macro.actioncount].delay = UINT_MAX; + macro.actions[macro.actioncount].delay = delay; macro.actioncount++; break; } From 5b1cf99c914e5e9de1e3d7693ae91964787ede7f Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Fri, 12 Aug 2016 22:15:37 -0400 Subject: [PATCH 07/16] update readme syntax for macro delay --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 48b3c32..1cbf26c 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ The delay is set with the ckb-daemon's `delay` command followed by an unsigned i Examples: ```` delay 1000 # delay 1,000us between action playback - delay on # delay 30us between action playback - # should be (how it worked before): + delay on # long macro delay -- how it worked before: # 30us for 'short' macros (<200 actions) # 100us for 'long' macros (>=200 acitions) delay off # no delay From 5ee2d407406ed629daba37a9114ac0fa843346e9 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sat, 13 Aug 2016 11:31:02 -0400 Subject: [PATCH 08/16] update readme to flesh out specification of global and local delay syntax and meaning --- README.md | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1cbf26c..e93300a 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,50 @@ ckb: RGB Driver for Linux and OS X with Macro Delay =================================================== -This `macro-delay` version implements a delay between macro actions. -The delay is set with the ckb-daemon's `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. This also has a delay after the last action (still to be determined if that's a bug or a feature.) +This `macro-delay` version of `ckb` implements global and local delays during macro action playback. Setting a _global delay_ value introduces a time delay between events during macro execution or playback. _Local delay_ allows setting the delay after an individual event, overriding the global delay value for that event. Thus global delay can be used to set the overall playback speed of macros and local delays can be used to tune individual events within a macro. -Examples: +All delay values are specified in microseconds (us) and are positive values from `0` to `UINT_MAX - 1`. This means delays range from 0 to just over 1 hour (4,294,967,294us, +4,294 seconds, 71 minutes, or 1.19 hours). A value of zero (0) represents no delay between actions. + +Global Delay +------------ + +Global delay allows macro playback speed to be changed. It sets the time between (actually after) each recorded macro event. If global delay is set to 1 microsecond then a 1 ms delay will follow each individual macro event when the macro is triggered. + +The _global delay_ is set with the ckb-daemon's existing (in testing branch) `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. + +Global delay can also be set to `on` which maintains backwards compatibility with the current development of `ckb-daemon` for long macro playback. That is, setting the global delay to `on` introduces a 30us and a 100us delay based on the macro's length during playback. + +**NOTE**: This setting also introduces a delay after the last macro action. This functionality exists in the current testing branch and was left as-is. It is still to be determined if this is a bug or a feature. + +*Examples*: ```` delay 1000 # delay 1,000us between action playback delay on # long macro delay -- how it worked before: # 30us for 'short' macros (<200 actions) # 100us for 'long' macros (>=200 acitions) - delay off # no delay - delay 0 # no delay - delay spearmint-potato # no delay + delay off # no delay (same as 0) + delay 0 # no delay (same as off) + delay spearmint-potato # invalid setting, no change in delay ```` -Macro Delay (specification) --------- +Local Delay +----------- -Allow each macro action to have a post-action delay associated with it. -If no delay is specified, then the global `delay` (above) is used. All -delay values are in microsecods (us). +Local Delay allows each macro action to have a post-action delay associated with it. This allows a macro to vary it's playback speed for each event. If no local delay is specified for a macro action, then the global `delay` (above) is used. All delay values are in microsecods (us) as with the global delay setting. -Example; define a macro for `g5` with a 5,000us delay between the `e` -down and `e` up actions. A 1,000us delay between `l` up and `a` down. -And a delay of one second (1,000,000us) after `y` up and before `enter`. +*Example*: define a macro for `g5` with a 5,000us delay between the `e` down and `e` up actions. A 1,000us delay between `l` up and `a` down, a delay of one second (1,000,000us) after `y` up and before `enter`, and the global delay for all other actions. ```` macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter ```` -Example; use default delay between `d` down and `d` up and no delay (0us) -after `d` up. +*Example*: use default delay between `d` down and `d` up and no delay (0us) after `d` up. This removes the noted feature/bug (above) where the last action has a trailing delay associated with it. + ```` macro g5:+d,-d=0 ```` -NOTE: Delays are limited to just over 1 hour (4,294,967,294us, 4,294 seconds, -71 minutes, 1.19 hours). - ckb: RGB Driver for Linux and OS X ================================== From 2eed13713e0ad85d384e8ab7976c23927fcb0857 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sat, 13 Aug 2016 11:50:34 -0400 Subject: [PATCH 09/16] Move macro delay specification out of README.md into MACRO-DELAY.md --- MACRO-DELAY.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 47 ----------------------------------------------- 2 files changed, 46 insertions(+), 47 deletions(-) create mode 100644 MACRO-DELAY.md diff --git a/MACRO-DELAY.md b/MACRO-DELAY.md new file mode 100644 index 0000000..3f7d111 --- /dev/null +++ b/MACRO-DELAY.md @@ -0,0 +1,46 @@ +ckb: RGB Driver for Linux and OS X with Macro Delay +=================================================== + +This `macro-delay` version of `ckb` implements global and local delays during macro action playback. Setting a _global delay_ value introduces a time delay between events during macro execution or playback. _Local delay_ allows setting the delay after an individual event, overriding the global delay value for that event. Thus global delay can be used to set the overall playback speed of macros and local delays can be used to tune individual events within a macro. + +All delay values are specified in microseconds (us) and are positive values from `0` to `UINT_MAX - 1`. This means delays range from 0 to just over 1 hour (4,294,967,294us, +4,294 seconds, 71 minutes, or 1.19 hours). A value of zero (0) represents no delay between actions. + +Global Delay +------------ + +Global delay allows macro playback speed to be changed. It sets the time between (actually after) each recorded macro event. If global delay is set to 1 microsecond then a 1 ms delay will follow each individual macro event when the macro is triggered. + +The _global delay_ is set with the ckb-daemon's existing (in testing branch) `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. + +Global delay can also be set to `on` which maintains backwards compatibility with the current development of `ckb-daemon` for long macro playback. That is, setting the global delay to `on` introduces a 30us and a 100us delay based on the macro's length during playback. + +**NOTE**: This setting also introduces a delay after the last macro action. This functionality exists in the current testing branch and was left as-is. It is still to be determined if this is a bug or a feature. + +*Examples*: +```` + delay 1000 # delay 1,000us between action playback + delay on # long macro delay -- how it worked before: + # 30us for 'short' macros (<200 actions) + # 100us for 'long' macros (>=200 acitions) + delay off # no delay (same as 0) + delay 0 # no delay (same as off) + delay spearmint-potato # invalid setting, no change in delay +```` + +Local Delay +----------- + +Local Delay allows each macro action to have a post-action delay associated with it. This allows a macro to vary it's playback speed for each event. If no local delay is specified for a macro action, then the global `delay` (above) is used. All delay values are in microsecods (us) as with the global delay setting. + +*Example*: define a macro for `g5` with a 5,000us delay between the `e` down and `e` up actions. A 1,000us delay between `l` up and `a` down, a delay of one second (1,000,000us) after `y` up and before `enter`, and the global delay for all other actions. + +```` + macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter +```` + +*Example*: use default delay between `d` down and `d` up and no delay (0us) after `d` up. This removes the noted feature/bug (above) where the last action has a trailing delay associated with it. + +```` + macro g5:+d,-d=0 +```` diff --git a/README.md b/README.md index e93300a..354ca9c 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,3 @@ -ckb: RGB Driver for Linux and OS X with Macro Delay -=================================================== - -This `macro-delay` version of `ckb` implements global and local delays during macro action playback. Setting a _global delay_ value introduces a time delay between events during macro execution or playback. _Local delay_ allows setting the delay after an individual event, overriding the global delay value for that event. Thus global delay can be used to set the overall playback speed of macros and local delays can be used to tune individual events within a macro. - -All delay values are specified in microseconds (us) and are positive values from `0` to `UINT_MAX - 1`. This means delays range from 0 to just over 1 hour (4,294,967,294us, -4,294 seconds, 71 minutes, or 1.19 hours). A value of zero (0) represents no delay between actions. - -Global Delay ------------- - -Global delay allows macro playback speed to be changed. It sets the time between (actually after) each recorded macro event. If global delay is set to 1 microsecond then a 1 ms delay will follow each individual macro event when the macro is triggered. - -The _global delay_ is set with the ckb-daemon's existing (in testing branch) `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. - -Global delay can also be set to `on` which maintains backwards compatibility with the current development of `ckb-daemon` for long macro playback. That is, setting the global delay to `on` introduces a 30us and a 100us delay based on the macro's length during playback. - -**NOTE**: This setting also introduces a delay after the last macro action. This functionality exists in the current testing branch and was left as-is. It is still to be determined if this is a bug or a feature. - -*Examples*: -```` - delay 1000 # delay 1,000us between action playback - delay on # long macro delay -- how it worked before: - # 30us for 'short' macros (<200 actions) - # 100us for 'long' macros (>=200 acitions) - delay off # no delay (same as 0) - delay 0 # no delay (same as off) - delay spearmint-potato # invalid setting, no change in delay -```` - -Local Delay ------------ - -Local Delay allows each macro action to have a post-action delay associated with it. This allows a macro to vary it's playback speed for each event. If no local delay is specified for a macro action, then the global `delay` (above) is used. All delay values are in microsecods (us) as with the global delay setting. - -*Example*: define a macro for `g5` with a 5,000us delay between the `e` down and `e` up actions. A 1,000us delay between `l` up and `a` down, a delay of one second (1,000,000us) after `y` up and before `enter`, and the global delay for all other actions. - -```` - macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter -```` - -*Example*: use default delay between `d` down and `d` up and no delay (0us) after `d` up. This removes the noted feature/bug (above) where the last action has a trailing delay associated with it. - -```` - macro g5:+d,-d=0 -```` - ckb: RGB Driver for Linux and OS X ================================== From ee23e015990221009887b998ad5e04c47690c586 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sat, 13 Aug 2016 11:53:37 -0400 Subject: [PATCH 10/16] Remove trailing spaces in code and documentation --- MACRO-DELAY.md | 5 ++--- src/ckb-daemon/command.c | 6 +++--- src/ckb-daemon/input.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/MACRO-DELAY.md b/MACRO-DELAY.md index 3f7d111..8cde13c 100644 --- a/MACRO-DELAY.md +++ b/MACRO-DELAY.md @@ -3,15 +3,14 @@ ckb: RGB Driver for Linux and OS X with Macro Delay This `macro-delay` version of `ckb` implements global and local delays during macro action playback. Setting a _global delay_ value introduces a time delay between events during macro execution or playback. _Local delay_ allows setting the delay after an individual event, overriding the global delay value for that event. Thus global delay can be used to set the overall playback speed of macros and local delays can be used to tune individual events within a macro. -All delay values are specified in microseconds (us) and are positive values from `0` to `UINT_MAX - 1`. This means delays range from 0 to just over 1 hour (4,294,967,294us, -4,294 seconds, 71 minutes, or 1.19 hours). A value of zero (0) represents no delay between actions. +All delay values are specified in microseconds (us) and are positive values from `0` to `UINT_MAX - 1`. This means delays range from 0 to just over 1 hour (4,294,967,294us, 4,294 seconds, 71 minutes, or 1.19 hours). A value of zero (0) represents no delay between actions. Global Delay ------------ Global delay allows macro playback speed to be changed. It sets the time between (actually after) each recorded macro event. If global delay is set to 1 microsecond then a 1 ms delay will follow each individual macro event when the macro is triggered. -The _global delay_ is set with the ckb-daemon's existing (in testing branch) `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. +The _global delay_ is set with the ckb-daemon's existing (in testing branch) `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. Global delay can also be set to `on` which maintains backwards compatibility with the current development of `ckb-daemon` for long macro playback. That is, setting the global delay to `on` introduces a 30us and a 100us delay based on the macro's length during playback. diff --git a/src/ckb-daemon/command.c b/src/ckb-daemon/command.c index a61bfc5..6a03630 100644 --- a/src/ckb-daemon/command.c +++ b/src/ckb-daemon/command.c @@ -202,13 +202,13 @@ int readcmd(usbdevice* kb, const char* line){ uint delay; if(sscanf(word, "%u", &delay) == 1) { // Add delay of `newdelay` microseconds to macro playback - kb->delay = delay; - } else if(strcmp(word, "on") == 0) { + kb->delay = delay; + } else if(strcmp(word, "on") == 0) { // allow previous syntax, `delay on` means use old long macro delay // 30us for short macros (<200 actions) and 100us for long macros (>=200 actions) kb->delay = UINT_MAX; } else { - // bad parameter to handle false commands like "delay off" + // bad parameter to handle false commands like "delay off" kb->delay = 0; // No delay. } continue; diff --git a/src/ckb-daemon/input.c b/src/ckb-daemon/input.c index 69c9f67..2335170 100644 --- a/src/ckb-daemon/input.c +++ b/src/ckb-daemon/input.c @@ -292,13 +292,13 @@ static void _cmd_macro(usbmode* mode, const char* keys, const char* assignment){ long int long_delay; // scanned delay value, used to keep delay in range. unsigned int delay = UINT_MAX; // computed delay value. UINT_MAX means use global delay value. char real_keyname[12]; // temp to hold the left side (key) of the = - int scan_matches = sscanf(keyname, "%11[^=]=%ld", real_keyname, &long_delay); + int scan_matches = sscanf(keyname, "%11[^=]=%ld", real_keyname, &long_delay); if (scan_matches == 2) { if (0 <= long_delay && long_delay < UINT_MAX) { delay = (unsigned int)long_delay; strcpy(keyname, real_keyname); // keyname[24], real_keyname[12] } - } + } int down = (keyname[0] == '+'); if(down || keyname[0] == '-'){ From bfd3d49087acc9466ead2794ed11daff63ab6656 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sat, 13 Aug 2016 11:55:44 -0400 Subject: [PATCH 11/16] Update specification to match invalid setting of global delay --- MACRO-DELAY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MACRO-DELAY.md b/MACRO-DELAY.md index 8cde13c..646ba22 100644 --- a/MACRO-DELAY.md +++ b/MACRO-DELAY.md @@ -24,7 +24,7 @@ Global delay can also be set to `on` which maintains backwards compatibility wit # 100us for 'long' macros (>=200 acitions) delay off # no delay (same as 0) delay 0 # no delay (same as off) - delay spearmint-potato # invalid setting, no change in delay + delay spearmint-potato # invalid input, no delay (same as off) ```` Local Delay From ed088366f0e9213bcc1a1df07cffbb18e4cd22f7 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sun, 14 Aug 2016 13:41:55 -0400 Subject: [PATCH 12/16] Remove MACRO-DELAY.md and integrate macro delay content into DAEMON.md --- DAEMON.md | 35 +++++++++++++++++++++++++++++++ MACRO-DELAY.md | 45 ---------------------------------------- src/ckb-daemon/command.c | 3 +-- 3 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 MACRO-DELAY.md diff --git a/DAEMON.md b/DAEMON.md index 88cf37a..c08b848 100644 --- a/DAEMON.md +++ b/DAEMON.md @@ -128,6 +128,41 @@ Macros are a more advanced form of key binding, controlled with the `macro` comm Assigning a macro to a key will cause its binding to be ignored; for instance, `macro a:+b,-b` will cause A to generate a B character regardless of its binding. However, `macro lctrl+a:+b,-b` will cause A to generate a B only when Ctrl is also held down. +### Macro playback delay + +There are two types of playback delay that can be set with macros; global and local. Setting a _global delay_ value introduces a time delay between events during macro execution or playback. _Local delay_ allows setting the delay after an individual event, overriding the global delay value for that event. Thus global delay can be used to set the overall playback speed of macros and local delays can be used to tune individual events within a macro. + +All delay values are specified in microseconds (us) and are positive values from `0` to `UINT_MAX - 1`. This means delays range from 0 to just over 1 hour (4,294,967,294us, 4,294 seconds, 71 minutes, or 1.19 hours). A value of zero (0) represents no delay between actions. + +#### Global macro delay (default delay) + +Global delay allows macro playback speed to be changed. It sets the time between (actually after) each recorded macro event. If global delay is set to 1 microsecond then a 1 ms delay will follow each individual macro event when the macro is triggered. + +The _global delay_ is set with the ckb-daemon's existing (in testing branch) `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. + +Global delay can also be set to `on` which maintains backwards compatibility with the current development of `ckb-daemon` for long macro playback. That is, setting the global delay to `on` introduces a 30us and a 100us delay based on the macro's length during playback. + +**NOTE**: This setting also introduces a delay after the last macro action. This functionality exists in the current testing branch and was left as-is. It is still to be determined if this is a bug or a feature. + +**Examples:** +`delay 1000` sets a 1,000us delay between action playback +`delay on` sets long macro delay; 30us for actions between 20 and 200, 100us for actions > 200 +`delay off` sets no delay (same as 0) +`delay 0` sets no delay (same as off) +`delay spearmint-potato` is invalid input, sets no delay (same as off) + +#### Local macro delay (keystroke delay) + +Local Delay allows each macro action to have a post-action delay associated with it. This allows a macro to vary it's playback speed for each event. If no local delay is specified for a macro action, then the global `delay` (above) is used. All delay values are in microsecods (us) as with the global delay setting. + +***Example:*** define a macro for `g5` with a 5,000us delay between the `e` down and `e` up actions. A 1,000us delay between `l` up and `a` down, a delay of one second (1,000,000us) after `y` up and before `enter`, and the global delay for all other actions. + +`macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter` + +***Example:*** use default delay between `d` down and `d` up and no delay (0us) after `d` up. This removes the noted feature/bug (above) where the last action has a trailing delay associated with it. + +`macro g5:+d,-d=0` + DPI and mouse settings ---------------------- diff --git a/MACRO-DELAY.md b/MACRO-DELAY.md deleted file mode 100644 index 646ba22..0000000 --- a/MACRO-DELAY.md +++ /dev/null @@ -1,45 +0,0 @@ -ckb: RGB Driver for Linux and OS X with Macro Delay -=================================================== - -This `macro-delay` version of `ckb` implements global and local delays during macro action playback. Setting a _global delay_ value introduces a time delay between events during macro execution or playback. _Local delay_ allows setting the delay after an individual event, overriding the global delay value for that event. Thus global delay can be used to set the overall playback speed of macros and local delays can be used to tune individual events within a macro. - -All delay values are specified in microseconds (us) and are positive values from `0` to `UINT_MAX - 1`. This means delays range from 0 to just over 1 hour (4,294,967,294us, 4,294 seconds, 71 minutes, or 1.19 hours). A value of zero (0) represents no delay between actions. - -Global Delay ------------- - -Global delay allows macro playback speed to be changed. It sets the time between (actually after) each recorded macro event. If global delay is set to 1 microsecond then a 1 ms delay will follow each individual macro event when the macro is triggered. - -The _global delay_ is set with the ckb-daemon's existing (in testing branch) `delay` command followed by an unsigned integer representing the number of microseconds to wait after each macro action and before the next. - -Global delay can also be set to `on` which maintains backwards compatibility with the current development of `ckb-daemon` for long macro playback. That is, setting the global delay to `on` introduces a 30us and a 100us delay based on the macro's length during playback. - -**NOTE**: This setting also introduces a delay after the last macro action. This functionality exists in the current testing branch and was left as-is. It is still to be determined if this is a bug or a feature. - -*Examples*: -```` - delay 1000 # delay 1,000us between action playback - delay on # long macro delay -- how it worked before: - # 30us for 'short' macros (<200 actions) - # 100us for 'long' macros (>=200 acitions) - delay off # no delay (same as 0) - delay 0 # no delay (same as off) - delay spearmint-potato # invalid input, no delay (same as off) -```` - -Local Delay ------------ - -Local Delay allows each macro action to have a post-action delay associated with it. This allows a macro to vary it's playback speed for each event. If no local delay is specified for a macro action, then the global `delay` (above) is used. All delay values are in microsecods (us) as with the global delay setting. - -*Example*: define a macro for `g5` with a 5,000us delay between the `e` down and `e` up actions. A 1,000us delay between `l` up and `a` down, a delay of one second (1,000,000us) after `y` up and before `enter`, and the global delay for all other actions. - -```` - macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter -```` - -*Example*: use default delay between `d` down and `d` up and no delay (0us) after `d` up. This removes the noted feature/bug (above) where the last action has a trailing delay associated with it. - -```` - macro g5:+d,-d=0 -```` diff --git a/src/ckb-daemon/command.c b/src/ckb-daemon/command.c index 6a03630..43ff710 100644 --- a/src/ckb-daemon/command.c +++ b/src/ckb-daemon/command.c @@ -204,8 +204,7 @@ int readcmd(usbdevice* kb, const char* line){ // Add delay of `newdelay` microseconds to macro playback kb->delay = delay; } else if(strcmp(word, "on") == 0) { - // allow previous syntax, `delay on` means use old long macro delay - // 30us for short macros (<200 actions) and 100us for long macros (>=200 actions) + // allow previous syntax, `delay on` means use old `long macro delay` kb->delay = UINT_MAX; } else { // bad parameter to handle false commands like "delay off" From ca9eb63a9bd1522fe17f1d93dff293c7c1bc971d Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sun, 14 Aug 2016 13:43:59 -0400 Subject: [PATCH 13/16] Add periods at end of examples for macro delay in DAEMON.md --- DAEMON.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DAEMON.md b/DAEMON.md index c08b848..8e031c4 100644 --- a/DAEMON.md +++ b/DAEMON.md @@ -145,11 +145,11 @@ Global delay can also be set to `on` which maintains backwards compatibility wit **NOTE**: This setting also introduces a delay after the last macro action. This functionality exists in the current testing branch and was left as-is. It is still to be determined if this is a bug or a feature. **Examples:** -`delay 1000` sets a 1,000us delay between action playback -`delay on` sets long macro delay; 30us for actions between 20 and 200, 100us for actions > 200 -`delay off` sets no delay (same as 0) -`delay 0` sets no delay (same as off) -`delay spearmint-potato` is invalid input, sets no delay (same as off) +`delay 1000` sets a 1,000us delay between action playback. +`delay on` sets long macro delay; 30us for actions between 20 and 200, 100us for actions > 200. +`delay off` sets no delay (same as 0). +`delay 0` sets no delay (same as off). +`delay spearmint-potato` is invalid input, sets no delay (same as off). #### Local macro delay (keystroke delay) From 652b3ba299cabc4845e65767a352f2847bfdba98 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sun, 14 Aug 2016 13:44:59 -0400 Subject: [PATCH 14/16] Make examples for macro delay a bulleted list to match document's style --- DAEMON.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DAEMON.md b/DAEMON.md index 8e031c4..a06d364 100644 --- a/DAEMON.md +++ b/DAEMON.md @@ -145,11 +145,11 @@ Global delay can also be set to `on` which maintains backwards compatibility wit **NOTE**: This setting also introduces a delay after the last macro action. This functionality exists in the current testing branch and was left as-is. It is still to be determined if this is a bug or a feature. **Examples:** -`delay 1000` sets a 1,000us delay between action playback. -`delay on` sets long macro delay; 30us for actions between 20 and 200, 100us for actions > 200. -`delay off` sets no delay (same as 0). -`delay 0` sets no delay (same as off). -`delay spearmint-potato` is invalid input, sets no delay (same as off). +* `delay 1000` sets a 1,000us delay between action playback. +* `delay on` sets long macro delay; 30us for actions between 20 and 200, 100us for actions > 200. +* `delay off` sets no delay (same as 0). +* `delay 0` sets no delay (same as off). +* `delay spearmint-potato` is invalid input, sets no delay (same as off). #### Local macro delay (keystroke delay) From 99ffd3e5860312ad413e60d8ca168be39d41ba36 Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sun, 14 Aug 2016 13:46:06 -0400 Subject: [PATCH 15/16] Make examples for macro delay a bulleted list to match document's style --- DAEMON.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/DAEMON.md b/DAEMON.md index a06d364..681b212 100644 --- a/DAEMON.md +++ b/DAEMON.md @@ -155,13 +155,9 @@ Global delay can also be set to `on` which maintains backwards compatibility wit Local Delay allows each macro action to have a post-action delay associated with it. This allows a macro to vary it's playback speed for each event. If no local delay is specified for a macro action, then the global `delay` (above) is used. All delay values are in microsecods (us) as with the global delay setting. -***Example:*** define a macro for `g5` with a 5,000us delay between the `e` down and `e` up actions. A 1,000us delay between `l` up and `a` down, a delay of one second (1,000,000us) after `y` up and before `enter`, and the global delay for all other actions. - -`macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter` - -***Example:*** use default delay between `d` down and `d` up and no delay (0us) after `d` up. This removes the noted feature/bug (above) where the last action has a trailing delay associated with it. - -`macro g5:+d,-d=0` +***Examples:*** +* `macro g5:+d,-d,+e=5000,-e,+l,-l=10000,+a,-a,+y,-y=1000000,+enter,-enter` define a macro for `g5` with a 5,000us delay between the `e` down and `e` up actions. A 1,000us delay between `l` up and `a` down, a delay of one second (1,000,000us) after `y` up and before `enter`, and the global delay for all other actions. +* `macro g5:+d,-d=0` use default delay between `d` down and `d` up and no delay (0us) after `d` up. This removes the noted feature/bug (above) where the last action has a trailing delay associated with it. DPI and mouse settings ---------------------- From d6aa207202d44b236681340ae297c62607a79eaf Mon Sep 17 00:00:00 2001 From: Stephen Houser Date: Sun, 14 Aug 2016 13:52:54 -0400 Subject: [PATCH 16/16] Add uint bounds check for global delay setting. --- src/ckb-daemon/command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ckb-daemon/command.c b/src/ckb-daemon/command.c index 43ff710..a58adb4 100644 --- a/src/ckb-daemon/command.c +++ b/src/ckb-daemon/command.c @@ -199,10 +199,10 @@ int readcmd(usbdevice* kb, const char* line){ continue; } case DELAY: { - uint delay; - if(sscanf(word, "%u", &delay) == 1) { + long int delay; + if(sscanf(word, "%ld", &delay) == 1 && 0 <= delay && delay < UINT_MAX) { // Add delay of `newdelay` microseconds to macro playback - kb->delay = delay; + kb->delay = (unsigned int)delay; } else if(strcmp(word, "on") == 0) { // allow previous syntax, `delay on` means use old `long macro delay` kb->delay = UINT_MAX;