summaryrefslogtreecommitdiff
path: root/app/src/events.c
blob: 376f370a694366ac53d9cca17b9cd6663c98ee09 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

#include <zephyr.h>
#include <drivers/behavior.h>
#include <zmk/behavior.h>
#include <zmk/events.h>
#include <sys/util.h>

#define DT_DRV_COMPAT zmk_behavior_global
#define GLOBAL_BEHAVIOR_LEN DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)

#define LABEL_ENTRY(i) DT_INST_LABEL(i),
static const char *global_behaviors[] = {
    DT_INST_FOREACH_STATUS_OKAY(LABEL_ENTRY)
};

int zmk_events_position_pressed(u32_t position)
{
    for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) {
        const char* label = global_behaviors[i];
        struct device *dev = device_get_binding(label);
        behavior_position_pressed(dev, position);
    }
    return 0;
};

int zmk_events_position_released(u32_t position)
{
    for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) {
        const char* label = global_behaviors[i];
        struct device *dev = device_get_binding(label);
        behavior_position_released(dev, position);
    }
    return 0;
};

int zmk_events_keycode_pressed(u32_t keycode)
{
    for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) {
        const char* label = global_behaviors[i];
        struct device *dev = device_get_binding(label);
        behavior_keycode_pressed(dev, keycode);
    }
    return 0;
};

int zmk_events_keycode_released(u32_t keycode)
{
    for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) {
        const char* label = global_behaviors[i];
        struct device *dev = device_get_binding(label);
        behavior_keycode_released(dev, keycode);
    }
    return 0;
};

int zmk_events_modifiers_pressed(zmk_mod_flags modifiers)
{
    for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) {
        const char* label = global_behaviors[i];
        struct device *dev = device_get_binding(label);
        behavior_modifiers_pressed(dev, modifiers);
    }
    return 0;
};

int zmk_events_modifiers_released(zmk_mod_flags modifiers)
{
    for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) {
        const char* label = global_behaviors[i];
        struct device *dev = device_get_binding(label);
        behavior_modifiers_released(dev, modifiers);
    }
    return 0;
};

int zmk_events_consumer_key_pressed(u32_t usage)
{
    return 0;
};
int zmk_events_consumer_key_released(u32_t usage)
{
    return 0;
};