Skip to content

Commit

Permalink
lambda the flash util menu add item code (#1993)
Browse files Browse the repository at this point in the history
* lambda the flash util menu add code

* clean up
  • Loading branch information
zxkmm committed Mar 15, 2024
1 parent f0614c8 commit 181624d
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions firmware/application/apps/ui_flash_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace ui {

static const char16_t* firmware_folder = u"/FIRMWARE";
static const std::filesystem::path firmware_path = u"/FIRMWARE";

// Firmware image validation
static const char* hackrf_magic = "HACKRFFW";
Expand Down Expand Up @@ -84,30 +84,29 @@ FlashUtilityView::FlashUtilityView(NavigationView& nav)

menu_view.set_parent_rect({0, 3 * 8, 240, 33 * 8});

ensure_directory(firmware_folder);
ensure_directory(firmware_path);

auto add_firmware_items = [&](
const std::filesystem::path& folder_path,
const std::filesystem::path& wild,
ui::Color color) {
for (const auto& entry : std::filesystem::directory_iterator(folder_path, wild)) {
auto filename = entry.path().filename();
auto path = entry.path().native();

menu_view.add_item({filename.string().substr(0, max_filename_length),
color,
&bitmap_icon_temperature,
[this, path](KeyEvent) {
this->firmware_selected(path);
}});
}
};

for (const auto& entry : std::filesystem::directory_iterator(firmware_folder, u"*.bin")) {
auto filename = entry.path().filename();
auto path = entry.path().native();
add_firmware_items(firmware_path, u"*.bin", ui::Color::red());
add_firmware_items(firmware_path, u"*.tar", ui::Color::purple());

menu_view.add_item({filename.string().substr(0, max_filename_length),
ui::Color::red(),
&bitmap_icon_temperature,
[this, path](KeyEvent) {
this->firmware_selected(path);
}});
}
for (const auto& entry : std::filesystem::directory_iterator(firmware_folder, u"*.tar")) {
auto filename = entry.path().filename();
auto path = entry.path().native();

menu_view.add_item({filename.string().substr(0, max_filename_length),
ui::Color::purple(),
&bitmap_icon_temperature,
[this, path](KeyEvent) {
this->firmware_selected(path);
}});
}
// add_firmware_items(user_firmware_folder,u"*.bin", ui::Color::purple());
}

void FlashUtilityView::firmware_selected(std::filesystem::path::string_type path) {
Expand Down Expand Up @@ -179,4 +178,4 @@ void FlashUtilityView::focus() {
menu_view.focus();
}

} /* namespace ui */
} /* namespace ui */

0 comments on commit 181624d

Please sign in to comment.