Public Access
Add core runtime: event bus, services, app lifecycle
lib/core is hardware-independent and unit-tested on the host: - EventBus: fixed-size thread-safe queue, delivered on the UI task by dispatch(); drops newest when full and counts drops - Service / ServiceManager: cooperative ticking at per-service intervals, no catch-up bursts, safe across millis() wraparound - App / AppManager: one foreground App, Home always to Launcher, Back offered to the App first, hidden Apps, redraw requests - KeyEvent: logical keys for the upcoming input layer Firmware main loop now ticks services and dispatches events. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#include "app_manager.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace roro {
|
||||
|
||||
AppManager::AppManager(App& launcher) : launcher_(launcher), foreground_(&launcher) {}
|
||||
|
||||
void AppManager::registerApp(const AppInfo& info) { apps_.push_back(info); }
|
||||
|
||||
std::vector<const AppInfo*> AppManager::visibleApps() const {
|
||||
std::vector<const AppInfo*> visible;
|
||||
for (auto& info : apps_)
|
||||
if (!info.hidden) visible.push_back(&info);
|
||||
return visible;
|
||||
}
|
||||
|
||||
void AppManager::begin() {
|
||||
foreground_ = &launcher_;
|
||||
launcher_.onEnter();
|
||||
redraw_ = true;
|
||||
}
|
||||
|
||||
bool AppManager::open(const char* id) {
|
||||
for (auto& info : apps_) {
|
||||
if (std::strcmp(info.id, id) == 0) {
|
||||
switchTo(*info.app);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppManager::home() { switchTo(launcher_); }
|
||||
|
||||
void AppManager::handleKey(const KeyEvent& event) {
|
||||
if (event.key == Key::Home) {
|
||||
home();
|
||||
return;
|
||||
}
|
||||
bool consumed = foreground_->onKey(event);
|
||||
if (!consumed && event.key == Key::Back) home();
|
||||
}
|
||||
|
||||
bool AppManager::takeRedraw() {
|
||||
bool r = redraw_ | foreground_->consumeRedraw();
|
||||
redraw_ = false;
|
||||
return r;
|
||||
}
|
||||
|
||||
void AppManager::switchTo(App& app) {
|
||||
if (&app == foreground_) return;
|
||||
foreground_->onExit();
|
||||
foreground_ = &app;
|
||||
foreground_->onEnter();
|
||||
redraw_ = true;
|
||||
}
|
||||
|
||||
} // namespace roro
|
||||
Reference in New Issue
Block a user