Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
zxkmm committed Dec 13, 2024
1 parent fdeaf38 commit d858c24
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 40 deletions.
13 changes: 12 additions & 1 deletion firmware/application/ui_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ SystemStatusView::SystemStatusView(

audio::output::stop();
audio::output::update_audio_mute();

refresh();
}

Expand Down Expand Up @@ -764,7 +765,7 @@ static void add_apps(NavigationView& nav, BtnGridView& grid, app_location_t loc)
void add_external_items(NavigationView& nav, app_location_t location, BtnGridView& grid, uint8_t notice_pos) {
auto externalItems = ExternalItemsMenuLoader::load_external_items(location, nav);
if (externalItems.empty()) {
grid.insert_item({"Notice!",
grid.insert_item({"ExtApp Error",
Theme::getInstance()->error_dark->foreground,
nullptr,
[&nav]() {
Expand Down Expand Up @@ -795,6 +796,11 @@ void add_external_items(NavigationView& nav, app_location_t location, BtnGridVie
}
// clang-format on

bool verify_sdcard_format() {
FATFS* fs = &sd_card::fs;
return fs->fs_type == FS_FAT32;
}

/* ReceiversMenuView *****************************************************/

ReceiversMenuView::ReceiversMenuView(NavigationView& nav)
Expand Down Expand Up @@ -866,6 +872,11 @@ SystemMenuView::SystemMenuView(NavigationView& nav)
}

void SystemMenuView::on_populate() {
if (!verify_sdcard_format()) {
add_item({"SDCard Error", Theme::getInstance()->error_dark->foreground, nullptr, [this]() {
nav_.display_modal("Error", "SD Card is not FAT32,\nformat to FAT32 on PC");
}});
}
add_apps(nav_, *this, HOME);
add_external_items(nav_, app_location_t::HOME, *this, 2);
add_item({"HackRF", Theme::getInstance()->fg_cyan->foreground, &bitmap_icon_hackrf, [this]() { hackrf_mode(nav_); }});
Expand Down
1 change: 1 addition & 0 deletions firmware/application/ui_navigation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class SystemStatusView : public View {
static constexpr auto default_title = "";
bool batt_was_inited = false; // if the battery was off on tart, but later turned on.
bool batt_info_up = false; // to prevent show multiple batt info dialog

NavigationView& nav_;

Rectangle backdrop{
Expand Down
51 changes: 44 additions & 7 deletions firmware/application/ui_sd_card_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,16 @@ namespace ui {

SDCardDebugView::SDCardDebugView(NavigationView& nav) {
add_children({
&text_title,
&text_csd_title,
&labels,
&text_format,
&text_csd_value_3,
&text_csd_value_2,
&text_csd_value_1,
&text_csd_value_0,
&text_bus_width_title,
&text_bus_width_value,
&text_card_type_title,
&text_card_type_value,
&text_block_size_title,
&text_block_size_value,
&text_block_count_title,
&text_block_count_value,
&text_capacity_title,
&text_capacity_value,
&text_test_write_time_title,
&text_test_write_time_value,
Expand Down Expand Up @@ -374,6 +369,14 @@ void SDCardDebugView::on_status(const sd_card::Status) {
text_csd_value_1.set(to_string_hex(csd[1], 8));
text_csd_value_0.set(to_string_hex(csd[0], 8));

text_format.set(fetch_sdcard_format());
if (fetch_sdcard_format().find("FAT32") != std::string::npos) {
// to satisfy the intendent style in this app, the text contains padding space, thus can't use ==
text_format.set_style(Theme::getInstance()->fg_green);
} else {
text_format.set_style(Theme::getInstance()->error_dark);
}

BlockDeviceInfo block_device_info;
if (sdcGetInfo(&SDCD1, &block_device_info) == CH_SUCCESS) {
text_block_size_value.set(to_string_dec_uint(block_device_info.blk_size, 5));
Expand Down Expand Up @@ -447,4 +450,38 @@ void SDCardDebugView::on_test() {
}
}

std::string SDCardDebugView::fetch_sdcard_format() {
const size_t max_len = sizeof("Undefined: 255") + 1;

auto padding = [max_len](std::string s) {
if (s.length() < max_len) {
return std::string(max_len - s.length(), ' ') + s;
}
return s;
};

FATFS* fs = &sd_card::fs;
std::string resault;

switch (fs->fs_type) {
case FS_FAT12:
resault = "FAT12";
break;
case FS_FAT16:
resault = "FAT16";
break;
case FS_FAT32:
resault = "FAT32";
break;
case FS_EXFAT: // TODO: a bug from filesystem can't detect exfat, issue not from here
resault = "ExFAT";
break;
default:
resault = "Undefined: " + to_string_dec_uint(fs->fs_type, 1);
break;
}

return padding(resault);
}

} /* namespace ui */
45 changes: 14 additions & 31 deletions firmware/application/ui_sd_card_debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ class SDCardDebugView : public View {

void on_status(const sd_card::Status status);
void on_test();
std::string fetch_sdcard_format();

Labels labels{
{{0 * 8, 1 * 16}, "Format", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 3 * 16}, "CSD", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 5 * 16}, "Bus width", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 6 * 16}, "Card type", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 8 * 16}, "Block size", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 9 * 16}, "Block count", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 10 * 16}, "Capacity", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 5 * 16}, "Bus width", Theme::getInstance()->fg_light->foreground},

Text text_title{
{(240 - (7 * 8)) / 2, 1 * 16, (7 * 8), 16},
"SD Card",
};

Text text_csd_title{
{0, 3 * 16, (8 * 8), 16},
"CSD",
Text text_format{
{240 - ((sizeof("Undefined: 255") + 1) * 8), 1 * 16, (sizeof("Undefined: 255") + 1) * 8, 16},
"Unknown",
};

Text text_csd_value_3{
Expand All @@ -78,59 +86,34 @@ class SDCardDebugView : public View {

static constexpr size_t bus_width_characters = 1;

Text text_bus_width_title{
{0, 5 * 16, (9 * 8), 16},
"Bus width",
};

Text text_bus_width_value{
{240 - (bus_width_characters * 8), 5 * 16, (bus_width_characters * 8), 16},
"",
};

static constexpr size_t card_type_characters = 13;

Text text_card_type_title{
{0, 6 * 16, (9 * 8), 16},
"Card type",
};

Text text_card_type_value{
{240 - (card_type_characters * 8), 6 * 16, (card_type_characters * 8), 16},
"",
};

static constexpr size_t block_size_characters = 5;

Text text_block_size_title{
{0, 8 * 16, (10 * 8), 16},
"Block size",
};

Text text_block_size_value{
{240 - (block_size_characters * 8), 8 * 16, (block_size_characters * 8), 16},
"",
};

static constexpr size_t block_count_characters = 9;

Text text_block_count_title{
{0, 9 * 16, (11 * 8), 16},
"Block count",
};

Text text_block_count_value{
{240 - (block_count_characters * 8), 9 * 16, (block_count_characters * 8), 16},
"",
};

static constexpr size_t capacity_characters = 10;

Text text_capacity_title{
{0, 10 * 16, (8 * 8), 16},
"Capacity",
};

Text text_capacity_value{
{240 - (capacity_characters * 8), 10 * 16, (capacity_characters * 8), 16},
"",
Expand Down

0 comments on commit d858c24

Please sign in to comment.