global if behavior name starts with 'layer'
This commit is contained in:
parent
69b50b8ce7
commit
9ea017eef4
3 changed files with 10 additions and 24 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,bool pressed);
|
|
@ -37,13 +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) {
|
||||||
if(strncmp(item.binding.behavior_dev,"RGB_UG",6)==0){
|
zmk_run_behavior(&item.binding, event,true)
|
||||||
LOG_DBG("RGB_COLOR_HSB_CMD sending binding to peripheral");
|
// behavior_keymap_binding_pressed(&item.binding, event);
|
||||||
zmk_split_bt_invoke_behavior(0, &item.binding, event, true);
|
|
||||||
}
|
|
||||||
behavior_keymap_binding_pressed(&item.binding, event);
|
|
||||||
} else {
|
} else {
|
||||||
behavior_keymap_binding_released(&item.binding, event);
|
zmk_run_behavior(&item.binding, event,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,7 +182,10 @@ 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,
|
LOG_DBG("layer: %d position: %d, binding name: %s", layer, position,
|
||||||
log_strdup(binding.behavior_dev));
|
log_strdup(binding.behavior_dev));
|
||||||
|
|
||||||
|
return zmk_run_behavior(&binding,event,pressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
int zmk_run_behavior(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event,bool pressed){
|
||||||
|
|
||||||
behavior = device_get_binding(binding.behavior_dev);
|
behavior = device_get_binding(binding.behavior_dev);
|
||||||
|
|
||||||
|
@ -198,29 +201,16 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
|
||||||
}
|
}
|
||||||
|
|
||||||
enum behavior_locality locality = BEHAVIOR_LOCALITY_CENTRAL;
|
enum behavior_locality locality = BEHAVIOR_LOCALITY_CENTRAL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
err = behavior_get_locality(behavior, &locality);
|
err = behavior_get_locality(behavior, &locality);
|
||||||
if (err) {
|
if (err) {
|
||||||
LOG_ERR("Failed to get behavior locality %d", err);
|
LOG_ERR("Failed to get behavior locality %d", err);
|
||||||
return err;
|
return err;
|
||||||
}else{
|
|
||||||
LOG_DBG("got locality: BEHAVIOR_LOCALITY_CENTRAL from behavior");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(binding.behavior_dev, "layer", 5) == 0) {
|
|
||||||
locality = BEHAVIOR_LOCALITY_GLOBAL;
|
|
||||||
LOG_DBG("force locality: BEHAVIOR_LOCALITY_GLOBAL because of a 'layer' behavior");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
switch (locality) {
|
switch (locality) {
|
||||||
case BEHAVIOR_LOCALITY_CENTRAL:
|
case BEHAVIOR_LOCALITY_CENTRAL:
|
||||||
LOG_DBG("locality is: 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:
|
||||||
LOG_DBG("locality is: 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);
|
||||||
|
@ -231,14 +221,10 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
|
||||||
return invoke_locally(&binding, event, pressed);
|
return invoke_locally(&binding, event, pressed);
|
||||||
#endif
|
#endif
|
||||||
case BEHAVIOR_LOCALITY_GLOBAL:
|
case BEHAVIOR_LOCALITY_GLOBAL:
|
||||||
LOG_DBG("locality is: BEHAVIOR_LOCALITY_GLOBAL - Invoking %s", log_strdup(binding.behavior_dev));
|
|
||||||
#if ZMK_BLE_IS_CENTRAL
|
#if ZMK_BLE_IS_CENTRAL
|
||||||
LOG_DBG("BEHAVIOR_LOCALITY_GLOBAL is central, calling binding on the peripheral...");
|
|
||||||
for (int i = 0; i < ZMK_BLE_SPLIT_PERIPHERAL_COUNT; i++) {
|
for (int i = 0; i < ZMK_BLE_SPLIT_PERIPHERAL_COUNT; i++) {
|
||||||
zmk_split_bt_invoke_behavior(i, &binding, event, pressed);
|
zmk_split_bt_invoke_behavior(i, &binding, event, pressed);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
LOG_DBG("BEHAVIOR_LOCALITY_GLOBAL is peripheral");
|
|
||||||
#endif
|
#endif
|
||||||
return invoke_locally(&binding, event, pressed);
|
return invoke_locally(&binding, event, pressed);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue