summaryrefslogtreecommitdiff
path: root/app/src/split_listener.c
blob: 153ed99d9b1f74b0a4cec1d54688f342c54d58b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * Copyright (c) 2020 The ZMK Contributors
 *
 * SPDX-License-Identifier: MIT
 */

#define DT_DRV_COMPAT zmk_split_listener

#include <device.h>
#include <power/reboot.h>
#include <logging/log.h>

#include <zmk/split/bluetooth/service.h>

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#include <zmk/event_manager.h>
#include <zmk/events/position_state_changed.h>
#include <zmk/hid.h>
#include <zmk/endpoints.h>

int split_listener(const struct zmk_event_header *eh) {
    LOG_DBG("");
    if (is_position_state_changed(eh)) {
        const struct position_state_changed *ev = cast_position_state_changed(eh);
        if (ev->state) {
            return zmk_split_bt_position_pressed(ev->position);
        } else {
            return zmk_split_bt_position_released(ev->position);
        }
    }
    return 0;
}

ZMK_LISTENER(split_listener, split_listener);
ZMK_SUBSCRIPTION(split_listener, position_state_changed);