Unmount storage when there's a bad error

custom
jacqueline 1 year ago
parent f93e3c1c69
commit e5c6ffdb8b
  1. 4
      src/audio/fatfs_source.cpp
  2. 5
      src/system_fsm/include/system_events.hpp
  3. 1
      src/system_fsm/include/system_fsm.hpp
  4. 8
      src/system_fsm/running.cpp

@ -12,11 +12,13 @@
#include <memory>
#include "esp_log.h"
#include "event_queue.hpp"
#include "ff.h"
#include "audio_source.hpp"
#include "codec.hpp"
#include "spi.hpp"
#include "system_events.hpp"
#include "types.hpp"
namespace audio {
@ -39,7 +41,7 @@ auto FatfsSource::Read(cpp::span<std::byte> dest) -> ssize_t {
UINT bytes_read = 0;
FRESULT res = f_read(file_.get(), dest.data(), dest.size(), &bytes_read);
if (res != FR_OK) {
ESP_LOGE(kTag, "error reading from file");
events::System().Dispatch(system_fsm::StorageError{.error = res});
return -1;
}
return bytes_read;

@ -11,6 +11,7 @@
#include "battery.hpp"
#include "bluetooth_types.hpp"
#include "database.hpp"
#include "ff.h"
#include "haptics.hpp"
#include "samd.hpp"
#include "service_locator.hpp"
@ -42,7 +43,9 @@ struct OnIdle : tinyfsm::Event {};
*/
struct StorageMounted : tinyfsm::Event {};
struct StorageError : tinyfsm::Event {};
struct StorageError : tinyfsm::Event {
FRESULT error;
};
struct KeyLockChanged : tinyfsm::Event {
bool locking;

@ -105,6 +105,7 @@ class Running : public SystemState {
void react(const database::event::UpdateFinished&) override;
void react(const SamdUsbMscChanged&) override;
void react(const internal::UnmountTimeout&) override;
void react(const StorageError&) override;
using SystemState::react;

@ -8,6 +8,7 @@
#include "audio_events.hpp"
#include "database.hpp"
#include "db_events.hpp"
#include "ff.h"
#include "file_gatherer.hpp"
#include "freertos/portmacro.h"
#include "freertos/projdefs.h"
@ -119,6 +120,13 @@ void Running::react(const SamdUsbMscChanged& ev) {
}
}
void Running::react(const StorageError& ev) {
ESP_LOGE(kTag, "storage error %u", ev.error);
if (ev.error == FR_DISK_ERR || ev.error == FR_INVALID_OBJECT) {
unmountStorage();
}
}
auto Running::checkIdle() -> void {
xTimerStop(sUnmountTimer, portMAX_DELAY);
if (IdleCondition()) {

Loading…
Cancel
Save