Commit 59b64cb0 authored by natalie's avatar natalie 💜
Browse files

Refactor SD card cache invalidation

parent de09f355
......@@ -175,7 +175,7 @@ static void file_error() {
QueueLength = 0;
QueuePosition = 0;
Ui_Screen = UISCREEN_MAINMENU;
Sdcard_Online = false;
Sdcard_Invalidate();
ESP_LOGE(TAG, "IO error");
}
static bool DacStream_FoundAny = false;
......
......@@ -127,7 +127,7 @@ static void file_error() {
QueueLength = 0;
QueuePosition = 0;
Ui_Screen = UISCREEN_MAINMENU;
Sdcard_Online = false;
Sdcard_Invalidate();
ESP_LOGE(TAG, "IO error");
}
......
......@@ -317,7 +317,7 @@ const option_t Options[OPTION_COUNT] = {
static void file_error() {
modal_show_simple(TAG, "SD Card Error", "There was an error saving settings to the SD card.\nPlease check that the card is inserted and has free space.", LV_SYMBOL_OK " OK");
Sdcard_Online = false;
Sdcard_Invalidate();
Ui_Screen = UISCREEN_MAINMENU;
}
......@@ -494,7 +494,7 @@ void OptionsMgr_Main() {
while (1) {
if (OptionsMgr_Unsaved && OptionsMgr_ShittyTimer++ == 2) {
OptionsMgr_ShittyTimer = 0;
if (Sdcard_Online) {
if (Sdcard_IsOnline()) {
OptionsMgr_Unsaved = false;
OptionsMgr_Save();
} else {
......
......@@ -114,7 +114,7 @@ static void file_error(bool writing) {
QueueLength = 0;
QueuePosition = 0;
Ui_Screen = UISCREEN_MAINMENU;
Sdcard_Online = false;
Sdcard_Invalidate();
}
static bool Player_NextTrk(bool UserSpecified) { //returns true if there is now a track playing
......
......@@ -2,6 +2,7 @@
#include "mallocs.h"
#include "esp_log.h"
#include <dirent.h>
#include "ui/shuffleall.h"
static const char* TAG = "Sdcard";
......@@ -103,6 +104,10 @@ uint8_t Sdcard_Setup() {
return 0;
}
void Sdcard_Invalidate() { //mark card offline and invalidate any cached stuff that depends on card contents
Sdcard_Online = false;
}
void Sdcard_Destroy() {
if (state_mounted_fs) f_unmount(drv);
if (state_registered_vfs) {
......@@ -120,5 +125,9 @@ void Sdcard_Destroy() {
state_registered_diskio = false;
state_registered_vfs = false;
state_mounted_fs = false;
Sdcard_Online = false;
Sdcard_Invalidate(); //instead of Sdcard_Online = false;
}
bool Sdcard_IsOnline() {
return Sdcard_Online;
}
\ No newline at end of file
......@@ -9,9 +9,9 @@
#include "sdmmc_cmd.h"
#include "diskio.h"
extern volatile bool Sdcard_Online;
uint8_t Sdcard_Setup();
void Sdcard_Destroy();
bool Sdcard_IsOnline();
void Sdcard_Invalidate();
#endif
\ No newline at end of file
......@@ -88,7 +88,7 @@ static void file_error(bool writing) {
modal_show_simple(TAG, "SD Card Error", "There was an error writing to the SD card.\nPlease check that the card is inserted and has free space.", LV_SYMBOL_OK " OK");
}
Ui_Screen = UISCREEN_MAINMENU;
Sdcard_Online = false;
Sdcard_Invalidate();
ESP_LOGE(TAG, "IO error");
}
......
......@@ -197,7 +197,7 @@ void Ui_MainMenu_Key(KeyEvent_t event) {
break;
case KEY_C:
KeyMgr_Consume(KEY_C);
if (mm_curicon < MM_ICON_COUNT-1 && !Sdcard_Online) {
if (mm_curicon < MM_ICON_COUNT-1 && !Sdcard_IsOnline()) {
ESP_LOGW(TAG, "Sdcard is off, try to bring it up again...");
Sdcard_Destroy();
uint8_t ret = Sdcard_Setup();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment