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
This commit is contained in:
Nick Conway
2022-05-23 16:33:08 -04:00
committed by Pete Johanson
parent 9a73650041
commit 3db163aa2c
17 changed files with 301 additions and 107 deletions

View File

@@ -26,8 +26,7 @@ typedef int (*behavior_keymap_binding_callback_t)(struct zmk_behavior_binding *b
struct zmk_behavior_binding_event event);
typedef int (*behavior_sensor_keymap_binding_callback_t)(struct zmk_behavior_binding *binding,
const struct device *sensor,
uint32_t virtual_key_position,
int64_t timestamp);
struct zmk_behavior_binding_event event);
enum behavior_locality {
BEHAVIOR_LOCALITY_CENTRAL,
@@ -161,13 +160,12 @@ static inline int z_impl_behavior_keymap_binding_released(struct zmk_behavior_bi
*/
__syscall int behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding,
const struct device *sensor,
uint32_t virtual_key_position,
int64_t timestamp);
struct zmk_behavior_binding_event event);
static inline int
z_impl_behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding,
const struct device *sensor,
uint32_t virtual_key_position, int64_t timestamp) {
struct zmk_behavior_binding_event event) {
const struct device *dev = device_get_binding(binding->behavior_dev);
if (dev == NULL) {
@@ -180,7 +178,7 @@ z_impl_behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *bin
return -ENOTSUP;
}
return api->sensor_binding_triggered(binding, sensor, virtual_key_position, timestamp);
return api->sensor_binding_triggered(binding, sensor, event);
}
/**