Refactored events (#621)

Event handling:

- Added unified event handling for application, system, and Wi‑Fi events.
- Updated all apps to reflect event handling changes

Wi-Fi:

- Refactored event handling from listener interface to task & event group.
- Added direct Wi‑Fi radio controls and improved event subscriptions.
- Wi‑Fi screens now refresh asynchronously and handle unavailable devices more gracefully.
- Enabled Wi‑Fi by default on in dts files, but radio on/off is still done by code. The main reason was reliable event subscription and consistent devicetree states.
- Improved Wi‑Fi shutdown cleanup and radio-state handling.

Other:
- Renamed the Kernel Display app to Display.
This commit is contained in:
Ken Van Hoeylandt
2026-08-25 17:44:20 +02:00
committed by GitHub
parent db48dfe812
commit ab75d2022d
121 changed files with 2416 additions and 1381 deletions
@@ -6,10 +6,12 @@
#include <tactility/delay.h>
#include <tactility/time.h>
TEST_CASE("app_event_subscribe/_await deliver events in FIFO order") {
TEST_CASE("app_event_subscribe/_poll deliver events in FIFO order") {
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
AppEventSubscription sub {};
sub.app_instance_id = 1;
CHECK_EQ(app_event_subscribe(&sub), ERROR_NONE);
CHECK_EQ(app_event_subscribe_with_app_id(&sub, &event_group, 1), ERROR_NONE);
for (uint32_t i = 0; i < 3; i++) {
AppEvent event { .type = APP_EVENT_RESULT, .timestamp = 0, .result = { .launch_id = i, .result = 0 } };
@@ -18,32 +20,38 @@ TEST_CASE("app_event_subscribe/_await deliver events in FIFO order") {
for (uint32_t i = 0; i < 3; i++) {
AppEvent out {};
CHECK_EQ(app_event_await(&sub, &out, 0), ERROR_NONE);
CHECK_EQ(app_event_poll(&sub, &out), ERROR_NONE);
CHECK_EQ(out.type, APP_EVENT_RESULT);
CHECK_EQ(out.result.launch_id, i);
}
app_event_unsubscribe(&sub);
task_event_group_destruct(&event_group);
}
TEST_CASE("app_event_emit only delivers to subscriptions for that app_instance_id") {
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
AppEventSubscription sub {};
sub.app_instance_id = 10;
app_event_subscribe(&sub);
app_event_subscribe_with_app_id(&sub, &event_group, 10);
AppEvent event { .type = APP_EVENT_CLOSE, .timestamp = 0, .result = {} };
CHECK_EQ(app_event_emit(11, &event), ERROR_NOT_FOUND);
AppEvent out {};
CHECK_EQ(app_event_await(&sub, &out, 0), ERROR_TIMEOUT);
CHECK_EQ(app_event_poll(&sub, &out), ERROR_TIMEOUT);
app_event_unsubscribe(&sub);
task_event_group_destruct(&event_group);
}
TEST_CASE("app_event_emit returns ERROR_RESOURCE and drops the newest event once a subscription's queue is full") {
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
AppEventSubscription sub {};
sub.app_instance_id = 20;
app_event_subscribe(&sub);
app_event_subscribe_with_app_id(&sub, &event_group, 20);
for (uint32_t i = 0; i < APP_EVENT_QUEUE_CAPACITY; i++) {
AppEvent event { .type = APP_EVENT_RESULT, .timestamp = 0, .result = { .launch_id = i, .result = 0 } };
@@ -57,42 +65,52 @@ TEST_CASE("app_event_emit returns ERROR_RESOURCE and drops the newest event once
// The already-queued events survive, in order, and the dropped one never arrives.
for (uint32_t i = 0; i < APP_EVENT_QUEUE_CAPACITY; i++) {
AppEvent out {};
CHECK_EQ(app_event_await(&sub, &out, 0), ERROR_NONE);
CHECK_EQ(app_event_poll(&sub, &out), ERROR_NONE);
CHECK_EQ(out.result.launch_id, i);
}
AppEvent out {};
CHECK_EQ(app_event_await(&sub, &out, 0), ERROR_TIMEOUT);
CHECK_EQ(app_event_poll(&sub, &out), ERROR_TIMEOUT);
app_event_unsubscribe(&sub);
task_event_group_destruct(&event_group);
}
TEST_CASE("app_event_unsubscribe stops further delivery") {
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
AppEventSubscription sub {};
sub.app_instance_id = 30;
app_event_subscribe(&sub);
app_event_subscribe_with_app_id(&sub, &event_group, 30);
CHECK_EQ(app_event_unsubscribe(&sub), ERROR_NONE);
CHECK_EQ(app_event_unsubscribe(&sub), ERROR_NOT_FOUND);
AppEvent event { .type = APP_EVENT_CLOSE, .timestamp = 0, .result = {} };
CHECK_EQ(app_event_emit(30, &event), ERROR_NOT_FOUND);
task_event_group_destruct(&event_group);
}
TEST_CASE("app_event_await times out when no event has arrived") {
TEST_CASE("app_event_poll times out when no event has arrived") {
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
AppEventSubscription sub {};
sub.app_instance_id = 40;
app_event_subscribe(&sub);
app_event_subscribe_with_app_id(&sub, &event_group, 40);
AppEvent out {};
CHECK_EQ(app_event_await(&sub, &out, 0), ERROR_TIMEOUT);
CHECK_EQ(app_event_poll(&sub, &out), ERROR_TIMEOUT);
app_event_unsubscribe(&sub);
task_event_group_destruct(&event_group);
}
TEST_CASE("app_event_emit stamps the event with the current boot-relative time") {
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
AppEventSubscription sub {};
sub.app_instance_id = 50;
app_event_subscribe(&sub);
app_event_subscribe_with_app_id(&sub, &event_group, 50);
auto before = static_cast<uint64_t>(get_micros_since_boot());
AppEvent event { .type = APP_EVENT_CLOSE, .timestamp = 0, .result = {} };
@@ -100,17 +118,20 @@ TEST_CASE("app_event_emit stamps the event with the current boot-relative time")
auto after = static_cast<uint64_t>(get_micros_since_boot());
AppEvent out {};
REQUIRE_EQ(app_event_await(&sub, &out, 0), ERROR_NONE);
REQUIRE_EQ(app_event_poll(&sub, &out), ERROR_NONE);
CHECK_GE(out.timestamp, before);
CHECK_LE(out.timestamp, after);
app_event_unsubscribe(&sub);
task_event_group_destruct(&event_group);
}
TEST_CASE("app_event_await wakes when the event is emitted from another task") {
TEST_CASE("task_event_group_wait wakes when the event is emitted from another task") {
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
AppEventSubscription sub {};
sub.app_instance_id = 60;
CHECK_EQ(app_event_subscribe(&sub), ERROR_NONE);
CHECK_EQ(app_event_subscribe_with_app_id(&sub, &event_group, 60), ERROR_NONE);
auto* thread = thread_alloc_full(
"app-event-emitter",
@@ -126,12 +147,14 @@ TEST_CASE("app_event_await wakes when the event is emitted from another task") {
);
CHECK_EQ(thread_start(thread), ERROR_NONE);
CHECK_EQ(task_event_group_wait(&event_group, sub.bit, false, nullptr, pdMS_TO_TICKS(2000)), ERROR_NONE);
AppEvent out {};
CHECK_EQ(app_event_await(&sub, &out, pdMS_TO_TICKS(2000)), ERROR_NONE);
CHECK_EQ(app_event_poll(&sub, &out), ERROR_NONE);
CHECK_EQ(out.type, APP_EVENT_CLOSE);
CHECK_EQ(thread_join(thread, pdMS_TO_TICKS(2000), 1), ERROR_NONE);
thread_free(thread);
app_event_unsubscribe(&sub);
task_event_group_destruct(&event_group);
}