fix(sensors): Clean ups based on code review.
This commit is contained in:
parent
3a91b32513
commit
753802cd79
7 changed files with 26 additions and 29 deletions
17
app/Kconfig
17
app/Kconfig
|
@ -194,18 +194,6 @@ rsource "src/split/Kconfig"
|
|||
#Basic Keyboard Setup
|
||||
endmenu
|
||||
|
||||
menu "Encoders"
|
||||
|
||||
config ZMK_ENCODERS_DEFAULT_TRIGGERS_PER_ROTATION
|
||||
int "Default behavior triggers per rotation"
|
||||
help
|
||||
Unless overridden for a specific behavior in the keymap/devicetree, this value
|
||||
determines how many times to trigger the bound behavior per full rotation.
|
||||
For tactile encoders with detents, this usually should match the number of
|
||||
detents per rotation of the encoder.
|
||||
default 30
|
||||
|
||||
endmenu
|
||||
menu "Display/LED Options"
|
||||
|
||||
rsource "src/display/Kconfig"
|
||||
|
@ -548,6 +536,11 @@ if ZMK_KEYMAP_SENSORS
|
|||
|
||||
config ZMK_KEYMAP_SENSORS_DEFAULT_TRIGGERS_PER_ROTATION
|
||||
int "Default triggers per rotation"
|
||||
help
|
||||
Unless overridden for a sensor in the board/shield/devicetree, this value
|
||||
determines how many times to trigger the bound behavior per full rotation.
|
||||
For tactile encoders with detents, this usually should match the number of
|
||||
detents per rotation of the encoder.
|
||||
default 20
|
||||
|
||||
endif # ZMK_KEYMAP_SENSORS
|
||||
|
|
|
@ -49,7 +49,7 @@ __subsystem struct behavior_driver_api {
|
|||
behavior_keymap_binding_callback_t binding_convert_central_state_dependent_params;
|
||||
behavior_keymap_binding_callback_t binding_pressed;
|
||||
behavior_keymap_binding_callback_t binding_released;
|
||||
behavior_sensor_keymap_binding_accept_data_callback_t sensor_binding_data;
|
||||
behavior_sensor_keymap_binding_accept_data_callback_t sensor_binding_accept_data;
|
||||
behavior_sensor_keymap_binding_process_callback_t sensor_binding_process;
|
||||
};
|
||||
/**
|
||||
|
@ -186,11 +186,12 @@ static inline int z_impl_behavior_sensor_keymap_binding_accept_data(
|
|||
|
||||
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;
|
||||
|
||||
if (api->sensor_binding_data == NULL) {
|
||||
if (api->sensor_binding_accept_data == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return api->sensor_binding_data(binding, event, sensor_config, channel_data_size, channel_data);
|
||||
return api->sensor_binding_accept_data(binding, event, sensor_config, channel_data_size,
|
||||
channel_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "behavior_sensor_rotate_common.h"
|
||||
|
||||
static const struct behavior_driver_api behavior_sensor_rotate_driver_api = {
|
||||
.sensor_binding_data = zmk_behavior_sensor_rotate_common_data,
|
||||
.sensor_binding_accept_data = zmk_behavior_sensor_rotate_common_accept_data,
|
||||
.sensor_binding_process = zmk_behavior_sensor_rotate_common_process};
|
||||
|
||||
static int behavior_sensor_rotate_init(const struct device *dev) { return 0; };
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
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_accept_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);
|
||||
struct behavior_sensor_rotate_data *data = dev->data;
|
||||
|
||||
|
|
|
@ -20,11 +20,10 @@ struct behavior_sensor_rotate_data {
|
|||
int triggers[ZMK_KEYMAP_SENSORS_LEN];
|
||||
};
|
||||
|
||||
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_accept_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,
|
||||
enum behavior_sensor_binding_process_mode mode);
|
|
@ -13,7 +13,7 @@
|
|||
#include "behavior_sensor_rotate_common.h"
|
||||
|
||||
static const struct behavior_driver_api behavior_sensor_rotate_var_driver_api = {
|
||||
.sensor_binding_data = zmk_behavior_sensor_rotate_common_data,
|
||||
.sensor_binding_accept_data = zmk_behavior_sensor_rotate_common_accept_data,
|
||||
.sensor_binding_process = zmk_behavior_sensor_rotate_common_process};
|
||||
|
||||
static int behavior_sensor_rotate_var_init(const struct device *dev) { return 0; };
|
||||
|
|
|
@ -19,10 +19,10 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
#if ZMK_KEYMAP_HAS_SENSORS
|
||||
|
||||
struct sensors_item_cfg {
|
||||
uint8_t sensor_index;
|
||||
const struct zmk_sensor_config *config;
|
||||
const struct device *dev;
|
||||
struct sensor_trigger trigger;
|
||||
uint8_t sensor_index;
|
||||
};
|
||||
|
||||
#define _SENSOR_ITEM(idx, node) \
|
||||
|
@ -43,7 +43,11 @@ struct sensors_item_cfg {
|
|||
CONFIG_ZMK_KEYMAP_SENSORS_DEFAULT_TRIGGERS_PER_ROTATION)) \
|
||||
}
|
||||
#define SENSOR_CHILD_DEFAULTS(idx, arg) \
|
||||
{ .triggers_per_rotation = DT_PROP_OR(ZMK_KEYMAP_SENSORS_NODE, triggers_per_rotation, 20) }
|
||||
{ \
|
||||
.triggers_per_rotation = \
|
||||
DT_PROP_OR(ZMK_KEYMAP_SENSORS_NODE, triggers_per_rotation, \
|
||||
CONFIG_ZMK_KEYMAP_SENSORS_DEFAULT_TRIGGERS_PER_ROTATION) \
|
||||
}
|
||||
|
||||
static struct zmk_sensor_config configs[] = {
|
||||
#if ZMK_KEYMAP_SENSORS_CHILD_COUNT > 0
|
||||
|
@ -85,6 +89,7 @@ static void trigger_sensor_data_for_position(uint32_t sensor_index) {
|
|||
|
||||
ZMK_EVENT_RAISE(new_zmk_sensor_event(
|
||||
(struct zmk_sensor_event){.sensor_index = item->sensor_index,
|
||||
.channel_data_size = 1,
|
||||
.channel_data = {(struct zmk_sensor_channel_data){
|
||||
.value = value, .channel = item->trigger.chan}},
|
||||
.timestamp = k_uptime_get()}));
|
||||
|
|
Loading…
Add table
Reference in a new issue