Skip to content

Commit

Permalink
fix: sd card info panics when there's no sd card
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Oct 4, 2024
1 parent fdded88 commit cce6abd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
4 changes: 0 additions & 4 deletions firmware/components/sd_card/sd_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,5 @@ esp_err_t sd_card_fill_info(const sdmmc_card_t* card) {
}

sd_card_info_t sd_card_get_info() {
if (sd_card_is_not_mounted()) {
ESP_LOGE(TAG, "SD card not mounted");
}

return _sd_card_info;
}
41 changes: 26 additions & 15 deletions firmware/main/modules/settings/settings_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,34 @@ void update_sd_card_info() {
oled_screen_clear();
modals_module_show_banner("Loading...");
vTaskDelay(1000 / portTICK_PERIOD_MS); // Wait for the SD card to be mounted
sd_card_info_t sd_info = sd_card_get_info();

char* name_str = malloc(strlen(sd_info.name) + 1);
sprintf(name_str, "Name: %s", sd_info.name);
char* capacity_str = malloc(20);
sprintf(capacity_str, "Space: %.2fGB", ((float) sd_info.total_space) / 1024);
char* speed_str = malloc(25);
sprintf(speed_str, "Speed: %.2fMHz", sd_info.speed);
char* type_str = malloc(strlen(sd_info.type) + 1 + 6);
sprintf(type_str, "Type: %s", sd_info.type);
if (sd_card_is_not_mounted()) {
sd_card_info_2[0] = "";
sd_card_info_2[1] = "No SD Card";
sd_card_info_2[2] = "";
sd_card_info_2[3] = "";
sd_card_info_2[4] = "";
sd_card_info_2[5] = "";
} else {
sd_card_info_t sd_info = sd_card_get_info();
char* name_str = malloc(strlen(sd_info.name) + 1);
sprintf(name_str, "Name: %s", sd_info.name);
char* capacity_str = malloc(20);
sprintf(capacity_str, "Space: %.2fGB",
((float) sd_info.total_space) / 1024);
char* speed_str = malloc(25);
sprintf(speed_str, "Speed: %.2fMHz", sd_info.speed);
char* type_str = malloc(strlen(sd_info.type) + 1 + 6);
sprintf(type_str, "Type: %s", sd_info.type);

sd_card_info_2[0] = "";
sd_card_info_2[1] = "SD Card Info";
sd_card_info_2[2] = name_str;
sd_card_info_2[3] = capacity_str;
sd_card_info_2[4] = speed_str;
sd_card_info_2[5] = type_str;
}

sd_card_info_2[0] = "";
sd_card_info_2[1] = "SD Card Info";
sd_card_info_2[2] = name_str;
sd_card_info_2[3] = capacity_str;
sd_card_info_2[4] = speed_str;
sd_card_info_2[5] = type_str;
sd_card_unmount();
general_register_scrolling_menu(&SD_inf);
general_screen_display_scrolling_text_handler(menus_module_exit_app);
Expand Down

0 comments on commit cce6abd

Please sign in to comment.