aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/behaviors
diff options
context:
space:
mode:
authorPeter Johanson <[email protected]>2023-05-04 00:04:20 +0000
committerPete Johanson <[email protected]>2023-06-18 20:45:06 -0600
commit8b29f6d34556d98df60f529e84ee66e49e6bf0c0 (patch)
tree73975efef99dd3e9c3a392c740cfba40a6707a46 /app/src/behaviors
parentd781ec795b9d9e053ce71c30450ba2b979eab43b (diff)
downloadzmk-8b29f6d34556d98df60f529e84ee66e49e6bf0c0.tar.gz
zmk-8b29f6d34556d98df60f529e84ee66e49e6bf0c0.zip
refactor(sensors): Split data handling from triggers.
* All sensor behaviors should see sensor data, then selectively only have some trigger their behaviors.
Diffstat (limited to 'app/src/behaviors')
-rw-r--r--app/src/behaviors/behavior_sensor_rotate.c3
-rw-r--r--app/src/behaviors/behavior_sensor_rotate_common.c31
-rw-r--r--app/src/behaviors/behavior_sensor_rotate_common.h13
-rw-r--r--app/src/behaviors/behavior_sensor_rotate_var.c3
4 files changed, 38 insertions, 12 deletions
diff --git a/app/src/behaviors/behavior_sensor_rotate.c b/app/src/behaviors/behavior_sensor_rotate.c
index 86846d5be0..3b5bef6218 100644
--- a/app/src/behaviors/behavior_sensor_rotate.c
+++ b/app/src/behaviors/behavior_sensor_rotate.c
@@ -13,7 +13,8 @@
#include "behavior_sensor_rotate_common.h"
static const struct behavior_driver_api behavior_sensor_rotate_driver_api = {
- .sensor_binding_triggered = zmk_behavior_sensor_rotate_common_trigger};
+ .sensor_binding_data = zmk_behavior_sensor_rotate_common_data,
+ .sensor_binding_process = zmk_behavior_sensor_rotate_common_process};
static int behavior_sensor_rotate_init(const struct device *dev) { return 0; };
diff --git a/app/src/behaviors/behavior_sensor_rotate_common.c b/app/src/behaviors/behavior_sensor_rotate_common.c
index 99e4e019ba..0a2b619df8 100644
--- a/app/src/behaviors/behavior_sensor_rotate_common.c
+++ b/app/src/behaviors/behavior_sensor_rotate_common.c
@@ -11,13 +11,12 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
-int zmk_behavior_sensor_rotate_common_trigger(struct zmk_behavior_binding *binding,
- struct zmk_behavior_binding_event event,
- const struct zmk_sensor_config *sensor_config,
- size_t channel_data_size,
- const struct zmk_sensor_channel_data *channel_data) {
+int zmk_behavior_sensor_rotate_common_data(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event,
+ const struct zmk_sensor_config *sensor_config,
+ size_t channel_data_size,
+ const struct zmk_sensor_channel_data *channel_data) {
const struct device *dev = device_get_binding(binding->behavior_dev);
- const struct behavior_sensor_rotate_config *cfg = dev->config;
struct behavior_sensor_rotate_data *data = dev->data;
const struct sensor_value value = channel_data[0].value;
@@ -52,6 +51,26 @@ int zmk_behavior_sensor_rotate_common_trigger(struct zmk_behavior_binding *bindi
value.val1, value.val2, data->remainder[sensor_position].val1,
data->remainder[sensor_position].val2, triggers, binding->param1, binding->param2);
+ data->triggers[sensor_position] = triggers;
+ return 0;
+}
+
+int zmk_behavior_sensor_rotate_common_process(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event,
+ enum behavior_sensor_binding_process_mode mode) {
+ const struct device *dev = device_get_binding(binding->behavior_dev);
+ const struct behavior_sensor_rotate_config *cfg = dev->config;
+ struct behavior_sensor_rotate_data *data = dev->data;
+
+ const int sensor_position = ZMK_SENSOR_POSITION_FROM_VIRTUAL_KEY_POSITION(event.position);
+
+ if (mode != BEHAVIOR_SENSOR_BINDING_PROCESS_MODE_TRIGGER) {
+ data->triggers[sensor_position] = 0;
+ return 0;
+ }
+
+ int triggers = data->triggers[sensor_position];
+
struct zmk_behavior_binding triggered_binding;
if (triggers > 0) {
triggered_binding = cfg->cw_binding;
diff --git a/app/src/behaviors/behavior_sensor_rotate_common.h b/app/src/behaviors/behavior_sensor_rotate_common.h
index eab443a398..d9d4d855df 100644
--- a/app/src/behaviors/behavior_sensor_rotate_common.h
+++ b/app/src/behaviors/behavior_sensor_rotate_common.h
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
*/
+#include <drivers/behavior.h>
#include <zmk/behavior.h>
#include <zmk/sensors.h>
@@ -16,10 +17,14 @@ struct behavior_sensor_rotate_config {
struct behavior_sensor_rotate_data {
struct sensor_value remainder[ZMK_KEYMAP_SENSORS_LEN];
+ int triggers[ZMK_KEYMAP_SENSORS_LEN];
};
-int zmk_behavior_sensor_rotate_common_trigger(struct zmk_behavior_binding *binding,
+int zmk_behavior_sensor_rotate_common_data(struct zmk_behavior_binding *binding,
+ struct zmk_behavior_binding_event event,
+ const struct zmk_sensor_config *sensor_config,
+ size_t channel_data_size,
+ const struct zmk_sensor_channel_data *channel_data);
+int zmk_behavior_sensor_rotate_common_process(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event,
- const struct zmk_sensor_config *sensor_config,
- size_t channel_data_size,
- const struct zmk_sensor_channel_data *channel_data); \ No newline at end of file
+ enum behavior_sensor_binding_process_mode mode); \ No newline at end of file
diff --git a/app/src/behaviors/behavior_sensor_rotate_var.c b/app/src/behaviors/behavior_sensor_rotate_var.c
index 95bb99610b..3c2373b004 100644
--- a/app/src/behaviors/behavior_sensor_rotate_var.c
+++ b/app/src/behaviors/behavior_sensor_rotate_var.c
@@ -13,7 +13,8 @@
#include "behavior_sensor_rotate_common.h"
static const struct behavior_driver_api behavior_sensor_rotate_var_driver_api = {
- .sensor_binding_triggered = zmk_behavior_sensor_rotate_common_trigger};
+ .sensor_binding_data = zmk_behavior_sensor_rotate_common_data,
+ .sensor_binding_process = zmk_behavior_sensor_rotate_common_process};
static int behavior_sensor_rotate_var_init(const struct device *dev) { return 0; };