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

feat(behaviors): Add a send string behavior #1893

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joelspadin
Copy link
Collaborator

This adds the following:

  • A character map driver API, which maps Unicode code points to behavior bindings.
  • A zmk,character-map driver which implements this API. This driver is designed for ROM efficiency, and it sends every value defined in the map to one behavior and passes any code point not in the map through to another. (A more flexible implementation that allows for a unique behavior binding per character could be added later if necessary.)
  • A zmk,send-string behavior, which users can define and bind to their keymaps to send strings.
  • A zmk_send_string() function, which queues the necessary behaviors to type a UTF-8 string. This is separated from the send string behavior since it could be used for other features such as Unicode key sequences, behaviors that print dynamic messages, etc.

@joelspadin joelspadin requested a review from a team as a code owner August 6, 2023 04:39
@caksoylar
Copy link
Contributor

I will do a second pass later but the docs look great, thank you for the effort you put into it! One suggestion I'd have is to put a pointer in the macros page pointing to this behavior for string sending purposes, similar to the pointer we have for modifier functions.

@jhorology
Copy link
Contributor

I've been waiting for this function. If there is a printf-style format function, I would be more than happy. Once I read the zephyr's code related to printf, It's difficult to understand to me.

@joelspadin
Copy link
Collaborator Author

One suggestion I'd have is to put a pointer in the macros page pointing to this behavior for string sending purposes, similar to the pointer we have for modifier functions.

Good idea. I'll add that.

I've been waiting for this function. If there is a printf-style format function, I would be more than happy. Once I read the zephyr's code related to printf, It's difficult to understand to me.

You could use the zmk_send_string() function with printf by printing to a string buffer and then sending that to the function, for example:

struct zmk_send_string_config config = {
    .character_map = DEVICE_DT_GET(DT_CHOSEN(zmk_character_map)),
    .wait_ms = CONFIG_ZMK_SEND_STRING_DEFAULT_WAIT_MS,
    .tap_ms = CONFIG_ZMK_SEND_STRING_DEFAULT_TAP_MS,
};

char string[32];
snprintf(string, sizeof(string), "Battery level is %u%%", zmk_battery_state_of_charge());

zmk_send_string(&config, position, string);

@joelspadin
Copy link
Collaborator Author

I added some macros for creating the config structs, so the code example above can now be simplified to

ZMK_BUILD_ASSERT_CHARACTER_MAP_CHOSEN();
...

char string[32];
snprintf(string, sizeof(string), "Battery level is %u%%", zmk_battery_state_of_charge());

zmk_send_string(&ZMK_SEND_STRING_CONFIG_DEFAULT, position, string);

docs/docs/config/behaviors.md Show resolved Hide resolved
docs/docs/behaviors/send-string.md Outdated Show resolved Hide resolved
docs/docs/behaviors/send-string.md Outdated Show resolved Hide resolved
@caksoylar
Copy link
Contributor

LGTM from a docs perspective 👍

@minhe7735
Copy link

pr broken because of this? 690bc1b

@dryqin
Copy link

dryqin commented Dec 15, 2023

Will be great if this gets merged!

@joelspadin
Copy link
Collaborator Author

Rebased and fixed everything to work with current ZMK.

This adds the following:

- A character map driver API, which maps Unicode code points to behavior
  bindings.

- A zmk,character-map driver which implements this API. This driver is
  designed for ROM efficiency, so it sends every value defined in the
  map to one behavior and passes any code point not in the map through
  to another. (A more flexible implementation that allows for a unique
  behavior binding per character could be added later if necessary.)

- A zmk,send-string behavior, which users can define and bind to their
  keymaps to send strings.

- A zmk_send_string() function, which queues the necessary behaviors
  to type a UTF-8 string. This is separated from the send string
  behavior since it could be used for other features such as Unicode
  key sequences, behaviors that print dynamic messages, etc.
@prez
Copy link

prez commented May 27, 2024

I've been eagerly waiting for this for almost a year now. Is there any chance we'll get to see this merged soon? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants