#pragma once #include "core/app_event.h" #include #include #include #include namespace borla { class AppEventQueue { public: static constexpr size_t kCapacity = 32; AppEventQueue() { queue_ = xQueueCreateStatic( kCapacity, sizeof(AppEvent), storage_, &queue_storage_); } bool Publish(const AppEvent& event, TickType_t wait_ticks = 0) { return xQueueSend(queue_, &event, wait_ticks) == pdTRUE; } bool PublishFromIsr(const AppEvent& event, BaseType_t* higher_priority_woken) { return xQueueSendFromISR(queue_, &event, higher_priority_woken) == pdTRUE; } bool Receive(AppEvent* event, TickType_t wait_ticks = portMAX_DELAY) { return xQueueReceive(queue_, event, wait_ticks) == pdTRUE; } size_t Pending() const { return static_cast(uxQueueMessagesWaiting(queue_)); } private: StaticQueue_t queue_storage_{}; alignas(AppEvent) uint8_t storage_[kCapacity * sizeof(AppEvent)]{}; QueueHandle_t queue_ = nullptr; }; } // namespace borla