Refactor app launching (#174)
- Refactor the way apps work: Instead of a C interface, they are now C++ classes. The main reasoning is that attaching data to an app was cumbersome. Having different implementations for different kinds of apps was cumbersome too. (3 or 4 layers of manifest nesting for the TactilityC project) - External apps are still written in C, but they get a createData/destroyData in their manifest, so: - External apps now have their own manifest. - All functions in the original AppManifest are removed and replaced by a single `createApp` function - External apps now automatically register (each app individually!) when they run the first time. As a side-effect they become visible in the `AppList` app! - Adapted all apps for the new interface. - Adapted all internal logic for these changes (Gui, ViewPort, Loader, AppContext, AppInstance, etc.) - Rewrote parts of Loader to use std::shared_ptr to make the code much safer. - Added a refcount check for the `AppInstance` and `App` at the end of their lifecycle. Show warning if refcount is too high.
This commit is contained in:
committed by
GitHub
parent
2bbd44a8b5
commit
c3bcf93698
@@ -24,101 +24,93 @@
|
||||
|
||||
namespace tt::app::boot {
|
||||
|
||||
static int32_t bootThreadCallback(void* context);
|
||||
static void startNextApp();
|
||||
class BootApp : public App {
|
||||
|
||||
struct Data {
|
||||
Data() : thread("boot", 4096, bootThreadCallback, this) {}
|
||||
private:
|
||||
|
||||
Thread thread;
|
||||
};
|
||||
Thread thread = Thread("boot", 4096, bootThreadCallback, this);
|
||||
|
||||
static int32_t bootThreadCallback(TT_UNUSED void* context) {
|
||||
TickType_t start_time = kernel::getTicks();
|
||||
static int32_t bootThreadCallback(TT_UNUSED void* context) {
|
||||
TickType_t start_time = kernel::getTicks();
|
||||
|
||||
kernel::systemEventPublish(kernel::SystemEvent::BootSplash);
|
||||
kernel::systemEventPublish(kernel::SystemEvent::BootSplash);
|
||||
|
||||
auto* lvgl_display = lv_display_get_default();
|
||||
tt_assert(lvgl_display != nullptr);
|
||||
auto* hal_display = (hal::Display*)lv_display_get_user_data(lvgl_display);
|
||||
tt_assert(hal_display != nullptr);
|
||||
if (hal_display->supportsBacklightDuty()) {
|
||||
int32_t backlight_duty = app::display::getBacklightDuty();
|
||||
hal_display->setBacklightDuty(backlight_duty);
|
||||
}
|
||||
|
||||
if (hal::usb::isUsbBootMode()) {
|
||||
TT_LOG_I(TAG, "Rebooting into mass storage device mode");
|
||||
hal::usb::resetUsbBootMode();
|
||||
hal::usb::startMassStorageWithSdmmc();
|
||||
} else {
|
||||
TickType_t end_time = tt::kernel::getTicks();
|
||||
TickType_t ticks_passed = end_time - start_time;
|
||||
TickType_t minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS);
|
||||
if (minimum_ticks > ticks_passed) {
|
||||
kernel::delayTicks(minimum_ticks - ticks_passed);
|
||||
auto* lvgl_display = lv_display_get_default();
|
||||
tt_assert(lvgl_display != nullptr);
|
||||
auto* hal_display = (hal::Display*)lv_display_get_user_data(lvgl_display);
|
||||
tt_assert(hal_display != nullptr);
|
||||
if (hal_display->supportsBacklightDuty()) {
|
||||
int32_t backlight_duty = app::display::getBacklightDuty();
|
||||
hal_display->setBacklightDuty(backlight_duty);
|
||||
}
|
||||
|
||||
tt::service::loader::stopApp();
|
||||
startNextApp();
|
||||
if (hal::usb::isUsbBootMode()) {
|
||||
TT_LOG_I(TAG, "Rebooting into mass storage device mode");
|
||||
hal::usb::resetUsbBootMode();
|
||||
hal::usb::startMassStorageWithSdmmc();
|
||||
} else {
|
||||
TickType_t end_time = tt::kernel::getTicks();
|
||||
TickType_t ticks_passed = end_time - start_time;
|
||||
TickType_t minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS);
|
||||
if (minimum_ticks > ticks_passed) {
|
||||
kernel::delayTicks(minimum_ticks - ticks_passed);
|
||||
}
|
||||
|
||||
tt::service::loader::stopApp();
|
||||
startNextApp();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void startNextApp() {
|
||||
static void startNextApp() {
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_PANIC) {
|
||||
app::crashdiagnostics::start();
|
||||
return;
|
||||
}
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_PANIC) {
|
||||
app::crashdiagnostics::start();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
auto* config = tt::getConfiguration();
|
||||
if (config->autoStartAppId) {
|
||||
TT_LOG_I(TAG, "init auto-starting %s", config->autoStartAppId);
|
||||
tt::service::loader::startApp(config->autoStartAppId);
|
||||
} else {
|
||||
app::launcher::start();
|
||||
auto* config = tt::getConfiguration();
|
||||
if (config->autoStartAppId) {
|
||||
TT_LOG_I(TAG, "init auto-starting %s", config->autoStartAppId);
|
||||
tt::service::loader::startApp(config->autoStartAppId);
|
||||
} else {
|
||||
app::launcher::start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) {
|
||||
auto data = std::static_pointer_cast<Data>(app.getData());
|
||||
public:
|
||||
|
||||
auto* image = lv_image_create(parent);
|
||||
lv_obj_set_size(image, LV_PCT(100), LV_PCT(100));
|
||||
void onShow(TT_UNUSED AppContext& app, lv_obj_t* parent) override {
|
||||
auto* image = lv_image_create(parent);
|
||||
lv_obj_set_size(image, LV_PCT(100), LV_PCT(100));
|
||||
|
||||
auto paths = app.getPaths();
|
||||
const char* logo = hal::usb::isUsbBootMode() ? "logo_usb.png" : "logo.png";
|
||||
auto logo_path = paths->getSystemPathLvgl(logo);
|
||||
TT_LOG_I(TAG, "%s", logo_path.c_str());
|
||||
lv_image_set_src(image, logo_path.c_str());
|
||||
auto paths = app.getPaths();
|
||||
const char* logo = hal::usb::isUsbBootMode() ? "logo_usb.png" : "logo.png";
|
||||
auto logo_path = paths->getSystemPathLvgl(logo);
|
||||
TT_LOG_I(TAG, "%s", logo_path.c_str());
|
||||
lv_image_set_src(image, logo_path.c_str());
|
||||
|
||||
lvgl::obj_set_style_bg_blacken(parent);
|
||||
lvgl::obj_set_style_bg_blacken(parent);
|
||||
|
||||
data->thread.start();
|
||||
}
|
||||
// Just in case this app is somehow resumed
|
||||
if (thread.getState() == Thread::State::Stopped) {
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
static void onStart(AppContext& app) {
|
||||
auto data = std::make_shared<Data>();
|
||||
app.setData(data);
|
||||
}
|
||||
|
||||
static void onStop(AppContext& app) {
|
||||
auto data = std::static_pointer_cast<Data>(app.getData());
|
||||
data->thread.join();
|
||||
}
|
||||
void onStop(AppContext& app) override {
|
||||
thread.join();
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.id = "Boot",
|
||||
.name = "Boot",
|
||||
.type = TypeBoot,
|
||||
.onStart = onStart,
|
||||
.onStop = onStop,
|
||||
.onShow = onShow,
|
||||
.type = Type::Boot,
|
||||
.createApp = create<BootApp>
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user