Redesign launcher and support SD backgrounds
This commit is contained in:
Executable
+85
@@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""Convert an image to an uncompressed LVGL RGB565 launcher background."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import shutil
|
||||||
|
import struct
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
LV_IMAGE_HEADER_MAGIC = 0x19
|
||||||
|
LV_COLOR_FORMAT_RGB565 = 0x12
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args() -> argparse.Namespace:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description=(
|
||||||
|
"Create an uncompressed LVGL .bin image for "
|
||||||
|
"/sdcard/tactility/launcher/background.bin"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
parser.add_argument("input", type=Path, help="Source image")
|
||||||
|
parser.add_argument("output", type=Path, help="Destination .bin file")
|
||||||
|
parser.add_argument("--width", type=int, required=True, help="Output width")
|
||||||
|
parser.add_argument("--height", type=int, required=True, help="Output height")
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
args = parse_args()
|
||||||
|
if args.width <= 0 or args.width > 65535 or args.height <= 0 or args.height > 65535:
|
||||||
|
raise SystemExit("width and height must be between 1 and 65535")
|
||||||
|
|
||||||
|
magick = shutil.which("magick")
|
||||||
|
if magick is None:
|
||||||
|
raise SystemExit("ImageMagick is required (the 'magick' command was not found)")
|
||||||
|
|
||||||
|
command = [
|
||||||
|
magick,
|
||||||
|
str(args.input),
|
||||||
|
"-resize",
|
||||||
|
f"{args.width}x{args.height}^",
|
||||||
|
"-gravity",
|
||||||
|
"center",
|
||||||
|
"-extent",
|
||||||
|
f"{args.width}x{args.height}",
|
||||||
|
"-depth",
|
||||||
|
"8",
|
||||||
|
"rgb:-",
|
||||||
|
]
|
||||||
|
rgb888 = subprocess.run(command, check=True, stdout=subprocess.PIPE).stdout
|
||||||
|
expected_size = args.width * args.height * 3
|
||||||
|
if len(rgb888) != expected_size:
|
||||||
|
raise SystemExit(f"unexpected ImageMagick output: {len(rgb888)} bytes, expected {expected_size}")
|
||||||
|
|
||||||
|
rgb565 = bytearray(args.width * args.height * 2)
|
||||||
|
for source_offset in range(0, len(rgb888), 3):
|
||||||
|
r, g, b = rgb888[source_offset : source_offset + 3]
|
||||||
|
pixel = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
|
||||||
|
destination_offset = (source_offset // 3) * 2
|
||||||
|
struct.pack_into("<H", rgb565, destination_offset, pixel)
|
||||||
|
|
||||||
|
stride = args.width * 2
|
||||||
|
header = struct.pack(
|
||||||
|
"<BBHHHHH",
|
||||||
|
LV_IMAGE_HEADER_MAGIC,
|
||||||
|
LV_COLOR_FORMAT_RGB565,
|
||||||
|
0,
|
||||||
|
args.width,
|
||||||
|
args.height,
|
||||||
|
stride,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
args.output.write_bytes(header + rgb565)
|
||||||
|
print(
|
||||||
|
f"Wrote {args.output} ({args.width}x{args.height}, "
|
||||||
|
f"{len(header) + len(rgb565)} bytes, uncompressed RGB565)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 298 KiB |
@@ -21,3 +21,7 @@ lvgl.colorDepth=16
|
|||||||
storage.userDataLocation=SD
|
storage.userDataLocation=SD
|
||||||
|
|
||||||
dependencies.useDeprecatedHal=false
|
dependencies.useDeprecatedHal=false
|
||||||
|
|
||||||
|
# Launcher clock and full-screen wallpaper
|
||||||
|
sdkconfig.CONFIG_LV_FONT_MONTSERRAT_48=y
|
||||||
|
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=1048576
|
||||||
|
|||||||
@@ -22,5 +22,7 @@ storage.userDataLocation=SD
|
|||||||
|
|
||||||
dependencies.useDeprecatedHal=false
|
dependencies.useDeprecatedHal=false
|
||||||
|
|
||||||
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=524288
|
# Launcher clock and full-screen wallpaper
|
||||||
|
sdkconfig.CONFIG_LV_FONT_MONTSERRAT_48=y
|
||||||
|
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=1048576
|
||||||
sdkconfig.CONFIG_LV_IMAGE_HEADER_CACHE_DEF_CNT=16
|
sdkconfig.CONFIG_LV_IMAGE_HEADER_CACHE_DEF_CNT=16
|
||||||
|
|||||||
@@ -1,75 +1,51 @@
|
|||||||
#include <Tactility/Tactility.h>
|
#include <Tactility/Tactility.h>
|
||||||
|
|
||||||
|
#include <Tactility/Paths.h>
|
||||||
#include <Tactility/app/AppContext.h>
|
#include <Tactility/app/AppContext.h>
|
||||||
#include <Tactility/app/AppPaths.h>
|
#include <Tactility/app/AppPaths.h>
|
||||||
#include <Tactility/app/AppRegistration.h>
|
#include <Tactility/app/AppRegistration.h>
|
||||||
#include <Tactility/app/setup/Setup.h>
|
#include <Tactility/app/setup/Setup.h>
|
||||||
|
#include <Tactility/file/File.h>
|
||||||
|
#include <Tactility/lvgl/Lvgl.h>
|
||||||
#include <Tactility/service/loader/Loader.h>
|
#include <Tactility/service/loader/Loader.h>
|
||||||
|
#include <Tactility/service/wifi/Wifi.h>
|
||||||
#include <Tactility/settings/BootSettings.h>
|
#include <Tactility/settings/BootSettings.h>
|
||||||
|
#include <Tactility/settings/Time.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <ctime>
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <tactility/device.h>
|
#include <tactility/device.h>
|
||||||
#include <tactility/drivers/power_supply.h>
|
#include <tactility/drivers/power_supply.h>
|
||||||
#include <tactility/log.h>
|
#include <tactility/log.h>
|
||||||
#include <tactility/lvgl_fonts.h>
|
#include <tactility/lvgl_fonts.h>
|
||||||
#include <tactility/lvgl_icon_launcher.h>
|
#include <tactility/lvgl_icon_launcher.h>
|
||||||
|
#include <tactility/lvgl_icon_statusbar.h>
|
||||||
#include <tactility/lvgl_module.h>
|
#include <tactility/lvgl_module.h>
|
||||||
|
|
||||||
namespace tt::app::launcher {
|
namespace tt::app::launcher {
|
||||||
|
|
||||||
constexpr auto* TAG = "Launcher";
|
constexpr auto* TAG = "Launcher";
|
||||||
|
constexpr auto* BACKGROUND_ASSET = "color-field.png";
|
||||||
static uint32_t getButtonPadding(UiDensity density, uint32_t buttonSize) {
|
constexpr auto* CUSTOM_BACKGROUND_PATH = "tactility/launcher/background.bin";
|
||||||
if (density == LVGL_UI_DENSITY_COMPACT) {
|
constexpr lv_color_t TEXT_COLOR = LV_COLOR_MAKE(0xF8, 0xF5, 0xF2);
|
||||||
return 0;
|
constexpr lv_color_t MUTED_TEXT_COLOR = LV_COLOR_MAKE(0xDF, 0xD6, 0xD3);
|
||||||
} else {
|
constexpr lv_color_t ACCENT_COLOR = LV_COLOR_MAKE(0xEC, 0x75, 0x69);
|
||||||
return buttonSize / 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t computeButtonMargin(int32_t available_span, int32_t total_button_size) {
|
|
||||||
const int32_t usable = std::max<int32_t>(0, available_span - (3 * total_button_size));
|
|
||||||
return std::min<int32_t>(usable / 16, total_button_size / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
class LauncherApp final : public App {
|
class LauncherApp final : public App {
|
||||||
|
lv_obj_t* timeLabel = nullptr;
|
||||||
|
lv_obj_t* dateLabel = nullptr;
|
||||||
|
lv_obj_t* dataLabel = nullptr;
|
||||||
|
lv_obj_t* statusLabel = nullptr;
|
||||||
|
lv_timer_t* updateTimer = nullptr;
|
||||||
|
|
||||||
static lv_obj_t* createAppButton(lv_obj_t* parent, UiDensity uiDensity, const char* imageFile, const char* appId, int32_t itemMargin, bool isLandscape) {
|
static void onAppPressed(lv_event_t* event) {
|
||||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
const auto* app_id = static_cast<const char*>(lv_event_get_user_data(event));
|
||||||
const auto button_padding = getButtonPadding(uiDensity, button_size);
|
start(app_id);
|
||||||
auto* apps_button = lv_button_create(parent);
|
|
||||||
|
|
||||||
lv_obj_set_style_pad_all(apps_button, static_cast<int32_t>(button_padding), LV_STATE_DEFAULT);
|
|
||||||
if (isLandscape) {
|
|
||||||
lv_obj_set_style_margin_hor(apps_button, itemMargin, LV_STATE_DEFAULT);
|
|
||||||
} else {
|
|
||||||
lv_obj_set_style_margin_ver(apps_button, itemMargin, LV_STATE_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_set_style_shadow_width(apps_button, 0, LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_bg_opa(apps_button, 0, LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
// create the image first
|
|
||||||
auto* button_image = lv_image_create(apps_button);
|
|
||||||
lv_obj_set_style_text_font(button_image, lvgl_get_launcher_icon_font(), LV_STATE_DEFAULT);
|
|
||||||
lv_image_set_src(button_image, imageFile);
|
|
||||||
lv_obj_set_style_text_color(button_image, lv_theme_get_color_primary(button_image), LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_image_recolor(button_image, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_image_recolor_opa(button_image, LV_OPA_COVER, LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
// Ensure it's square (Material Symbols are slightly wider than tall)
|
|
||||||
lv_obj_set_size(button_image, button_size, button_size);
|
|
||||||
|
|
||||||
lv_obj_add_event_cb(apps_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)appId);
|
|
||||||
|
|
||||||
return apps_button;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onAppPressed(lv_event_t* e) {
|
|
||||||
auto* appId = static_cast<const char*>(lv_event_get_user_data(e));
|
|
||||||
start(appId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool shouldShowPowerButton() {
|
static bool shouldShowPowerButton() {
|
||||||
@@ -77,139 +53,284 @@ class LauncherApp final : public App {
|
|||||||
device_for_each_of_type(&POWER_SUPPLY_TYPE, &show_power_button, [](Device* device, void* context) {
|
device_for_each_of_type(&POWER_SUPPLY_TYPE, &show_power_button, [](Device* device, void* context) {
|
||||||
if (device_is_ready(device) && power_supply_supports_power_off(device)) {
|
if (device_is_ready(device) && power_supply_supports_power_off(device)) {
|
||||||
*static_cast<bool*>(context) = true;
|
*static_cast<bool*>(context) = true;
|
||||||
return false; // stop iterating
|
return false;
|
||||||
} else {
|
|
||||||
return true; // continue iterating
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
return show_power_button;
|
return show_power_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The screen object outlives the launcher's views (it's recreated by GuiService::redraw()
|
static int getBatteryPercentage() {
|
||||||
// via lv_obj_clean() on every app switch), so the LV_EVENT_SIZE_CHANGED callback registered
|
Device* power = nullptr;
|
||||||
// on it must be removed once buttons_wrapper is destroyed, to avoid a dangling user-data
|
device_for_each_of_type(&POWER_SUPPLY_TYPE, &power, [](Device* device, void* context) {
|
||||||
// pointer on the next rotation while a different app is visible.
|
if (device_is_ready(device) && power_supply_supports_property(device, POWER_SUPPLY_PROP_CAPACITY)) {
|
||||||
static void onButtonsWrapperDeleted(lv_event_t* e) {
|
*static_cast<Device**>(context) = device;
|
||||||
auto* buttons_wrapper = lv_event_get_target_obj(e);
|
return false;
|
||||||
auto* screen = lv_obj_get_screen(buttons_wrapper);
|
}
|
||||||
lv_obj_remove_event_cb_with_user_data(screen, onButtonsWrapperResized, buttons_wrapper);
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (power == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
PowerSupplyPropertyValue charge_level;
|
||||||
|
if (power_supply_get_property(power, POWER_SUPPLY_PROP_CAPACITY, &charge_level) != ERROR_NONE) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return std::clamp(charge_level.int_value, 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-applies the flex direction and per-button margins when the display orientation
|
static const char* getWifiStatusIcon(service::wifi::RadioState state) {
|
||||||
// changes while the launcher is the visible app (these are decided once at onShow()
|
using enum service::wifi::RadioState;
|
||||||
// based on the resolution at that time, so a later rotation needs this to catch up).
|
switch (state) {
|
||||||
static void onButtonsWrapperResized(lv_event_t* e) {
|
case ConnectionActive:
|
||||||
auto* buttons_wrapper = static_cast<lv_obj_t*>(lv_event_get_user_data(e));
|
return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_4_BAR;
|
||||||
const auto* display = lv_obj_get_display(buttons_wrapper);
|
case Off:
|
||||||
|
case OffPending:
|
||||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_OFF;
|
||||||
const auto button_padding = getButtonPadding(lvgl_get_ui_density(), button_size);
|
default:
|
||||||
const auto total_button_size = button_size + (button_padding * 2);
|
return LVGL_ICON_STATUSBAR_SIGNAL_WIFI_0_BAR;
|
||||||
|
|
||||||
const auto horizontal_px = lv_display_get_horizontal_resolution(display);
|
|
||||||
const auto vertical_px = lv_display_get_vertical_resolution(display);
|
|
||||||
const bool is_landscape_display = horizontal_px >= vertical_px;
|
|
||||||
const auto current_flow = lv_obj_get_style_flex_flow(buttons_wrapper, LV_PART_MAIN);
|
|
||||||
const bool was_landscape = current_flow == LV_FLEX_FLOW_ROW;
|
|
||||||
if (is_landscape_display == was_landscape) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lv_obj_set_flex_flow(buttons_wrapper, is_landscape_display ? LV_FLEX_FLOW_ROW : LV_FLEX_FLOW_COLUMN);
|
static const char* getBatteryStatusIcon(int percentage) {
|
||||||
|
if (percentage < 0) {
|
||||||
const int32_t margin = is_landscape_display
|
return "";
|
||||||
? computeButtonMargin(horizontal_px, total_button_size)
|
} else if (percentage >= 95) {
|
||||||
: computeButtonMargin(vertical_px, total_button_size);
|
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_FULL;
|
||||||
|
} else if (percentage >= 64) {
|
||||||
const uint32_t child_count = lv_obj_get_child_count(buttons_wrapper);
|
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_5;
|
||||||
for (uint32_t i = 0; i < child_count; i++) {
|
} else if (percentage >= 32) {
|
||||||
auto* button = lv_obj_get_child(buttons_wrapper, i);
|
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_3;
|
||||||
lv_obj_set_style_margin_hor(button, is_landscape_display ? margin : 0, LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_margin_ver(button, is_landscape_display ? 0 : margin, LV_STATE_DEFAULT);
|
|
||||||
}
|
}
|
||||||
|
return LVGL_ICON_STATUSBAR_BATTERY_ANDROID_FRAME_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static lv_obj_t* createAppButton(
|
||||||
|
lv_obj_t* parent,
|
||||||
|
const char* icon,
|
||||||
|
const char* appId,
|
||||||
|
bool emphasized
|
||||||
|
) {
|
||||||
|
auto* button = lv_button_create(parent);
|
||||||
|
lv_obj_set_size(button, 52, 52);
|
||||||
|
lv_obj_set_style_radius(button, 15, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_shadow_width(button, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_border_width(button, emphasized ? 2 : 1, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_border_color(button, emphasized ? ACCENT_COLOR : lv_color_hex(0x746568), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_border_opa(button, emphasized ? LV_OPA_COVER : LV_OPA_60, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_color(button, lv_color_hex(0x211B20), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_opa(button, emphasized ? LV_OPA_80 : LV_OPA_70, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_color(button, lv_color_hex(0x392C32), LV_STATE_PRESSED);
|
||||||
|
lv_obj_set_style_transform_scale(button, 238, LV_STATE_PRESSED);
|
||||||
|
lv_obj_set_style_outline_color(button, ACCENT_COLOR, LV_STATE_FOCUSED);
|
||||||
|
lv_obj_set_style_outline_width(button, 2, LV_STATE_FOCUSED);
|
||||||
|
lv_obj_set_style_outline_pad(button, 2, LV_STATE_FOCUSED);
|
||||||
|
|
||||||
|
auto* image = lv_image_create(button);
|
||||||
|
lv_obj_set_size(image, 36, 36);
|
||||||
|
lv_obj_center(image);
|
||||||
|
lv_obj_set_style_text_font(image, lvgl_get_launcher_icon_font(), LV_STATE_DEFAULT);
|
||||||
|
lv_image_set_src(image, icon);
|
||||||
|
lv_obj_set_style_image_recolor(image, TEXT_COLOR, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_image_recolor_opa(image, LV_OPA_COVER, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
lv_obj_add_event_cb(button, onAppPressed, LV_EVENT_SHORT_CLICKED, const_cast<char*>(appId));
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateInformation() {
|
||||||
|
const std::time_t now = std::time(nullptr);
|
||||||
|
std::tm local_time {};
|
||||||
|
localtime_r(&now, &local_time);
|
||||||
|
|
||||||
|
char time_buffer[12];
|
||||||
|
char date_buffer[40];
|
||||||
|
if (local_time.tm_year >= 125) {
|
||||||
|
if (settings::isTimeFormat24Hour()) {
|
||||||
|
std::strftime(time_buffer, sizeof(time_buffer), "%H:%M", &local_time);
|
||||||
|
} else {
|
||||||
|
std::strftime(time_buffer, sizeof(time_buffer), "%I:%M", &local_time);
|
||||||
|
if (time_buffer[0] == '0') {
|
||||||
|
std::memmove(time_buffer, time_buffer + 1, std::strlen(time_buffer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::strftime(date_buffer, sizeof(date_buffer), "%A, %B %e", &local_time);
|
||||||
|
} else {
|
||||||
|
std::strcpy(time_buffer, "--:--");
|
||||||
|
std::strcpy(date_buffer, "Set date and time");
|
||||||
|
}
|
||||||
|
lv_label_set_text(timeLabel, time_buffer);
|
||||||
|
lv_label_set_text(dateLabel, date_buffer);
|
||||||
|
|
||||||
|
const auto wifi_state = service::wifi::getRadioState();
|
||||||
|
const bool wifi_connected = wifi_state == service::wifi::RadioState::ConnectionActive;
|
||||||
|
std::string sd_card_path;
|
||||||
|
const bool sd_ready = findFirstMountedSdCardPath(sd_card_path);
|
||||||
|
const int battery_percentage = getBatteryPercentage();
|
||||||
|
|
||||||
|
char data_buffer[80];
|
||||||
|
if (battery_percentage >= 0) {
|
||||||
|
std::snprintf(
|
||||||
|
data_buffer,
|
||||||
|
sizeof(data_buffer),
|
||||||
|
"%s • %s • %d%%",
|
||||||
|
wifi_connected ? "Wi-Fi connected" : "Wi-Fi offline",
|
||||||
|
sd_ready ? "SD ready" : "No SD",
|
||||||
|
battery_percentage
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
std::snprintf(
|
||||||
|
data_buffer,
|
||||||
|
sizeof(data_buffer),
|
||||||
|
"%s • %s",
|
||||||
|
wifi_connected ? "Wi-Fi connected" : "Wi-Fi offline",
|
||||||
|
sd_ready ? "SD ready" : "No SD"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
lv_label_set_text(dataLabel, data_buffer);
|
||||||
|
|
||||||
|
char status_buffer[24];
|
||||||
|
std::snprintf(
|
||||||
|
status_buffer,
|
||||||
|
sizeof(status_buffer),
|
||||||
|
"%s%s",
|
||||||
|
getWifiStatusIcon(wifi_state),
|
||||||
|
getBatteryStatusIcon(battery_percentage)
|
||||||
|
);
|
||||||
|
lv_label_set_text(statusLabel, status_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onUpdateTimer(lv_timer_t* timer) {
|
||||||
|
static_cast<LauncherApp*>(lv_timer_get_user_data(timer))->updateInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void onCreate(AppContext& app) override {
|
void onCreate(AppContext& app) override {
|
||||||
settings::BootSettings boot_properties;
|
settings::BootSettings boot_properties;
|
||||||
if (
|
if (
|
||||||
// Auto-start due to built-in requirement
|
std::strcmp(CONFIG_TT_AUTO_START_APP_ID, "") != 0 &&
|
||||||
strcmp(CONFIG_TT_AUTO_START_APP_ID, "") != 0 &&
|
|
||||||
findAppManifestById(CONFIG_TT_AUTO_START_APP_ID) != nullptr
|
findAppManifestById(CONFIG_TT_AUTO_START_APP_ID) != nullptr
|
||||||
) {
|
) {
|
||||||
LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID);
|
LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID);
|
||||||
start(CONFIG_TT_AUTO_START_APP_ID);
|
start(CONFIG_TT_AUTO_START_APP_ID);
|
||||||
} else if (
|
} else if (
|
||||||
// Auto-start due to user configuration
|
|
||||||
settings::loadBootSettings(boot_properties) &&
|
settings::loadBootSettings(boot_properties) &&
|
||||||
!boot_properties.autoStartAppId.empty() &&
|
!boot_properties.autoStartAppId.empty() &&
|
||||||
findAppManifestById(boot_properties.autoStartAppId) != nullptr
|
findAppManifestById(boot_properties.autoStartAppId) != nullptr
|
||||||
) {
|
) {
|
||||||
LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
|
LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
|
||||||
start(boot_properties.autoStartAppId);
|
start(boot_properties.autoStartAppId);
|
||||||
} else {
|
} else if (!setup::isCompleted()) {
|
||||||
// No auto-start, consider running system setup
|
setup::start();
|
||||||
if (!setup::isCompleted()) {
|
|
||||||
setup::start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||||
auto* buttons_wrapper = lv_obj_create(parent);
|
lv_obj_set_style_bg_color(parent, lv_color_hex(0x211A20), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_opa(parent, LV_OPA_COVER, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_pad_all(parent, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
auto ui_density = lvgl_get_ui_density();
|
auto background_path = lvgl::PATH_PREFIX + app.getPaths()->getAssetsPath(BACKGROUND_ASSET);
|
||||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
std::string sd_card_path;
|
||||||
const auto button_padding = getButtonPadding(ui_density, button_size);
|
if (findFirstMountedSdCardPath(sd_card_path)) {
|
||||||
const auto total_button_size = button_size + (button_padding * 2);
|
const auto custom_background_path = file::getChildPath(sd_card_path, CUSTOM_BACKGROUND_PATH);
|
||||||
|
if (file::isFile(custom_background_path)) {
|
||||||
lv_obj_align(buttons_wrapper, LV_ALIGN_CENTER, 0, 0);
|
const auto lvgl_custom_background_path = lvgl::PATH_PREFIX + custom_background_path;
|
||||||
lv_obj_set_size(buttons_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
lv_image_header_t header {};
|
||||||
lv_obj_set_style_border_width(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
if (lv_image_decoder_get_info(lvgl_custom_background_path.c_str(), &header) == LV_RESULT_OK) {
|
||||||
lv_obj_set_flex_grow(buttons_wrapper, 1);
|
background_path = lvgl_custom_background_path;
|
||||||
|
LOG_I(
|
||||||
// Fix for button selection
|
TAG,
|
||||||
lv_obj_set_style_pad_all(buttons_wrapper, 6, LV_STATE_DEFAULT);
|
"Using SD background %s (%ux%u, format 0x%02x)",
|
||||||
|
custom_background_path.c_str(),
|
||||||
const auto* display = lv_obj_get_display(parent);
|
header.w,
|
||||||
const auto horizontal_px = lv_display_get_horizontal_resolution(display);
|
header.h,
|
||||||
const auto vertical_px = lv_display_get_vertical_resolution(display);
|
header.cf
|
||||||
const bool is_landscape_display = horizontal_px >= vertical_px;
|
);
|
||||||
if (is_landscape_display) {
|
} else {
|
||||||
lv_obj_set_flex_flow(buttons_wrapper, LV_FLEX_FLOW_ROW);
|
LOG_W(TAG, "Ignoring invalid SD background %s", custom_background_path.c_str());
|
||||||
} else {
|
}
|
||||||
lv_obj_set_flex_flow(buttons_wrapper, LV_FLEX_FLOW_COLUMN);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int32_t margin = is_landscape_display
|
auto* background = lv_image_create(parent);
|
||||||
? computeButtonMargin(lv_display_get_horizontal_resolution(display), total_button_size)
|
lv_image_set_src(background, background_path.c_str());
|
||||||
: computeButtonMargin(lv_display_get_vertical_resolution(display), total_button_size);
|
lv_obj_align(background, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
lv_obj_add_flag(background, LV_OBJ_FLAG_IGNORE_LAYOUT);
|
||||||
|
|
||||||
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_APPS, "AppList", margin, is_landscape_display);
|
timeLabel = lv_label_create(parent);
|
||||||
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_FOLDER, "Files", margin, is_landscape_display);
|
lv_label_set_text(timeLabel, "--:--");
|
||||||
createAppButton(buttons_wrapper, ui_density, LVGL_ICON_LAUNCHER_SETTINGS, "Settings", margin, is_landscape_display);
|
lv_obj_set_style_text_color(timeLabel, TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
#if LV_FONT_MONTSERRAT_48
|
||||||
|
lv_obj_set_style_text_font(timeLabel, &lv_font_montserrat_48, LV_PART_MAIN);
|
||||||
|
#else
|
||||||
|
lv_obj_set_style_text_font(timeLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN);
|
||||||
|
#endif
|
||||||
|
lv_obj_align(timeLabel, LV_ALIGN_TOP_LEFT, 18, 58);
|
||||||
|
|
||||||
// The launcher's container is several levels below the screen, and LVGL only sends
|
dateLabel = lv_label_create(parent);
|
||||||
// LV_EVENT_SIZE_CHANGED to the screen object itself on a resolution change - so the
|
lv_obj_set_style_text_font(dateLabel, lvgl_get_text_font(FONT_SIZE_LARGE), LV_PART_MAIN);
|
||||||
// handler is attached there, with buttons_wrapper passed through as user data.
|
lv_obj_set_style_text_color(dateLabel, TEXT_COLOR, LV_PART_MAIN);
|
||||||
lv_obj_add_event_cb(lv_obj_get_screen(parent), onButtonsWrapperResized, LV_EVENT_SIZE_CHANGED, buttons_wrapper);
|
lv_obj_align(dateLabel, LV_ALIGN_TOP_LEFT, 20, 118);
|
||||||
lv_obj_add_event_cb(buttons_wrapper, onButtonsWrapperDeleted, LV_EVENT_DELETE, nullptr);
|
|
||||||
|
dataLabel = lv_label_create(parent);
|
||||||
|
lv_obj_set_width(dataLabel, 225);
|
||||||
|
lv_label_set_long_mode(dataLabel, LV_LABEL_LONG_MODE_WRAP);
|
||||||
|
lv_obj_set_style_text_font(dataLabel, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_text_color(dataLabel, MUTED_TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
lv_obj_align(dataLabel, LV_ALIGN_TOP_LEFT, 20, 148);
|
||||||
|
|
||||||
|
statusLabel = lv_label_create(parent);
|
||||||
|
lv_obj_set_style_text_font(statusLabel, lvgl_get_statusbar_icon_font(), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_text_color(statusLabel, TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
lv_obj_align(statusLabel, LV_ALIGN_TOP_RIGHT, -15, 8);
|
||||||
|
|
||||||
|
auto* buttonRail = lv_obj_create(parent);
|
||||||
|
lv_obj_set_size(buttonRail, 60, 184);
|
||||||
|
lv_obj_align(buttonRail, LV_ALIGN_RIGHT_MID, -7, 8);
|
||||||
|
lv_obj_set_flex_flow(buttonRail, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_flex_align(buttonRail, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
|
lv_obj_set_style_pad_all(buttonRail, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_border_width(buttonRail, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_opa(buttonRail, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||||
|
lv_obj_clear_flag(buttonRail, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
createAppButton(buttonRail, LVGL_ICON_LAUNCHER_APPS, "AppList", true);
|
||||||
|
createAppButton(buttonRail, LVGL_ICON_LAUNCHER_FOLDER, "Files", false);
|
||||||
|
createAppButton(buttonRail, LVGL_ICON_LAUNCHER_SETTINGS, "Settings", false);
|
||||||
|
|
||||||
// Some devices (e.g. T-Lora Pager) have no other way to power off, so the
|
|
||||||
// button stays in the launcher; the confirmation flow lives in the PowerOff app.
|
|
||||||
if (shouldShowPowerButton()) {
|
if (shouldShowPowerButton()) {
|
||||||
auto* power_button = lv_button_create(parent);
|
auto* power_button = lv_button_create(parent);
|
||||||
lv_obj_set_style_pad_all(power_button, 8, 0);
|
lv_obj_set_size(power_button, 36, 36);
|
||||||
lv_obj_align(power_button, LV_ALIGN_BOTTOM_MID, 0, -10);
|
lv_obj_align(power_button, LV_ALIGN_BOTTOM_LEFT, 16, -12);
|
||||||
lv_obj_add_event_cb(power_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)"PowerOff");
|
lv_obj_set_style_radius(power_button, LV_RADIUS_CIRCLE, LV_PART_MAIN);
|
||||||
lv_obj_set_style_shadow_width(power_button, 0, LV_STATE_DEFAULT);
|
lv_obj_set_style_shadow_width(power_button, 0, LV_PART_MAIN);
|
||||||
lv_obj_set_style_bg_opa(power_button, 0, LV_PART_MAIN);
|
lv_obj_set_style_bg_color(power_button, lv_color_hex(0x211B20), LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_opa(power_button, LV_OPA_70, LV_PART_MAIN);
|
||||||
|
lv_obj_add_event_cb(power_button, onAppPressed, LV_EVENT_SHORT_CLICKED, const_cast<char*>("PowerOff"));
|
||||||
|
|
||||||
auto* power_label = lv_label_create(power_button);
|
auto* power_label = lv_label_create(power_button);
|
||||||
lv_label_set_text(power_label, LV_SYMBOL_POWER);
|
lv_label_set_text(power_label, LV_SYMBOL_POWER);
|
||||||
lv_obj_set_style_text_color(power_label, lv_theme_get_color_primary(parent), LV_STATE_DEFAULT);
|
lv_obj_set_style_text_color(power_label, TEXT_COLOR, LV_PART_MAIN);
|
||||||
|
lv_obj_center(power_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateInformation();
|
||||||
|
updateTimer = lv_timer_create(onUpdateTimer, 1000, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onHide(AppContext& app) override {
|
||||||
|
if (updateTimer != nullptr) {
|
||||||
|
lv_timer_delete(updateTimer);
|
||||||
|
updateTimer = nullptr;
|
||||||
|
}
|
||||||
|
timeLabel = nullptr;
|
||||||
|
dateLabel = nullptr;
|
||||||
|
dataLabel = nullptr;
|
||||||
|
statusLabel = nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -217,7 +338,7 @@ extern const AppManifest manifest = {
|
|||||||
.appId = "Launcher",
|
.appId = "Launcher",
|
||||||
.appName = "Launcher",
|
.appName = "Launcher",
|
||||||
.appCategory = Category::System,
|
.appCategory = Category::System,
|
||||||
.appFlags = AppManifest::Flags::Hidden,
|
.appFlags = AppManifest::Flags::Hidden | AppManifest::Flags::HideStatusBar,
|
||||||
.createApp = create<LauncherApp>
|
.createApp = create<LauncherApp>
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -225,4 +346,4 @@ LaunchId start() {
|
|||||||
return app::start(manifest.appId);
|
return app::start(manifest.appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace tt::app::launcher
|
||||||
|
|||||||
@@ -3,4 +3,4 @@
|
|||||||
nvs, data, nvs, 0x9000, 0x6000,
|
nvs, data, nvs, 0x9000, 0x6000,
|
||||||
phy_init, data, phy, 0xf000, 0x1000,
|
phy_init, data, phy, 0xf000, 0x1000,
|
||||||
factory, app, factory, 0x10000, 4M,
|
factory, app, factory, 0x10000, 4M,
|
||||||
system, data, fat, , 100k,
|
system, data, fat, , 512k,
|
||||||
|
|||||||
|
Reference in New Issue
Block a user