refactor(core): Extra event payloads to own types, refactor API.

* Make it easier to use *just* event payloads by defining the data,
  and then having event manager macros generate "wrapper structs"
* Improve is_*/cast_* APIs to hide details of full event struct.
* Create `zmk_event_t` typedef to pass to event handlers.
* Bring event names inline w/ consistent `zmk_` prefix.
This commit is contained in:
Pete Johanson
2021-01-18 00:35:56 -05:00
parent 003db892ad
commit 3fe2acc2d1
40 changed files with 190 additions and 239 deletions

View File

@@ -246,14 +246,13 @@ int zmk_keymap_sensor_triggered(uint8_t sensor_number, const struct device *sens
#endif /* ZMK_KEYMAP_HAS_SENSORS */
int keymap_listener(const struct zmk_event_header *eh) {
if (is_position_state_changed(eh)) {
const struct position_state_changed *ev = cast_position_state_changed(eh);
return zmk_keymap_position_state_changed(ev->data.position, ev->data.state,
ev->data.timestamp);
int keymap_listener(const zmk_event_t *eh) {
if (is_zmk_position_state_changed(eh)) {
const struct zmk_position_state_changed *ev = cast_zmk_position_state_changed(eh);
return zmk_keymap_position_state_changed(ev->position, ev->state, ev->timestamp);
#if ZMK_KEYMAP_HAS_SENSORS
} else if (is_sensor_event(eh)) {
const struct sensor_event *ev = cast_sensor_event(eh);
} else if (is_zmk_sensor_event(eh)) {
const struct zmk_sensor_event *ev = cast_zmk_sensor_event(eh);
return zmk_keymap_sensor_triggered(ev->sensor_number, ev->sensor, ev->timestamp);
#endif /* ZMK_KEYMAP_HAS_SENSORS */
}
@@ -262,8 +261,8 @@ int keymap_listener(const struct zmk_event_header *eh) {
}
ZMK_LISTENER(keymap, keymap_listener);
ZMK_SUBSCRIPTION(keymap, position_state_changed);
ZMK_SUBSCRIPTION(keymap, zmk_position_state_changed);
#if ZMK_KEYMAP_HAS_SENSORS
ZMK_SUBSCRIPTION(keymap, sensor_event);
ZMK_SUBSCRIPTION(keymap, zmk_sensor_event);
#endif /* ZMK_KEYMAP_HAS_SENSORS */