feat(events): add timestamp to keycode_state_changed and sensor_event

These timestamps are necessary to correctly deal with delayed events due to hold-tap shenanigans.
This commit is contained in:
Okke Formsma
2020-11-11 22:06:25 +01:00
committed by Pete Johanson
parent 27d036b9d5
commit bee45f9b3a
7 changed files with 21 additions and 17 deletions

View File

@@ -21,15 +21,15 @@ static int behavior_key_press_init(struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
return ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(binding->param1, true));
return ZMK_EVENT_RAISE(
keycode_state_changed_from_encoded(binding->param1, true, event.timestamp));
}
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
return ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(binding->param1, false));
return ZMK_EVENT_RAISE(
keycode_state_changed_from_encoded(binding->param1, false, event.timestamp));
}
static const struct behavior_driver_api behavior_key_press_driver_api = {

View File

@@ -18,8 +18,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int behavior_sensor_rotate_key_press_init(struct device *dev) { return 0; };
static int on_sensor_binding_triggered(struct zmk_behavior_binding *binding,
struct device *sensor) {
static int on_sensor_binding_triggered(struct zmk_behavior_binding *binding, struct device *sensor,
s64_t timestamp) {
struct sensor_value value;
int err;
u32_t keycode;
@@ -45,12 +45,12 @@ static int on_sensor_binding_triggered(struct zmk_behavior_binding *binding,
LOG_DBG("SEND %d", keycode);
ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(keycode, true));
ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(keycode, true, timestamp));
// TODO: Better way to do this?
k_msleep(5);
return ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(keycode, false));
return ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(keycode, false, timestamp));
}
static const struct behavior_driver_api behavior_sensor_rotate_key_press_driver_api = {