fix hanging

This commit is contained in:
2025-10-12 20:37:30 +02:00
parent 088c6e47bd
commit 7474f65aaa
8 changed files with 28 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ private:
class HighResClockService;
class PowerService;
class FilesystemService;
class LoopHooksService;
std::unique_ptr<BuzzerService> buzzerService;
std::unique_ptr<BatteryService> batteryService;
@@ -70,6 +71,7 @@ private:
std::unique_ptr<PowerService> powerService;
std::unique_ptr<FilesystemService> filesystemService;
std::unique_ptr<EventBus> eventBus;
std::unique_ptr<LoopHooksService> loopHooksService;
cardboy::sdk::Services services{};
};

View File

@@ -128,6 +128,11 @@ public:
}
};
class EspRuntime::LoopHooksService final : public cardboy::sdk::ILoopHooks {
public:
void onLoopIteration() override { vTaskDelay(1); }
};
EspRuntime::EspRuntime() : framebuffer(), input(), clock() {
initializeHardware();
@@ -139,6 +144,7 @@ EspRuntime::EspRuntime() : framebuffer(), input(), clock() {
powerService = std::make_unique<PowerService>();
filesystemService = std::make_unique<FilesystemService>();
eventBus = std::make_unique<EventBus>();
loopHooksService = std::make_unique<LoopHooksService>();
services.buzzer = buzzerService.get();
services.battery = batteryService.get();
@@ -148,6 +154,7 @@ EspRuntime::EspRuntime() : framebuffer(), input(), clock() {
services.powerManager = powerService.get();
services.filesystem = filesystemService.get();
services.eventBus = eventBus.get();
services.loopHooks = loopHooksService.get();
Buttons::get().setEventBus(eventBus.get());
}

View File

@@ -17,6 +17,7 @@ target_sources(cardboy_backend_interface
${CMAKE_CURRENT_SOURCE_DIR}/include/cardboy/sdk/backend.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cardboy/sdk/display_spec.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cardboy/sdk/event_bus.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cardboy/sdk/loop_hooks.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cardboy/sdk/input_state.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cardboy/sdk/platform.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/cardboy/sdk/services.hpp

View File

@@ -0,0 +1,11 @@
#pragma once
namespace cardboy::sdk {
class ILoopHooks {
public:
virtual ~ILoopHooks() = default;
virtual void onLoopIteration() = 0;
};
} // namespace cardboy::sdk

View File

@@ -1,6 +1,7 @@
#pragma once
#include "cardboy/sdk/event_bus.hpp"
#include "cardboy/sdk/loop_hooks.hpp"
#include <cstdint>
#include <string>
@@ -85,6 +86,7 @@ struct Services {
IPowerManager* powerManager = nullptr;
IFilesystem* filesystem = nullptr;
IEventBus* eventBus = nullptr;
ILoopHooks* loopHooks = nullptr;
};
} // namespace cardboy::sdk

View File

@@ -244,6 +244,7 @@ DesktopRuntime::DesktopRuntime() :
services.powerManager = &powerService;
services.filesystem = &filesystemService;
services.eventBus = &eventBusService;
services.loopHooks = nullptr;
}
cardboy::sdk::Services& DesktopRuntime::serviceRegistry() { return services; }

View File

@@ -64,6 +64,7 @@ struct AppContext {
[[nodiscard]] IPowerManager* powerManager() const { return services ? services->powerManager : nullptr; }
[[nodiscard]] IFilesystem* filesystem() const { return services ? services->filesystem : nullptr; }
[[nodiscard]] IEventBus* eventBus() const { return services ? services->eventBus : nullptr; }
[[nodiscard]] ILoopHooks* loopHooks() const { return services ? services->loopHooks : nullptr; }
void requestAppSwitchByIndex(std::size_t index) {
pendingAppIndex = index;

View File

@@ -138,6 +138,9 @@ void AppSystem::run() {
eventBus->scheduleTimerSignal(waitMs);
eventBus->wait(mask, IEventBus::kWaitForever);
}
if (auto* hooks = context.loopHooks())
hooks->onLoopIteration();
}
}