Merge aba769f1ba
into a5c57fa224
This commit is contained in:
commit
d8aa55cacf
3 changed files with 25 additions and 11 deletions
|
@ -5,4 +5,6 @@
|
||||||
#include <zmk/behavior.h>
|
#include <zmk/behavior.h>
|
||||||
|
|
||||||
int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *binding,
|
int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event, bool state);
|
struct zmk_behavior_binding_event event, bool state);
|
||||||
|
|
||||||
|
int zmk_run_behavior(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event,uint8_t source,bool pressed);
|
|
@ -9,6 +9,8 @@
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
#include <drivers/behavior.h>
|
#include <drivers/behavior.h>
|
||||||
|
#include <zmk/split/bluetooth/central.h>
|
||||||
|
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
|
@ -35,9 +37,11 @@ static void behavior_queue_process_next(struct k_work *work) {
|
||||||
.timestamp = k_uptime_get()};
|
.timestamp = k_uptime_get()};
|
||||||
|
|
||||||
if (item.press) {
|
if (item.press) {
|
||||||
behavior_keymap_binding_pressed(&item.binding, event);
|
zmk_run_behavior(&item.binding, event,0,true);
|
||||||
|
// behavior_keymap_binding_pressed(&item.binding, event);
|
||||||
} else {
|
} else {
|
||||||
behavior_keymap_binding_released(&item.binding, event);
|
zmk_run_behavior(&item.binding, event,0,false);
|
||||||
|
// behavior_keymap_binding_released(&item.binding, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("Processing next queued behavior in %dms", item.wait);
|
LOG_DBG("Processing next queued behavior in %dms", item.wait);
|
||||||
|
|
|
@ -182,15 +182,23 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
|
||||||
};
|
};
|
||||||
|
|
||||||
LOG_DBG("layer: %d position: %d, binding name: %s", layer, position, binding.behavior_dev);
|
LOG_DBG("layer: %d position: %d, binding name: %s", layer, position, binding.behavior_dev);
|
||||||
|
return zmk_run_behavior(&binding,event,source,pressed);
|
||||||
|
}
|
||||||
|
|
||||||
behavior = device_get_binding(binding.behavior_dev);
|
int zmk_run_behavior(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event,uint8_t source,bool pressed){
|
||||||
|
|
||||||
|
LOG_DBG("layer: %d position: %d, binding name: %s", event.layer, event.position,
|
||||||
|
log_strdup(binding->behavior_dev));
|
||||||
|
|
||||||
|
|
||||||
|
const struct device *behavior = device_get_binding(binding->behavior_dev);
|
||||||
|
|
||||||
if (!behavior) {
|
if (!behavior) {
|
||||||
LOG_WRN("No behavior assigned to %d on layer %d", position, layer);
|
LOG_WRN("No behavior assigned to %d on layer %d", event.position, event.layer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = behavior_keymap_binding_convert_central_state_dependent_params(&binding, event);
|
int err = behavior_keymap_binding_convert_central_state_dependent_params(binding, event);
|
||||||
if (err) {
|
if (err) {
|
||||||
LOG_ERR("Failed to convert relative to absolute behavior binding (err %d)", err);
|
LOG_ERR("Failed to convert relative to absolute behavior binding (err %d)", err);
|
||||||
return err;
|
return err;
|
||||||
|
@ -205,24 +213,24 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
|
||||||
|
|
||||||
switch (locality) {
|
switch (locality) {
|
||||||
case BEHAVIOR_LOCALITY_CENTRAL:
|
case BEHAVIOR_LOCALITY_CENTRAL:
|
||||||
return invoke_locally(&binding, event, pressed);
|
return invoke_locally(binding, event, pressed);
|
||||||
case BEHAVIOR_LOCALITY_EVENT_SOURCE:
|
case BEHAVIOR_LOCALITY_EVENT_SOURCE:
|
||||||
#if ZMK_BLE_IS_CENTRAL
|
#if ZMK_BLE_IS_CENTRAL
|
||||||
if (source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) {
|
if (source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) {
|
||||||
return invoke_locally(&binding, event, pressed);
|
return invoke_locally(binding, event, pressed);
|
||||||
} else {
|
} else {
|
||||||
return zmk_split_bt_invoke_behavior(source, &binding, event, pressed);
|
return zmk_split_bt_invoke_behavior(source, &binding, event, pressed);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return invoke_locally(&binding, event, pressed);
|
return invoke_locally(binding, event, pressed);
|
||||||
#endif
|
#endif
|
||||||
case BEHAVIOR_LOCALITY_GLOBAL:
|
case BEHAVIOR_LOCALITY_GLOBAL:
|
||||||
#if ZMK_BLE_IS_CENTRAL
|
#if ZMK_BLE_IS_CENTRAL
|
||||||
for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) {
|
for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) {
|
||||||
zmk_split_bt_invoke_behavior(i, &binding, event, pressed);
|
zmk_split_bt_invoke_behavior(i, binding, event, pressed);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return invoke_locally(&binding, event, pressed);
|
return invoke_locally(binding, event, pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
|
Loading…
Add table
Reference in a new issue