Skip to content

Commit

Permalink
feat(split): trigger split_peripheral_status_changed event on central
Browse files Browse the repository at this point in the history
Trigger the peripheral_status_changed event on the central
  • Loading branch information
ReFil committed Dec 17, 2024
1 parent d0016b3 commit 959f8c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/include/zmk/events/split_peripheral_status_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

struct zmk_split_peripheral_status_changed {
bool connected;
uint8_t slot;
};

ZMK_EVENT_DECLARE(zmk_split_peripheral_status_changed);
6 changes: 6 additions & 0 deletions app/src/split/bluetooth/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/events/position_state_changed.h>
#include <zmk/events/sensor_event.h>
#include <zmk/events/battery_state_changed.h>
#include <zmk/events/split_peripheral_status_changed.h>
#include <zmk/pointing/input_split.h>
#include <zmk/hid_indicators_types.h>
#include <zmk/physical_layouts.h>
Expand Down Expand Up @@ -965,6 +966,8 @@ static void split_central_connected(struct bt_conn *conn, uint8_t conn_err) {

confirm_peripheral_slot_conn(conn);
split_central_process_connection(conn);
raise_zmk_split_peripheral_status_changed((struct zmk_split_peripheral_status_changed){
.connected = true, .slot = peripheral_slot_index_for_conn(conn)});
}

static void split_central_disconnected(struct bt_conn *conn, uint8_t reason) {
Expand All @@ -982,6 +985,9 @@ static void split_central_disconnected(struct bt_conn *conn, uint8_t reason) {
k_work_submit(&peripheral_batt_lvl_work);
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING)

raise_zmk_split_peripheral_status_changed((struct zmk_split_peripheral_status_changed){
.connected = false, .slot = peripheral_slot_index_for_conn(conn)});

#if IS_ENABLED(CONFIG_ZMK_INPUT_SPLIT)
release_peripheral_input_subs(conn);
#endif
Expand Down
4 changes: 2 additions & 2 deletions app/src/split/bluetooth/peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void connected(struct bt_conn *conn, uint8_t err) {
is_connected = (err == 0);

raise_zmk_split_peripheral_status_changed(
(struct zmk_split_peripheral_status_changed){.connected = is_connected});
(struct zmk_split_peripheral_status_changed){.connected = is_connected, .slot = 0});

if (err == BT_HCI_ERR_ADV_TIMEOUT) {
low_duty_advertising = true;
Expand All @@ -102,7 +102,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) {
is_connected = false;

raise_zmk_split_peripheral_status_changed(
(struct zmk_split_peripheral_status_changed){.connected = is_connected});
(struct zmk_split_peripheral_status_changed){.connected = is_connected, .slot = 0});

low_duty_advertising = false;
k_work_submit(&advertising_work);
Expand Down

0 comments on commit 959f8c7

Please sign in to comment.