feature(split): add support for sensors from peripheral

This commit adds a new GATT characteristics on the peripheral side
and wires it up to read sensor values. The central side subscribes
to this new characteristics and replays sensor values on its side.

Co-authored-by: Peter Johanson <peter@peterjohanson.com>
This commit is contained in:
Stephen Wan
2021-03-15 12:26:18 -07:00
committed by Pete Johanson
parent c957348e61
commit 9d44229800
7 changed files with 196 additions and 28 deletions

View File

@@ -24,7 +24,9 @@ struct zmk_sensor_config {
uint16_t triggers_per_rotation;
};
// This struct is also used for data transfer for splits, so any changes to the size, layout, etc
// is a breaking change for the split GATT service protocol.
struct zmk_sensor_channel_data {
enum sensor_channel channel;
struct sensor_value value;
};
enum sensor_channel channel;
} __packed;

View File

@@ -6,8 +6,18 @@
#pragma once
#include <zmk/events/sensor_event.h>
#include <zmk/sensors.h>
#define ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN 9
struct sensor_event {
uint8_t sensor_index;
uint8_t channel_data_size;
struct zmk_sensor_channel_data channel_data[ZMK_SENSOR_EVENT_MAX_CHANNELS];
} __packed;
struct zmk_split_run_behavior_data {
uint8_t position;
uint8_t state;
@@ -21,4 +31,7 @@ struct zmk_split_run_behavior_payload {
} __packed;
int zmk_split_bt_position_pressed(uint8_t position);
int zmk_split_bt_position_released(uint8_t position);
int zmk_split_bt_position_released(uint8_t position);
int zmk_split_bt_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size);

View File

@@ -16,3 +16,4 @@
#define ZMK_SPLIT_BT_SERVICE_UUID ZMK_BT_SPLIT_UUID(0x00000000)
#define ZMK_SPLIT_BT_CHAR_POSITION_STATE_UUID ZMK_BT_SPLIT_UUID(0x00000001)
#define ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID ZMK_BT_SPLIT_UUID(0x00000002)
#define ZMK_SPLIT_BT_CHAR_SENSOR_STATE_UUID ZMK_BT_SPLIT_UUID(0x00000003)