Skip to content

Commit

Permalink
Don't try and call any sd functions unless mounting was successful.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgreening committed Apr 11, 2024
1 parent 92d38e1 commit 120e009
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion player/src/SDCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SDCard::SDCard(gpio_num_t clk, gpio_num_t cmd, gpio_num_t d0, gpio_num_t d1, gpi
Serial.printf("SDCard mounted at: %s\n", MOUNT_POINT);
// Card has been initialized, print its properties
sdmmc_card_print_info(stdout, m_card);
sd_card_init_success = true;
#endif
}

Expand Down Expand Up @@ -123,6 +124,7 @@ SDCard::SDCard(gpio_num_t miso, gpio_num_t mosi, gpio_num_t clk, gpio_num_t cs)
Serial.printf("SDCard mounted at: %s\n", MOUNT_POINT);
// Card has been initialized, print its properties
sdmmc_card_print_info(stdout, m_card);
sd_card_init_success = true;
}

SDCard::~SDCard()
Expand All @@ -135,7 +137,10 @@ SDCard::~SDCard()


bool SDCard::isMounted() {
return sdmmc_get_status(m_card) == ESP_OK;
if (sd_card_init_success) {
return sdmmc_get_status(m_card) == ESP_OK;
}
return false;
}

std::vector<std::string> SDCard::listFiles(const char *folder, const char *extension)
Expand Down
1 change: 1 addition & 0 deletions player/src/SDCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SDCard
#else
sdmmc_host_t m_host = SDSPI_HOST_DEFAULT();
#endif
bool sd_card_init_success = false;
public:
SDCard(gpio_num_t miso, gpio_num_t mosi, gpio_num_t clk, gpio_num_t cs);
SDCard(gpio_num_t clk, gpio_num_t cmd, gpio_num_t d0, gpio_num_t d1, gpio_num_t d2, gpio_num_t d3);
Expand Down

0 comments on commit 120e009

Please sign in to comment.