Storage: poll the SD card on its own task

A failed mount retries for ~2.5 s, which froze the UI every 15 s while
no card was inserted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-02 10:14:27 +02:00
co-authored by Claude Opus 5.5
parent 987406fa7c
commit 44de78ea62
3 changed files with 50 additions and 14 deletions
+12 -3
View File
@@ -1,25 +1,34 @@
#pragma once
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include "service.h"
#include "storage_monitor.h"
namespace roro {
// Mounts the microSD card (retrying while absent) and feeds its usage to the StorageMonitor.
// Runs on its own task: a failed mount blocks for seconds and must never stall the UI.
class StorageService : public Service {
public:
explicit StorageService(EventBus& bus) : monitor_(bus) {}
const char* name() const override { return "storage"; }
uint32_t tickIntervalMs() const override { return 15000; }
void tick(uint32_t nowMs) override;
void start() override;
void stop() override;
const StorageState& state() const { return monitor_.state(); }
StorageState state() const;
private:
static constexpr uint32_t kPollMs = 15000;
static void taskEntry(void* self);
void poll();
bool mount();
StorageMonitor monitor_;
bool mounted_ = false;
TaskHandle_t task_ = nullptr;
mutable SemaphoreHandle_t lock_ = nullptr;
};
} // namespace roro