Skip to content

Commit

Permalink
Merge pull request #520 from Daft-Freak/sd-about
Browse files Browse the repository at this point in the history
Display SD card status and free space in the about menu
  • Loading branch information
Gadgetoid authored Jan 2, 2021
2 parents cc72da3 + b8402f1 commit 8bf872f
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions 32blit-stm32/Src/SystemMenu/about_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "32blit.h"
#include "32blit.hpp"
#include "ff.h"

using namespace blit;

Expand All @@ -23,13 +24,15 @@ enum MenuItem {
FIRMWARE_VERSION,
FIRMWARE_DATE,
BLIT_DEVICE_TYPE,
SD_CARD
};

static Menu::Item menu_items[]{
{ FIRMWARE_VERSION, "Version" },
{ FIRMWARE_DATE, "Date" },
{ Menu::Separator, nullptr },
{ BLIT_DEVICE_TYPE, "Device" },
{ SD_CARD, "SD Card"}
};

void AboutMenu::render_item(const Item &item, int y, int index) const {
Expand All @@ -52,11 +55,33 @@ void AboutMenu::render_item(const Item &item, int y, int index) const {
case BLIT_DEVICE_TYPE:
if(is_beta_unit) {
screen.text("Beta unit", minimal_font, Point(screen_width - item_padding_x, y + 1), true, TextAlign::right);
}
else {
} else {
screen.text("Retail unit", minimal_font, Point(screen_width - item_padding_x, y + 1), true, TextAlign::right);
}
break;
case SD_CARD:
if(blit_sd_mounted()) {
FATFS *fs;
DWORD free_clusters;
char buf[100];

auto res = f_getfree("", &free_clusters, &fs);

if(res == 0) {
// assuming 512b sectors
uint32_t total_mb = ((fs->n_fatent - 2) * fs->csize) / 2048;
uint32_t free_mb = (free_clusters * fs->csize) / 2048;

snprintf(buf, 100, "%lu/%lu MB free", free_mb, total_mb);
} else
snprintf(buf, 100, "Unknown %i", res);

screen.text(buf, minimal_font, Point(screen_width - item_padding_x, y + 1), true, TextAlign::right);
} else if(blit_sd_detected())
screen.text("Not mounted", minimal_font, Point(screen_width - item_padding_x, y + 1), true, TextAlign::right);
else
screen.text("Not inserted", minimal_font, Point(screen_width - item_padding_x, y + 1), true, TextAlign::right);
break;
default:
screen.pen = foreground_colour;
screen.text("Press A", minimal_font, Point(screen_width - item_padding_x, y + 1), true, TextAlign::right);
Expand Down

0 comments on commit 8bf872f

Please sign in to comment.