Skip to content

Commit

Permalink
feat(split): Add data transfer event
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Nov 21, 2023
1 parent fd9475a commit 0457618
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ target_sources_ifdef(CONFIG_ZMK_BATTERY_REPORTING app PRIVATE src/events/battery
target_sources_ifdef(CONFIG_ZMK_BATTERY_REPORTING app PRIVATE src/battery.c)

target_sources_ifdef(CONFIG_ZMK_SPLIT app PRIVATE src/events/split_peripheral_status_changed.c)
target_sources_ifdef(CONFIG_ZMK_SPLIT app PRIVATE src/events/split_data_xfer_event.c)
add_subdirectory(src/split)

target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)
Expand Down
17 changes: 17 additions & 0 deletions app/include/zmk/events/split_data_xfer_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2023 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#pragma once

#include <zephyr/kernel.h>
#include <zmk/event_manager.h>
#include <zmk/split/bluetooth/service.h>

struct zmk_split_data_xfer_event {
struct zmk_split_data_xfer_data data_xfer;
};

ZMK_EVENT_DECLARE(zmk_split_data_xfer_event);
10 changes: 10 additions & 0 deletions app/src/events/split_data_xfer_event.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2023 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <zephyr/kernel.h>
#include <zmk/events/split_data_xfer_event.h>

ZMK_EVENT_IMPL(zmk_split_data_xfer_event);
4 changes: 4 additions & 0 deletions app/src/split/bluetooth/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/split/bluetooth/service.h>
#include <zmk/events/sensor_event.h>
#include <zmk/sensors.h>
#include <zmk/events/split_data_xfer_event.h>

#if ZMK_KEYMAP_HAS_SENSORS
static struct sensor_event last_sensor_event;
Expand Down Expand Up @@ -109,6 +110,9 @@ static ssize_t split_svc_data_xfer(struct bt_conn *conn, const struct bt_gatt_at
// If whole packet transferred correctly
if ((end_addr == sizeof(struct zmk_split_data_xfer_data))) {
// Raise new data transfer event with received data
struct zmk_split_data_xfer_event event;
memcpy(&event.data_xfer, payload, sizeof(struct zmk_split_data_xfer_data));
ZMK_EVENT_RAISE(new_zmk_split_data_xfer_event(event));
}

return len;
Expand Down

0 comments on commit 0457618

Please sign in to comment.