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
@@ -98,92 +98,92 @@ static void onOrientationSet(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void onShow(AppContext& app, lv_obj_t* parent) {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
class DisplayApp : public App {
|
||||
|
||||
lvgl::toolbar_create(parent, app);
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lv_obj_t* main_wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_flex_flow(main_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_width(main_wrapper, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(main_wrapper, 1);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
|
||||
lv_obj_t* wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_width(wrapper, LV_PCT(100));
|
||||
lv_obj_set_style_pad_all(wrapper, 8, 0);
|
||||
lv_obj_set_style_border_width(wrapper, 0, 0);
|
||||
lv_obj_t* main_wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_flex_flow(main_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_width(main_wrapper, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(main_wrapper, 1);
|
||||
|
||||
lv_obj_t* brightness_label = lv_label_create(wrapper);
|
||||
lv_label_set_text(brightness_label, "Brightness");
|
||||
lv_obj_t* wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_width(wrapper, LV_PCT(100));
|
||||
lv_obj_set_style_pad_all(wrapper, 8, 0);
|
||||
lv_obj_set_style_border_width(wrapper, 0, 0);
|
||||
|
||||
lv_obj_t* brightness_slider = lv_slider_create(wrapper);
|
||||
lv_obj_set_width(brightness_slider, LV_PCT(50));
|
||||
lv_obj_align(brightness_slider, LV_ALIGN_TOP_RIGHT, -8, 0);
|
||||
lv_slider_set_range(brightness_slider, 0, 255);
|
||||
lv_obj_add_event_cb(brightness_slider, onBacklightSliderEvent, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
lv_obj_t* brightness_label = lv_label_create(wrapper);
|
||||
lv_label_set_text(brightness_label, "Brightness");
|
||||
|
||||
lv_obj_t* gamma_label = lv_label_create(wrapper);
|
||||
lv_label_set_text(gamma_label, "Gamma");
|
||||
lv_obj_set_y(gamma_label, 40);
|
||||
lv_obj_t* brightness_slider = lv_slider_create(wrapper);
|
||||
lv_obj_set_width(brightness_slider, LV_PCT(50));
|
||||
lv_obj_align(brightness_slider, LV_ALIGN_TOP_RIGHT, -8, 0);
|
||||
lv_slider_set_range(brightness_slider, 0, 255);
|
||||
lv_obj_add_event_cb(brightness_slider, onBacklightSliderEvent, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
|
||||
lv_obj_t* gamma_slider = lv_slider_create(wrapper);
|
||||
lv_obj_set_width(gamma_slider, LV_PCT(50));
|
||||
lv_obj_align(gamma_slider, LV_ALIGN_TOP_RIGHT, -8, 40);
|
||||
lv_slider_set_range(gamma_slider, 0, getHalDisplay(parent)->getGammaCurveCount());
|
||||
lv_obj_add_event_cb(gamma_slider, onGammaSliderEvent, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
lv_obj_t* gamma_label = lv_label_create(wrapper);
|
||||
lv_label_set_text(gamma_label, "Gamma");
|
||||
lv_obj_set_y(gamma_label, 40);
|
||||
|
||||
auto* hal_display = getHalDisplay(parent);
|
||||
tt_assert(hal_display != nullptr);
|
||||
lv_obj_t* gamma_slider = lv_slider_create(wrapper);
|
||||
lv_obj_set_width(gamma_slider, LV_PCT(50));
|
||||
lv_obj_align(gamma_slider, LV_ALIGN_TOP_RIGHT, -8, 40);
|
||||
lv_slider_set_range(gamma_slider, 0, getHalDisplay(parent)->getGammaCurveCount());
|
||||
lv_obj_add_event_cb(gamma_slider, onGammaSliderEvent, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
|
||||
if (!hal_display->supportsBacklightDuty()) {
|
||||
lv_slider_set_value(brightness_slider, 255, LV_ANIM_OFF);
|
||||
lv_obj_add_state(brightness_slider, LV_STATE_DISABLED);
|
||||
} else {
|
||||
uint8_t value = getBacklightDuty();
|
||||
lv_slider_set_value(brightness_slider, value, LV_ANIM_OFF);
|
||||
auto* hal_display = getHalDisplay(parent);
|
||||
tt_assert(hal_display != nullptr);
|
||||
|
||||
if (!hal_display->supportsBacklightDuty()) {
|
||||
lv_slider_set_value(brightness_slider, 255, LV_ANIM_OFF);
|
||||
lv_obj_add_state(brightness_slider, LV_STATE_DISABLED);
|
||||
} else {
|
||||
uint8_t value = getBacklightDuty();
|
||||
lv_slider_set_value(brightness_slider, value, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
lv_slider_set_value(gamma_slider, 128, LV_ANIM_OFF);
|
||||
|
||||
lv_obj_t* orientation_label = lv_label_create(wrapper);
|
||||
lv_label_set_text(orientation_label, "Orientation");
|
||||
lv_obj_align(orientation_label, LV_ALIGN_TOP_LEFT, 0, 80);
|
||||
|
||||
auto lvgl_display = lv_obj_get_display(parent);
|
||||
auto horizontal_px = lv_display_get_horizontal_resolution(lvgl_display);
|
||||
auto vertical_px = lv_display_get_vertical_resolution(lvgl_display);
|
||||
bool is_landscape_display = horizontal_px > vertical_px;
|
||||
|
||||
lv_obj_t* orientation_dropdown = lv_dropdown_create(wrapper);
|
||||
if (is_landscape_display) {
|
||||
lv_dropdown_set_options(orientation_dropdown, "Landscape\nLandscape (flipped)\nPortrait Left\nPortrait Right");
|
||||
} else {
|
||||
lv_dropdown_set_options(orientation_dropdown, "Portrait\nPortrait (flipped)\nLandscape Left\nLandscape Right");
|
||||
}
|
||||
|
||||
lv_obj_align(orientation_dropdown, LV_ALIGN_TOP_RIGHT, 0, 72);
|
||||
lv_obj_add_event_cb(orientation_dropdown, onOrientationSet, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
uint32_t orientation_selected = dipslayOrientationToOrientationSetting(
|
||||
lv_display_get_rotation(lv_display_get_default())
|
||||
);
|
||||
lv_dropdown_set_selected(orientation_dropdown, orientation_selected);
|
||||
}
|
||||
|
||||
lv_slider_set_value(gamma_slider, 128, LV_ANIM_OFF);
|
||||
|
||||
lv_obj_t* orientation_label = lv_label_create(wrapper);
|
||||
lv_label_set_text(orientation_label, "Orientation");
|
||||
lv_obj_align(orientation_label, LV_ALIGN_TOP_LEFT, 0, 80);
|
||||
|
||||
auto lvgl_display = lv_obj_get_display(parent);
|
||||
auto horizontal_px = lv_display_get_horizontal_resolution(lvgl_display);
|
||||
auto vertical_px = lv_display_get_vertical_resolution(lvgl_display);
|
||||
bool is_landscape_display = horizontal_px > vertical_px;
|
||||
|
||||
lv_obj_t* orientation_dropdown = lv_dropdown_create(wrapper);
|
||||
if (is_landscape_display) {
|
||||
lv_dropdown_set_options(orientation_dropdown, "Landscape\nLandscape (flipped)\nPortrait Left\nPortrait Right");
|
||||
} else {
|
||||
lv_dropdown_set_options(orientation_dropdown, "Portrait\nPortrait (flipped)\nLandscape Left\nLandscape Right");
|
||||
void onHide(TT_UNUSED AppContext& app) override {
|
||||
if (backlight_duty_set) {
|
||||
setBacklightDuty(backlight_duty);
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_align(orientation_dropdown, LV_ALIGN_TOP_RIGHT, 0, 72);
|
||||
lv_obj_add_event_cb(orientation_dropdown, onOrientationSet, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
uint32_t orientation_selected = dipslayOrientationToOrientationSetting(
|
||||
lv_display_get_rotation(lv_display_get_default())
|
||||
);
|
||||
lv_dropdown_set_selected(orientation_dropdown, orientation_selected);
|
||||
}
|
||||
|
||||
static void onHide(TT_UNUSED AppContext& app) {
|
||||
if (backlight_duty_set) {
|
||||
setBacklightDuty(backlight_duty);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern const AppManifest manifest = {
|
||||
.id = "Display",
|
||||
.name = "Display",
|
||||
.icon = TT_ASSETS_APP_ICON_DISPLAY_SETTINGS,
|
||||
.type = TypeSettings,
|
||||
.onStart = nullptr,
|
||||
.onStop = nullptr,
|
||||
.onShow = onShow,
|
||||
.onHide = onHide
|
||||
.type = Type::Settings,
|
||||
.createApp = create<DisplayApp>
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user