From c0fdb586ef2689ac12c5b9dd25f228a16e1b8585 Mon Sep 17 00:00:00 2001 From: Nicolas Munnich Date: Sat, 29 Nov 2025 21:17:52 +0000 Subject: [PATCH] fixup! feat: Refactor behaviors, sensor to raise behavior_binding_event --- .vscode/settings.json | 3 ++- app/include/zmk/sensors.h | 2 +- app/src/behaviors/behavior_hold_tap.c | 8 ++++---- app/src/behaviors/behavior_sensor_rotate_common.c | 2 +- app/src/behaviors/behavior_sticky_key.c | 4 ++-- app/src/behaviors/behavior_tap_dance.c | 4 ++-- app/src/combo.c | 4 ++-- app/src/pointing/input_processor_behaviors.c | 3 ++- app/src/sensors.c | 9 +++++---- app/src/split/central.c | 8 +++++--- 10 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 83fb7ae3a..91d486fa8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { "files.associations": { "*.overlay": "dts", - "*.keymap": "dts" + "*.keymap": "dts", + "regex": "c" }, "python.analysis.include": ["app/scripts", "zephyr/scripts"], "[c]": { diff --git a/app/include/zmk/sensors.h b/app/include/zmk/sensors.h index 4adbffa16..ec2c8b955 100644 --- a/app/include/zmk/sensors.h +++ b/app/include/zmk/sensors.h @@ -36,7 +36,7 @@ struct zmk_sensor_channel_data { enum sensor_channel channel; } __packed; -struct zmk_sensor_data *zmk_sensor_get_data(uint32_t sensor_idx); +const struct zmk_sensor_data *zmk_sensor_get_data(uint32_t sensor_idx); void zmk_sensor_set_num_triggers(uint32_t sensor_idx, int num_triggers); diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 51b9d1f0c..aed772c05 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -411,7 +411,7 @@ static int press_hold_binding(struct active_hold_tap *hold_tap) { .position = hold_tap->position, .timestamp = hold_tap->timestamp, .layer = hold_tap->layer, - .type = PRESS, + .type = ZMK_BEHAVIOR_TRIG_TYPE_PRESS, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = hold_tap->source, #endif @@ -428,7 +428,7 @@ static int press_tap_binding(struct active_hold_tap *hold_tap) { .position = hold_tap->position, .timestamp = hold_tap->timestamp, .layer = hold_tap->layer, - .type = PRESS, + .type = ZMK_BEHAVIOR_TRIG_TYPE_RELEASE, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = hold_tap->source, #endif @@ -446,7 +446,7 @@ static int release_hold_binding(struct active_hold_tap *hold_tap) { .position = hold_tap->position, .timestamp = hold_tap->timestamp, .layer = hold_tap->layer, - .type = RELEASE, + .type = ZMK_BEHAVIOR_TRIG_TYPE_RELEASE, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = hold_tap->source, #endif @@ -463,7 +463,7 @@ static int release_tap_binding(struct active_hold_tap *hold_tap) { .position = hold_tap->position, .timestamp = hold_tap->timestamp, .layer = hold_tap->layer, - .type = RELEASE, + .type = ZMK_BEHAVIOR_TRIG_TYPE_RELEASE, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = hold_tap->source, #endif diff --git a/app/src/behaviors/behavior_sensor_rotate_common.c b/app/src/behaviors/behavior_sensor_rotate_common.c index 5a9411699..f5fd6c4e7 100644 --- a/app/src/behaviors/behavior_sensor_rotate_common.c +++ b/app/src/behaviors/behavior_sensor_rotate_common.c @@ -19,7 +19,7 @@ int zmk_behavior_sensor_rotate_common_process(struct zmk_behavior_binding *bindi const int sensor_index = ZMK_SENSOR_POSITION_FROM_VIRTUAL_KEY_POSITION(event.position); - struct zmk_sensor_data *data = zmk_sensor_get_data(sensor_index); + const struct zmk_sensor_data *data = zmk_sensor_get_data(sensor_index); int triggers = data->num_triggers; struct zmk_behavior_binding triggered_binding; diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index c526ae4cd..4fc1c4a96 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -114,7 +114,7 @@ static inline int press_sticky_key_behavior(struct active_sticky_key *sticky_key .position = sticky_key->position, .layer = sticky_key->layer, .timestamp = timestamp, - .type = PRESS, + .type = ZMK_BEHAVIOR_TRIG_TYPE_PRESS, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = sticky_key->source, #endif @@ -133,7 +133,7 @@ static inline int release_sticky_key_behavior(struct active_sticky_key *sticky_k .position = sticky_key->position, .layer = sticky_key->layer, .timestamp = timestamp, - .type = RELEASE, + .type = ZMK_BEHAVIOR_TRIG_TYPE_RELEASE, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = sticky_key->source, #endif diff --git a/app/src/behaviors/behavior_tap_dance.c b/app/src/behaviors/behavior_tap_dance.c index 30be60b08..0385d940e 100644 --- a/app/src/behaviors/behavior_tap_dance.c +++ b/app/src/behaviors/behavior_tap_dance.c @@ -119,7 +119,7 @@ static inline int press_tap_dance_behavior(struct active_tap_dance *tap_dance, i .position = tap_dance->position, .timestamp = timestamp, .layer = tap_dance->layer, - .type = PRESS, + .type = ZMK_BEHAVIOR_TRIG_TYPE_PRESS, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = tap_dance->source, #endif @@ -135,7 +135,7 @@ static inline int release_tap_dance_behavior(struct active_tap_dance *tap_dance, .position = tap_dance->position, .timestamp = timestamp, .layer = tap_dance->layer, - .type = RELEASE, + .type = ZMK_BEHAVIOR_TRIG_TYPE_RELEASE, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = tap_dance->source, #endif diff --git a/app/src/combo.c b/app/src/combo.c index a48ad8fa8..0d4ae7bdb 100644 --- a/app/src/combo.c +++ b/app/src/combo.c @@ -285,7 +285,7 @@ static inline int press_combo_behavior(int combo_idx, const struct combo_cfg *co .layer = 0, // Combos don't have layers, so their layer is set to be the base layer. .position = ZMK_VIRTUAL_KEY_POSITION_COMBO(combo_idx), .timestamp = timestamp, - .type = PRESS, + .type = ZMK_BEHAVIOR_TRIG_TYPE_PRESS, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL, #endif @@ -303,7 +303,7 @@ static inline int release_combo_behavior(int combo_idx, const struct combo_cfg * .layer = 0, // Combos don't have layers, so their layer is set to be the base layer. .position = ZMK_VIRTUAL_KEY_POSITION_COMBO(combo_idx), .timestamp = timestamp, - .type = RELEASE, + .type = ZMK_BEHAVIOR_TRIG_TYPE_RELEASE, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL, #endif diff --git a/app/src/pointing/input_processor_behaviors.c b/app/src/pointing/input_processor_behaviors.c index 3751fea5a..db9a84630 100644 --- a/app/src/pointing/input_processor_behaviors.c +++ b/app/src/pointing/input_processor_behaviors.c @@ -45,7 +45,8 @@ static int ip_behaviors_handle_event(const struct device *dev, struct input_even .position = ZMK_VIRTUAL_KEY_POSITION_BEHAVIOR_INPUT_PROCESSOR( state->input_device_index, cfg->index), .timestamp = k_uptime_get(), - .type = event->value ? PRESS : RELEASE, + .type = + event->value ? ZMK_BEHAVIOR_TRIG_TYPE_PRESS : ZMK_BEHAVIOR_TRIG_TYPE_RELEASE, #if IS_ENABLED(CONFIG_ZMK_SPLIT) .source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL, #endif diff --git a/app/src/sensors.c b/app/src/sensors.c index 35da9b9d0..84ffc8d00 100644 --- a/app/src/sensors.c +++ b/app/src/sensors.c @@ -58,7 +58,7 @@ static struct zmk_sensor_config configs[] = { static struct sensors_item_cfg sensors[] = {LISTIFY(ZMK_KEYMAP_SENSORS_LEN, SENSOR_ITEM, (, ), 0)}; struct zmk_sensor_data sensor_data[ZMK_KEYMAP_SENSORS_LEN] = {}; -struct zmk_sensor_data *zmk_sensor_get_data(uint32_t sensor_idx) { +const struct zmk_sensor_data *zmk_sensor_get_data(uint32_t sensor_idx) { if (sensor_idx >= ZMK_KEYMAP_SENSORS_LEN) { return NULL; } @@ -151,7 +151,7 @@ int sensor_listener(const zmk_event_t *eh) { } uint32_t sensor_index = sensor_ev->sensor_index; const struct sensor_value value = sensor_ev->channel_data[0].value; - struct zmk_sensor_data *data = zmk_sensor_get_data(sensor_index); + const struct zmk_sensor_data *data = zmk_sensor_get_data(sensor_index); const struct zmk_sensor_config *sensor_config = zmk_sensors_get_config_at_index(sensor_index); data->remainder.val1 += value.val1; data->remainder.val2 += value.val2; @@ -176,7 +176,8 @@ int sensor_listener(const zmk_event_t *eh) { #if IS_ENABLED(CONFIG_ZMK_SPLIT) ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL, #endif - position, SENSOR, sensor_ev->timestamp); + position, ZMK_BEHAVIOR_TRIG_TYPE_SENSOR, + sensor_ev->timestamp); if (ret < 0) { LOG_DBG("Behavior returned error: %d", ret); } @@ -214,5 +215,5 @@ SYS_INIT(zmk_sensors_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); #else /* ZMK_KEYMAP_HAS_SENSORS */ struct zmk_sensor_data sensor_data[0] = {}; -struct zmk_sensor_data *zmk_sensor_get_data(uint32_t sensor_idx) { return NULL; }; +const struct zmk_sensor_data *zmk_sensor_get_data(uint32_t sensor_idx) { return NULL; }; #endif /* ZMK_KEYMAP_HAS_SENSORS */ diff --git a/app/src/split/central.c b/app/src/split/central.c index 61f8f5405..2ce174d60 100644 --- a/app/src/split/central.c +++ b/app/src/split/central.c @@ -94,16 +94,18 @@ int zmk_split_central_invoke_behavior(uint8_t source, struct zmk_behavior_bindin .param1 = binding->param1, .param2 = binding->param2, .position = event->position, +#if IS_ENABLED(CONFIG_ZMK_SPLIT) .event_source = event->source, - .state = (event->type == PRESS) ? 1 : 0, +#endif + .state = (event->type == ZMK_BEHAVIOR_TRIG_TYPE_PRESS) ? 1 : 0, }, }, }; switch (event->type) { - case PRESS: + case ZMK_BEHAVIOR_TRIG_TYPE_PRESS: command.data.invoke_behavior.state = 1; break; - case RELEASE: + case ZMK_BEHAVIOR_TRIG_TYPE_RELEASE: command.data.invoke_behavior.state = 0; break; default: