Basic working SD card.'
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#include "storage_task.h"
|
||||
|
||||
#include "../storage/storage_config.h"
|
||||
|
||||
StorageTask::StorageTask(SDManager& manager)
|
||||
|
||||
StorageTask::StorageTask(SDManager& manager, StorageState& state)
|
||||
:
|
||||
storage(manager),
|
||||
storageState(state),
|
||||
taskHandle(nullptr)
|
||||
{
|
||||
}
|
||||
@@ -40,6 +43,11 @@ void StorageTask::run()
|
||||
{
|
||||
Serial.println("[Storage] Initializing SD card...");
|
||||
|
||||
storageState.begin();
|
||||
|
||||
// While the mount has not succeeded the dashboard must show "SD not found".
|
||||
storageState.setMounted(false);
|
||||
|
||||
// Retry the mount until it succeeds. This keeps the card dead-pin-capable:
|
||||
// reseating the card, fixing a wire, or powering the module will bring it
|
||||
// up without rebooting the Hub. (The SD init handshake runs at 400 kHz, so
|
||||
@@ -53,17 +61,35 @@ void StorageTask::run()
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
}
|
||||
|
||||
storageState.setMounted(true);
|
||||
storageState.setCardType(storage.cardTypeName());
|
||||
|
||||
storage.printCardInfo();
|
||||
storage.listFiles();
|
||||
|
||||
// Initial write-speed estimate for the dashboard.
|
||||
storageState.setWriteSpeedBps(storage.measureWriteSpeed());
|
||||
storageState.setCapacity(storage.totalBytes(), storage.usedBytes());
|
||||
|
||||
TickType_t lastWake =
|
||||
xTaskGetTickCount();
|
||||
|
||||
uint32_t lastSpeedMeasure = millis();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Periodically re-estimate write speed and refresh capacity so the
|
||||
// dashboard stays current. An interval of 0 disables re-measuring.
|
||||
if (STORAGE_SPEED_MEASURE_INTERVAL_MS != 0 &&
|
||||
millis() - lastSpeedMeasure >= STORAGE_SPEED_MEASURE_INTERVAL_MS)
|
||||
{
|
||||
lastSpeedMeasure = millis();
|
||||
storageState.setWriteSpeedBps(storage.measureWriteSpeed());
|
||||
storageState.setCapacity(storage.totalBytes(), storage.usedBytes());
|
||||
}
|
||||
|
||||
// Future integration point: a producer/consumer queue will feed
|
||||
// audio data here to be flushed to the card. For now the task
|
||||
// simply idles while the system runs.
|
||||
// audio data here to be flushed to the card.
|
||||
vTaskDelayUntil(
|
||||
&lastWake,
|
||||
pdMS_TO_TICKS(1000)
|
||||
|
||||
Reference in New Issue
Block a user