led color to right side
This commit is contained in:
parent
b735a051ce
commit
cb9917a498
3 changed files with 22 additions and 11 deletions
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <zmk/events/position_state_changed.h>
|
||||
#include <zmk/behavior.h>
|
||||
|
||||
#define ZMK_LAYER_CHILD_LEN_PLUS_ONE(node) 1 +
|
||||
#define ZMK_KEYMAP_LAYERS_LEN \
|
||||
|
@ -27,6 +28,10 @@ const char *zmk_keymap_layer_name(uint8_t layer);
|
|||
int zmk_keymap_position_state_changed(uint8_t source, uint32_t position, bool pressed,
|
||||
int64_t timestamp);
|
||||
|
||||
int zmk_trigger_behavior_callbacks(struct zmk_behavior_binding *binding,
|
||||
struct zmk_behavior_binding_event event, uint8_t source,
|
||||
bool pressed);
|
||||
|
||||
#define ZMK_KEYMAP_EXTRACT_BINDING(idx, drv_inst) \
|
||||
{ \
|
||||
.behavior_dev = DEVICE_DT_NAME(DT_PHANDLE_BY_IDX(drv_inst, bindings, idx)), \
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <zmk/behavior_queue.h>
|
||||
#include <zmk/keymap.h>
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
@ -35,9 +36,9 @@ static void behavior_queue_process_next(struct k_work *work) {
|
|||
.timestamp = k_uptime_get()};
|
||||
|
||||
if (item.press) {
|
||||
behavior_keymap_binding_pressed(&item.binding, event);
|
||||
zmk_trigger_behavior_callbacks(&item.binding, event, 0, true);
|
||||
} else {
|
||||
behavior_keymap_binding_released(&item.binding, event);
|
||||
zmk_trigger_behavior_callbacks(&item.binding, event, 0, false);
|
||||
}
|
||||
|
||||
LOG_DBG("Processing next queued behavior in %dms", item.wait);
|
||||
|
|
|
@ -177,7 +177,6 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
|
|||
// We want to make a copy of this, since it may be converted from
|
||||
// relative to absolute before being invoked
|
||||
struct zmk_behavior_binding binding = zmk_keymap[layer][position];
|
||||
const struct device *behavior;
|
||||
struct zmk_behavior_binding_event event = {
|
||||
.layer = layer,
|
||||
.position = position,
|
||||
|
@ -186,14 +185,20 @@ 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);
|
||||
|
||||
behavior = zmk_behavior_get_binding(binding.behavior_dev);
|
||||
return zmk_trigger_behavior_callbacks(&binding, event, source, pressed);
|
||||
}
|
||||
|
||||
int zmk_trigger_behavior_callbacks(struct zmk_behavior_binding *binding,
|
||||
struct zmk_behavior_binding_event event, uint8_t source,
|
||||
bool pressed) {
|
||||
const struct device *behavior = zmk_behavior_get_binding(binding->behavior_dev);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
LOG_ERR("Failed to convert relative to absolute behavior binding (err %d)", err);
|
||||
return err;
|
||||
|
@ -208,24 +213,24 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
|
|||
|
||||
switch (locality) {
|
||||
case BEHAVIOR_LOCALITY_CENTRAL:
|
||||
return invoke_locally(&binding, event, pressed);
|
||||
return invoke_locally(binding, event, pressed);
|
||||
case BEHAVIOR_LOCALITY_EVENT_SOURCE:
|
||||
#if ZMK_BLE_IS_CENTRAL
|
||||
if (source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) {
|
||||
return invoke_locally(&binding, event, pressed);
|
||||
return invoke_locally(binding, event, pressed);
|
||||
} else {
|
||||
return zmk_split_bt_invoke_behavior(source, &binding, event, pressed);
|
||||
}
|
||||
#else
|
||||
return invoke_locally(&binding, event, pressed);
|
||||
return invoke_locally(binding, event, pressed);
|
||||
#endif
|
||||
case BEHAVIOR_LOCALITY_GLOBAL:
|
||||
#if ZMK_BLE_IS_CENTRAL
|
||||
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
|
||||
return invoke_locally(&binding, event, pressed);
|
||||
return invoke_locally(binding, event, pressed);
|
||||
}
|
||||
|
||||
return -ENOTSUP;
|
||||
|
|
Loading…
Add table
Reference in a new issue