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

@@ -29,7 +29,10 @@ static uint32_t activity_last_uptime;
#define MAX_SLEEP_MS CONFIG_ZMK_IDLE_SLEEP_TIMEOUT
#endif
int raise_event() { return ZMK_EVENT_RAISE(create_activity_state_changed(activity_state)); }
int raise_event() {
return ZMK_EVENT_RAISE(new_zmk_activity_state_changed(
(struct zmk_activity_state_changed){.state = activity_state}));
}
int set_state(enum zmk_activity_state state) {
if (activity_state == state)
@@ -41,7 +44,7 @@ int set_state(enum zmk_activity_state state) {
enum zmk_activity_state zmk_activity_get_state() { return activity_state; }
int activity_event_listener(const struct zmk_event_header *eh) {
int activity_event_listener(const zmk_event_t *eh) {
activity_last_uptime = k_uptime_get();
return set_state(ZMK_ACTIVITY_ACTIVE);
@@ -74,7 +77,7 @@ int activity_init() {
}
ZMK_LISTENER(activity, activity_event_listener);
ZMK_SUBSCRIPTION(activity, position_state_changed);
ZMK_SUBSCRIPTION(activity, sensor_event);
ZMK_SUBSCRIPTION(activity, zmk_position_state_changed);
ZMK_SUBSCRIPTION(activity, zmk_sensor_event);
SYS_INIT(activity_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);