Skip to content

Commit

Permalink
fix(sensors): Only accept data once per behavior.
Browse files Browse the repository at this point in the history
* Don't accept data for the same behavior on multiple layers more than
  once, to avoid duplicate/extraneous triggers.
  • Loading branch information
petejohanson committed Jun 28, 2023
1 parent 4f45ae2 commit 585c7f6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/src/keymap.c
Expand Up @@ -257,7 +257,11 @@ int zmk_keymap_sensor_event(uint8_t sensor_index,
size_t channel_data_size, int64_t timestamp) {
bool opaque_response = false;

const struct device *accepted_devices[ZMK_KEYMAP_LAYERS_LEN] = {};
uint8_t accepted_devices_count = 0;

for (int layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer >= 0; layer--) {
int ret;
struct zmk_behavior_binding *binding = &zmk_sensor_keymap[layer][sensor_index];

LOG_DBG("layer: %d sensor_index: %d, binding name: %s", layer, sensor_index,
Expand All @@ -275,9 +279,21 @@ int zmk_keymap_sensor_event(uint8_t sensor_index,
.timestamp = timestamp,
};

int ret = behavior_sensor_keymap_binding_accept_data(
binding, event, zmk_sensors_get_config_at_index(sensor_index), channel_data_size,
channel_data);
bool already_accepted = false;
for (int j = 0; j < accepted_devices_count; j++) {
if (behavior == accepted_devices[j]) {
already_accepted = true;
break;
}
}

if (!already_accepted) {
ret = behavior_sensor_keymap_binding_accept_data(
binding, event, zmk_sensors_get_config_at_index(sensor_index), channel_data_size,
channel_data);

accepted_devices[accepted_devices_count++] = behavior;
}

if (ret < 0) {
LOG_WRN("behavior data accept for behavior %s returned an error (%d). Processing to "
Expand Down

0 comments on commit 585c7f6

Please sign in to comment.