
A list of "user applications" is built at compile time. It contains all the info needed to create the application at runtime (ptr to a create() function) and to display the app in the application menu. All applications declare a TypeTrait with these information. When a new app must be loaded, DisplayApp first check if this app is a System app (in which case it creates it like it did before). If it's not a System app, it looks for the app in the list of User applications and creates it if it found it. Those changes allow to more easily add new app and to select which app must be built into the firmware. Switch to C++20 (and fix a few issues in SpiMaster.cpp and Watchdog.cpp.
109 lines
3.5 KiB
C++
109 lines
3.5 KiB
C++
#include "displayapp/screens/Tile.h"
|
|
#include "displayapp/screens/BatteryIcon.h"
|
|
#include "components/ble/BleController.h"
|
|
#include "displayapp/InfiniTimeTheme.h"
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
namespace {
|
|
void lv_update_task(struct _lv_task_t* task) {
|
|
auto* user_data = static_cast<Tile*>(task->user_data);
|
|
user_data->UpdateScreen();
|
|
}
|
|
|
|
void event_handler(lv_obj_t* obj, lv_event_t event) {
|
|
if (event != LV_EVENT_VALUE_CHANGED) {
|
|
return;
|
|
}
|
|
|
|
Tile* screen = static_cast<Tile*>(obj->user_data);
|
|
auto* eventDataPtr = (uint32_t*) lv_event_get_data();
|
|
uint32_t eventData = *eventDataPtr;
|
|
screen->OnValueChangedEvent(obj, eventData);
|
|
}
|
|
}
|
|
|
|
Tile::Tile(uint8_t screenID,
|
|
uint8_t numScreens,
|
|
DisplayApp* app,
|
|
Controllers::Settings& settingsController,
|
|
const Controllers::Battery& batteryController,
|
|
const Controllers::Ble& bleController,
|
|
Controllers::DateTime& dateTimeController,
|
|
std::array<Applications, 6>& applications)
|
|
: app {app}, dateTimeController {dateTimeController}, pageIndicator(screenID, numScreens), statusIcons(batteryController, bleController) {
|
|
|
|
settingsController.SetAppMenu(screenID);
|
|
|
|
statusIcons.Create();
|
|
lv_obj_align(statusIcons.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -8, 0);
|
|
|
|
// Time
|
|
label_time = lv_label_create(lv_scr_act(), nullptr);
|
|
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
|
|
lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
|
|
|
pageIndicator.Create();
|
|
|
|
uint8_t btIndex = 0;
|
|
for (uint8_t i = 0; i < 6; i++) {
|
|
if (i == 3) {
|
|
btnmMap[btIndex++] = "\n";
|
|
}
|
|
if (applications[i].application == Apps::None) {
|
|
btnmMap[btIndex] = " ";
|
|
} else {
|
|
btnmMap[btIndex] = applications[i].icon;
|
|
}
|
|
btIndex++;
|
|
apps[i] = applications[i].application;
|
|
}
|
|
btnmMap[btIndex] = "";
|
|
|
|
btnm1 = lv_btnmatrix_create(lv_scr_act(), nullptr);
|
|
lv_btnmatrix_set_map(btnm1, btnmMap);
|
|
lv_obj_set_size(btnm1, LV_HOR_RES - 16, LV_VER_RES - 60);
|
|
lv_obj_align(btnm1, nullptr, LV_ALIGN_CENTER, 0, 10);
|
|
|
|
lv_obj_set_style_local_radius(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, 20);
|
|
lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_OPA_50);
|
|
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_COLOR_AQUA);
|
|
lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, LV_OPA_50);
|
|
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, Colors::bgDark);
|
|
lv_obj_set_style_local_pad_all(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 0);
|
|
lv_obj_set_style_local_pad_inner(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 10);
|
|
|
|
for (uint8_t i = 0; i < 6; i++) {
|
|
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_CLICK_TRIG);
|
|
if (applications[i].application == Apps::None || !applications[i].enabled) {
|
|
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_DISABLED);
|
|
}
|
|
}
|
|
|
|
btnm1->user_data = this;
|
|
lv_obj_set_event_cb(btnm1, event_handler);
|
|
|
|
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);
|
|
|
|
UpdateScreen();
|
|
}
|
|
|
|
Tile::~Tile() {
|
|
lv_task_del(taskUpdate);
|
|
lv_obj_clean(lv_scr_act());
|
|
}
|
|
|
|
void Tile::UpdateScreen() {
|
|
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
|
statusIcons.Update();
|
|
}
|
|
|
|
void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) {
|
|
if (obj != btnm1) {
|
|
return;
|
|
}
|
|
|
|
app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
|
|
running = false;
|
|
}
|