Files
zmk/docs/docs/behaviors/sensor-rotate.md
Nick Conway 3db163aa2c feat(behaviors): Add reusable sensor behaviors.
* Add new sensor behaviors that either take full bindings
  add definition, or accept parameters when bound in the
  keymap.
* Remove existing hard-coded key press sensor behavior
  and instead leverage new generic sensor behaviors to
  achieve the same functionality.

Co-authored-by: nick@conway.dev
2023-04-21 21:13:31 -07:00

2.3 KiB

title, sidebar_label
title sidebar_label
Sensor Rotation Sensor Rotation

Summary

The Sensor Rotation behavior triggers a different behavior, depending on whether the sensor is rotated clockwise or counter-clockwise. Two variants of this behavior are available, allowing either fully specifying the two behaviors and their parameters together, or allowing binding the sensor rotation with different clockwise and counterclockwise parameters in the keymap itself.

Sensor Rotation

The standard sensor rotation behavior allows fully binding behaviors to be invoked:

  • If rotated counter-clockwise, the first bound behavior is triggered.
  • If rotated clockwise, the second bound behavior is triggered.

Configuration

Here is an example that binds the RGB Underglow Behavior to change the RGB brightness:

/ {
    behaviors {
        rgb_encoder: rgb_encoder {
            compatible = "zmk,behavior-sensor-rotate";
            label = "RGB_ENCODER";
            #sensor-binding-cells = <0>;
            bindings = <&rgb_ug RGB_BRD>, <&rgb_ug RGB_BRI>;
        };
    };

    keymap {
        compatible = "zmk,keymap";

        base {
            ...
            sensor-bindings = <&rgb_encoder>;
        }
    };
};

Variable Sensor Rotation

The variable sensor rotation behavior is configured with two behaviors that each expect a single parameter, allowing the sensor rotation instance to be bound with two parameters at usage time.

  • If rotated counter-clockwise, the first bound behavior is triggered with the first parameter passed to the sensor rotation.
  • If rotated clockwise, the second bound behavior is triggered with the second parameter passed to the sensor rotation.

Configuration

Here is an example, showing how send key presses on rotation:

First, defining the sensor rotation itself, binding the Key Press Behavior twice, then binding it in the sensor-bindings property of a keymap layer:

/ {
    behaviors {
        rot_kp: behavior_sensor_rotate_kp {
            compatible = "zmk,behavior-sensor-rotate-var";
            label = "ENC_KP";
            #sensor-binding-cells = <2>;
            bindings = <&kp>, <&kp>;
        };
    };

    keymap {
        compatible = "zmk,keymap";
        base {
            ...
            sensor-bindings = <&rot_kp PG_DN PG_UP>;
        }
    }
};