Access to the "/data" partition via USB Mass Storage (#405)
This commit is contained in:
@@ -11,32 +11,50 @@
|
||||
|
||||
namespace tt::app::usbsettings {
|
||||
|
||||
static void onRebootMassStorage(TT_UNUSED lv_event_t* event) {
|
||||
static void onRebootMassStorageSdmmc(TT_UNUSED lv_event_t* event) {
|
||||
hal::usb::rebootIntoMassStorageSdmmc();
|
||||
}
|
||||
|
||||
// Flash reboot handler
|
||||
static void onRebootMassStorageFlash(TT_UNUSED lv_event_t* event) {
|
||||
hal::usb::rebootIntoMassStorageFlash();
|
||||
}
|
||||
|
||||
class UsbSettingsApp : public App {
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
auto* toolbar = lvgl::toolbar_create(parent, app);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
if (hal::usb::canRebootIntoMassStorageSdmmc()) {
|
||||
auto* button = lv_button_create(parent);
|
||||
auto* label = lv_label_create(button);
|
||||
lv_label_set_text(label, "Reboot as USB storage");
|
||||
lv_obj_align(button, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_event_cb(button, onRebootMassStorage, LV_EVENT_SHORT_CLICKED, nullptr);
|
||||
} else {
|
||||
// Create a wrapper container for buttons
|
||||
auto* wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(wrapper, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_size(wrapper, lv_pct(100), LV_SIZE_CONTENT);
|
||||
lv_obj_align(wrapper, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
bool hasSd = hal::usb::canRebootIntoMassStorageSdmmc();
|
||||
bool hasFlash = hal::usb::canRebootIntoMassStorageFlash();
|
||||
|
||||
if (hasSd) {
|
||||
auto* button_sd = lv_button_create(wrapper);
|
||||
auto* label_sd = lv_label_create(button_sd);
|
||||
lv_label_set_text(label_sd, "Reboot as USB storage (SD)");
|
||||
lv_obj_add_event_cb(button_sd, onRebootMassStorageSdmmc, LV_EVENT_SHORT_CLICKED, nullptr);
|
||||
}
|
||||
|
||||
if (hasFlash) {
|
||||
auto* button_flash = lv_button_create(wrapper);
|
||||
auto* label_flash = lv_label_create(button_flash);
|
||||
lv_label_set_text(label_flash, "Reboot as USB storage (Flash)");
|
||||
lv_obj_add_event_cb(button_flash, onRebootMassStorageFlash, LV_EVENT_SHORT_CLICKED, nullptr);
|
||||
}
|
||||
|
||||
if (!hasSd && !hasFlash) {
|
||||
bool supported = hal::usb::isSupported();
|
||||
const char* first = supported ? "USB storage not available:" : "USB driver not supported";
|
||||
const char* second = supported ? "SD card not mounted" : "on this hardware";
|
||||
auto* label_a = lv_label_create(parent);
|
||||
lv_label_set_text(label_a, first);
|
||||
lv_obj_align(label_a, LV_ALIGN_CENTER, 0, 0);
|
||||
auto* label_b = lv_label_create(parent);
|
||||
lv_label_set_text(label_b, second);
|
||||
lv_obj_align_to(label_b, label_a, LV_ALIGN_OUT_BOTTOM_MID, 0, 4);
|
||||
const char* message = supported ? "USB storage not available" : "USB driver not supported";
|
||||
auto* label = lv_label_create(wrapper);
|
||||
lv_label_set_text(label, message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user