forked from kofal.net/zmk
Revert "feat: Split physical layout selection sync."
This reverts commit 03b5b38bc4.
This commit is contained in:
@@ -30,7 +30,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
#include <zmk/events/sensor_event.h>
|
||||
#include <zmk/events/battery_state_changed.h>
|
||||
#include <zmk/hid_indicators_types.h>
|
||||
#include <zmk/physical_layouts.h>
|
||||
|
||||
static int start_scanning(void);
|
||||
|
||||
@@ -57,7 +56,6 @@ struct peripheral_slot {
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
||||
uint16_t update_hid_indicators;
|
||||
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
||||
uint16_t selected_physical_layout_handle;
|
||||
uint8_t position_state[POSITION_STATE_DATA_LEN];
|
||||
uint8_t changed_positions[POSITION_STATE_DATA_LEN];
|
||||
};
|
||||
@@ -143,7 +141,6 @@ int release_peripheral_slot(int index) {
|
||||
// Clean up previously discovered handles;
|
||||
slot->subscribe_params.value_handle = 0;
|
||||
slot->run_behavior_handle = 0;
|
||||
slot->selected_physical_layout_handle = 0;
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
||||
slot->update_hid_indicators = 0;
|
||||
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
||||
@@ -395,28 +392,6 @@ static int split_central_subscribe(struct bt_conn *conn, struct bt_gatt_subscrib
|
||||
return err;
|
||||
}
|
||||
|
||||
static int update_peripheral_selected_layout(struct peripheral_slot *slot, uint8_t layout_idx) {
|
||||
if (slot->state != PERIPHERAL_SLOT_STATE_CONNECTED) {
|
||||
return -ENOTCONN;
|
||||
}
|
||||
|
||||
if (slot->selected_physical_layout_handle == 0) {
|
||||
// It appears that sometimes the peripheral is considered connected
|
||||
// before the GATT characteristics have been discovered. If this is
|
||||
// the case, the selected_physical_layout_handle will not yet be set.
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
int err = bt_gatt_write_without_response(slot->conn, slot->selected_physical_layout_handle,
|
||||
&layout_idx, sizeof(layout_idx), true);
|
||||
|
||||
if (err < 0) {
|
||||
LOG_ERR("Failed to write physical layout index to peripheral (err %d)", err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr,
|
||||
struct bt_gatt_discover_params *params) {
|
||||
@@ -467,11 +442,6 @@ static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn,
|
||||
slot->discover_params.uuid = NULL;
|
||||
slot->discover_params.start_handle = attr->handle + 2;
|
||||
slot->run_behavior_handle = bt_gatt_attr_value_handle(attr);
|
||||
} else if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid,
|
||||
BT_UUID_DECLARE_128(ZMK_SPLIT_BT_SELECT_PHYS_LAYOUT_UUID))) {
|
||||
LOG_DBG("Found select physical layout handle");
|
||||
slot->selected_physical_layout_handle = bt_gatt_attr_value_handle(attr);
|
||||
update_peripheral_selected_layout(slot, zmk_physical_layouts_get_selected());
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
||||
} else if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid,
|
||||
BT_UUID_DECLARE_128(ZMK_SPLIT_BT_UPDATE_HID_INDICATORS_UUID))) {
|
||||
@@ -497,8 +467,7 @@ static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn,
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING) */
|
||||
}
|
||||
|
||||
bool subscribed = slot->run_behavior_handle && slot->subscribe_params.value_handle &&
|
||||
slot->selected_physical_layout_handle;
|
||||
bool subscribed = slot->run_behavior_handle && slot->subscribe_params.value_handle;
|
||||
|
||||
#if ZMK_KEYMAP_HAS_SENSORS
|
||||
subscribed = subscribed && slot->sensor_subscribe_params.value_handle;
|
||||
@@ -928,27 +897,3 @@ static int zmk_split_bt_central_init(void) {
|
||||
}
|
||||
|
||||
SYS_INIT(zmk_split_bt_central_init, APPLICATION, CONFIG_ZMK_BLE_INIT_PRIORITY);
|
||||
|
||||
static void update_peripherals_selected_physical_layout(struct k_work *_work) {
|
||||
uint8_t layout_idx = zmk_physical_layouts_get_selected();
|
||||
for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) {
|
||||
if (peripherals[i].state != PERIPHERAL_SLOT_STATE_CONNECTED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
update_peripheral_selected_layout(&peripherals[i], layout_idx);
|
||||
}
|
||||
}
|
||||
|
||||
K_WORK_DEFINE(update_peripherals_selected_layouts_work,
|
||||
update_peripherals_selected_physical_layout);
|
||||
|
||||
static int zmk_split_bt_central_listener_cb(const zmk_event_t *eh) {
|
||||
if (as_zmk_physical_layout_selection_changed(eh)) {
|
||||
k_work_submit(&update_peripherals_selected_layouts_work);
|
||||
}
|
||||
return ZMK_EV_EVENT_BUBBLE;
|
||||
}
|
||||
|
||||
ZMK_LISTENER(zmk_split_bt_central, zmk_split_bt_central_listener_cb);
|
||||
ZMK_SUBSCRIPTION(zmk_split_bt_central, zmk_physical_layout_selection_changed);
|
||||
Reference in New Issue
Block a user