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

Feature: Encoder layers #333

Open
benjizhai opened this issue Nov 5, 2020 · 3 comments
Open

Feature: Encoder layers #333

benjizhai opened this issue Nov 5, 2020 · 3 comments
Labels
core Core functionality/behavior of ZMK enhancement New feature or request keymaps PRs and issues related to keymaps

Comments

@benjizhai
Copy link

benjizhai commented Nov 5, 2020

Problem

The encoder (AB and pushbutton) functions are defined per layer. Adding multiple functions to encoders are cumbersome and would involve many duplications of each layer.

Proposal

  • Implement a separate set of encoder layers, plus an override of the encoder functions per layer. If &trans is defined then no override takes place.
  • Add "encoder momentary" &emo, "encoder toggle" &etog, and "encoder layer raise/lower" &einc &edec references.

Example

An example keymap with 2 normal keys and 2 encoders.

/ {
	keymap {
		compatible = "zmk,keymap";

		default_layer {
			bindings = < &tog 1    &kp Z    &kp M    &kp K>;   //normal keys + pushbutton override
			sensor-bindings = <&inc_dec_cp C_VOLUME_UP C_VOLUME_DOWN   &inc_dec_cp C_BRI_INC C_BRI_DEC  >;   // encoder override
                };

		lower_layer {
			bindings = < &tog 1    &einc    &trans    &trans>;   //normal keys + pushbutton override
			sensor-bindings = <&trans &trans &trans &trans>;   // encoder override
                };
	};

	encodermap {
		compatible = "zmk,encodermap";

		default_layer {
			bindings = <&C_MUTE    &C_BKLT_TOG>;   // pushbuttons
			sensor-bindings = <&inc_dec_cp C_VOLUME_UP C_VOLUME_DOWN   &inc_dec_cp C_BRI_INC C_BRI_DEC  >;   // encoders
                };

		lower_layer {
			bindings = < &kp M    &kp C>;   // pushbuttons
			sensor-bindings = <&kp LC(U) &kp LC(D) &kp N &kp LS(N)>;   // encoders
                };
	};

};

And define which keys in the key matrix correspond to encoder pushbuttons in .dtsi file

left_encoder0: encoder_0 {
		compatible = "alps,ec11";
		label = "ENCODER_0";
		a-gpios = <&pro_micro_a 3 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
		b-gpios = <&pro_micro_a 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
		resolution = <4>;
		btn-row = <0>;
		btn-col = <2>;
	};
left_encoder1: encoder_1 {
		compatible = "alps,ec11";
		label = "ENCODER_1";
		a-gpios = <&pro_micro_a 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
		b-gpios = <&pro_micro_a 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
		resolution = <4>;
		btn-row = <0>;
		btn-col = <3>;
	};
@innovaker innovaker added core Core functionality/behavior of ZMK enhancement New feature or request keymaps PRs and issues related to keymaps labels Nov 5, 2020
@joelspadin
Copy link
Collaborator

Keep in mind that encoders are currently the only type of sensor, but other types of sensors will likely be added in the future (sliders, trackballs, accelerometers?, etc.). Should these special layers only apply to encoders or to all sensors at the same time?

@innovaker
Copy link
Contributor

innovaker commented Nov 5, 2020

Thanks @benjizhai!

@joelspadin, I can envisage use cases for them, but they'd need to be optional. I believe @petejohanson's also keeping multiple types of sensors in mind as he revisits inter-node communications.

Also, let's keep in mind that we're currently fitting our square pegs into DT's round holes, so there might be come a point where it's wiser just to start working on the successor (built for purpose) rather than burning time trying to it with the current system.

@innovaker
Copy link
Contributor

Generally speaking I'd like us to avoid the route of duplicating behaviors. This has been discussed at length in #213, so I think we should think outside the box a bit before going down this path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality/behavior of ZMK enhancement New feature or request keymaps PRs and issues related to keymaps
Projects
None yet
Development

No branches or pull requests

3 participants