mirror of https://github.com/zmkfirmware/zmk.git
fixup! feat: Refactor behaviors, sensor to raise behavior_binding_event
This commit is contained in:
parent
e4b44ace6d
commit
c0fdb586ef
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"*.overlay": "dts",
|
||||
"*.keymap": "dts"
|
||||
"*.keymap": "dts",
|
||||
"regex": "c"
|
||||
},
|
||||
"python.analysis.include": ["app/scripts", "zephyr/scripts"],
|
||||
"[c]": {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue