Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up tap_code functionality #4609

Merged
merged 8 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/config_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ If you define these options you will enable the associated feature, which may in
* Set this to the number of combos that you're using in the [Combo](feature_combo.md) feature.
* `#define COMBO_TERM 200`
* how long for the Combo keys to be detected. Defaults to `TAPPING_TERM` if not defined.
* `#define TAP_CODE_DELAY 100`
* Sets the delay between `register_code` and `unregister_code`, if you're having issues with it registering properly (common on VUSB boards).
drashna marked this conversation as resolved.
Show resolved Hide resolved

## RGB Light Configuration

Expand Down
2 changes: 2 additions & 0 deletions docs/feature_macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ Parallel to `register_code` function, this sends the `<kc>` keyup event to the c

This will send `register_code(<kc>)` and then `unregister_code(<kc>)`. This is useful if you want to send both the press and release events ("tap" the key, rather than hold it).

You can add a delay between the register and unregister event by adding `#define TAP_CODE_DELAY 100` to your `config.h` file.
drashna marked this conversation as resolved.
Show resolved Hide resolved

### `clear_keyboard();`

This will clear all mods and keys currently pressed.
Expand Down
8 changes: 8 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ void unregister_code16 (uint16_t code) {
}
}

void tap_code16(uint16_t code) {
register_code16(code);
#if defined(TAP_CODE_DELAY) && TAP_CODE_DELAY > 0
drashna marked this conversation as resolved.
Show resolved Hide resolved
wait_ms(TAP_CODE_DELAY);
#endif
unregister_code16(code);
}

__attribute__ ((weak))
bool process_action_kb(keyrecord_t *record) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion quantum/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void shutdown_user(void);

void register_code16(uint16_t code);
void unregister_code16(uint16_t code);
inline void tap_code16(uint16_t code) { register_code16(code); unregister_code16(code); }
void tap_code16(uint16_t code);

#ifdef BACKLIGHT_ENABLE
void backlight_init_ports(void);
Expand Down
12 changes: 12 additions & 0 deletions tmk_core/common/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,18 @@ void unregister_code(uint8_t code)
#endif
}

/** \brief Utilities for actions. (FIXME: Needs better description)
*
* FIXME: Needs documentation.
*/
void tap_code(uint8_t code) {
register_code(code);
#if defined(TAP_CODE_DELAY) && TAP_CODE_DELAY > 0
drashna marked this conversation as resolved.
Show resolved Hide resolved
wait_ms(TAP_CODE_DELAY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wait_ms(TAP_CODE_DELAY);
wait_ms(TAP_CODE_DELAY);

#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif

unregister_code(code);
}

/** \brief Utilities for actions. (FIXME: Needs better description)
*
* FIXME: Needs documentation.
Expand Down
2 changes: 1 addition & 1 deletion tmk_core/common/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void process_record(keyrecord_t *record);
void process_action(keyrecord_t *record, action_t action);
void register_code(uint8_t code);
void unregister_code(uint8_t code);
inline void tap_code(uint8_t code) { register_code(code); unregister_code(code); }
void tap_code(uint8_t code);
void register_mods(uint8_t mods);
void unregister_mods(uint8_t mods);
//void set_mods(uint8_t mods);
Expand Down