forked from kofal.net/zmk
Initial event manager work, and two first events.
* Add initial event manager implementation, roughly mimicking Nordic's API. * Add `position_state_changed` and `keycode_state_changed` events. * Hook up HID and keymap to new events instead of using behaviour global event crazy.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#include <drivers/behavior.h>
|
||||
#include <logging/log.h>
|
||||
|
||||
#include <zmk/event-manager.h>
|
||||
#include <zmk/events/keycode-state-changed.h>
|
||||
#include <zmk/events.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
@@ -19,6 +21,22 @@ struct behavior_mod_tap_data {
|
||||
u16_t pending_press_positions;
|
||||
};
|
||||
|
||||
int behavior_mod_tap_listener(const struct zmk_event_header *eh)
|
||||
{
|
||||
if (is_keycode_state_changed(eh)) {
|
||||
struct device *dev = device_get_binding(DT_INST_LABEL(0));
|
||||
const struct keycode_state_changed *ev = cast_keycode_state_changed(eh);
|
||||
if (ev->state) {
|
||||
struct behavior_mod_tap_data *data = dev->driver_data;
|
||||
data->pending_press_positions = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ZMK_LISTENER(behavior_mod_tap, behavior_mod_tap_listener);
|
||||
ZMK_SUBSCRIPTION(behavior_mod_tap, keycode_state_changed);
|
||||
|
||||
static int behavior_mod_tap_init(struct device *dev)
|
||||
{
|
||||
return 0;
|
||||
@@ -40,7 +58,7 @@ static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t
|
||||
struct behavior_mod_tap_data *data = dev->driver_data;
|
||||
LOG_DBG("mods: %d, keycode: %d", mods, keycode);
|
||||
|
||||
zmk_events_modifiers_released(mods);
|
||||
zmk_events_modifiers_released(mods);
|
||||
if (data->pending_press_positions & BIT(position)) {
|
||||
zmk_events_keycode_pressed(USAGE_KEYPAD, keycode);
|
||||
k_msleep(10);
|
||||
@@ -50,30 +68,9 @@ zmk_events_modifiers_released(mods);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_keycode_pressed(struct device *dev, u8_t usage_page, u32_t keycode)
|
||||
{
|
||||
struct behavior_mod_tap_data *data = dev->driver_data;
|
||||
data->pending_press_positions = 0;
|
||||
LOG_DBG("pressing: %d", keycode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int on_keycode_released(struct device *dev, u8_t usage_page, u32_t keycode)
|
||||
{
|
||||
LOG_DBG("releasing: %d", keycode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct behavior_driver_api behavior_mod_tap_driver_api = {
|
||||
// These callbacks are all optional, and define which kinds of events the behavior can handle.
|
||||
// They can reference local functions defined here, or shared event handlers.
|
||||
.binding_pressed = on_keymap_binding_pressed,
|
||||
.binding_released = on_keymap_binding_released,
|
||||
.keycode_pressed = on_keycode_pressed,
|
||||
.keycode_released = on_keycode_released
|
||||
// Other optional callbacks a behavior can implement
|
||||
// .on_mouse_moved
|
||||
// .on_sensor_data - Any behaviour that wants to be linked to a censor can implement this behavior
|
||||
};
|
||||
|
||||
|
||||
@@ -81,7 +78,7 @@ static const struct behavior_mod_tap_config behavior_mod_tap_config = {};
|
||||
|
||||
static struct behavior_mod_tap_data behavior_mod_tap_data;
|
||||
|
||||
DEVICE_AND_API_INIT(behavior_key_press, DT_INST_LABEL(0), behavior_mod_tap_init,
|
||||
DEVICE_AND_API_INIT(behavior_mod_tap, DT_INST_LABEL(0), behavior_mod_tap_init,
|
||||
&behavior_mod_tap_data,
|
||||
&behavior_mod_tap_config,
|
||||
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
||||
|
||||
Reference in New Issue
Block a user