2021-10-13 16:08:35 -04:00
|
|
|
#include "displayapp/screens/Tile.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
|
|
|
#include "displayapp/screens/BatteryIcon.h"
|
2020-02-16 12:32:36 -05:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
namespace {
|
2022-04-09 06:37:31 -04:00
|
|
|
void lv_update_task(struct _lv_task_t* task) {
|
2021-07-25 13:55:21 -04:00
|
|
|
auto* user_data = static_cast<Tile*>(task->user_data);
|
2021-04-03 22:08:51 -04:00
|
|
|
user_data->UpdateScreen();
|
|
|
|
}
|
|
|
|
|
2022-04-09 06:37:31 -04:00
|
|
|
void event_handler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
if (event != LV_EVENT_VALUE_CHANGED) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-25 13:55:21 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
Tile* screen = static_cast<Tile*>(obj->user_data);
|
2021-07-25 13:55:21 -04:00
|
|
|
auto* eventDataPtr = (uint32_t*) lv_event_get_data();
|
2021-04-03 22:08:51 -04:00
|
|
|
uint32_t eventData = *eventDataPtr;
|
2021-07-25 13:55:21 -04:00
|
|
|
screen->OnValueChangedEvent(obj, eventData);
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
2020-02-16 12:32:36 -05:00
|
|
|
}
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
Tile::Tile(uint8_t screenID,
|
|
|
|
uint8_t numScreens,
|
|
|
|
DisplayApp* app,
|
|
|
|
Controllers::Settings& settingsController,
|
|
|
|
Pinetime::Controllers::Battery& batteryController,
|
|
|
|
Controllers::DateTime& dateTimeController,
|
|
|
|
std::array<Applications, 6>& applications)
|
|
|
|
: Screen(app), batteryController {batteryController}, dateTimeController {dateTimeController} {
|
|
|
|
|
2021-02-24 14:40:24 -05:00
|
|
|
settingsController.SetAppMenu(screenID);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
|
|
|
// Time
|
2021-04-18 13:28:14 -04:00
|
|
|
label_time = lv_label_create(lv_scr_act(), nullptr);
|
2021-11-10 20:11:09 -05:00
|
|
|
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
2021-04-18 13:28:14 -04:00
|
|
|
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
|
|
|
// Battery
|
|
|
|
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, -8, 0);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
if (numScreens > 1) {
|
2021-06-13 05:47:12 -04:00
|
|
|
pageIndicatorBasePoints[0].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorBasePoints[0].y = 0;
|
|
|
|
pageIndicatorBasePoints[1].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorBasePoints[1].y = LV_VER_RES;
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
|
|
lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
|
|
|
|
lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints, 2);
|
|
|
|
|
2021-06-13 05:47:12 -04:00
|
|
|
const uint16_t indicatorSize = LV_VER_RES / numScreens;
|
|
|
|
const uint16_t indicatorPos = indicatorSize * screenID;
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-06-13 05:47:12 -04:00
|
|
|
pageIndicatorPoints[0].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorPoints[0].y = indicatorPos;
|
|
|
|
pageIndicatorPoints[1].x = LV_HOR_RES - 1;
|
|
|
|
pageIndicatorPoints[1].y = indicatorPos + indicatorSize;
|
2021-04-03 22:08:51 -04:00
|
|
|
|
|
|
|
pageIndicator = lv_line_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
|
2022-04-22 16:26:38 -04:00
|
|
|
lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_line_set_points(pageIndicator, pageIndicatorPoints, 2);
|
|
|
|
}
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
uint8_t btIndex = 0;
|
2021-04-18 13:28:14 -04:00
|
|
|
for (uint8_t i = 0; i < 6; i++) {
|
|
|
|
if (i == 3)
|
|
|
|
btnmMap[btIndex++] = "\n";
|
|
|
|
if (applications[i].application == Apps::None) {
|
2021-04-03 22:08:51 -04:00
|
|
|
btnmMap[btIndex] = " ";
|
|
|
|
} else {
|
|
|
|
btnmMap[btIndex] = applications[i].icon;
|
2020-08-14 03:46:37 -04:00
|
|
|
}
|
2021-04-03 22:08:51 -04:00
|
|
|
btIndex++;
|
|
|
|
apps[i] = applications[i].application;
|
2020-08-14 03:46:37 -04:00
|
|
|
}
|
2021-04-03 22:08:51 -04:00
|
|
|
btnmMap[btIndex] = "";
|
2020-02-16 12:32:36 -05:00
|
|
|
|
2021-01-28 12:13:28 -05:00
|
|
|
btnm1 = lv_btnmatrix_create(lv_scr_act(), nullptr);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_btnmatrix_set_map(btnm1, btnmMap);
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_set_size(btnm1, LV_HOR_RES - 16, LV_VER_RES - 60);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 10);
|
|
|
|
|
|
|
|
lv_obj_set_style_local_radius(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, 20);
|
2022-04-22 16:26:38 -04:00
|
|
|
lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_OPA_40);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DEFAULT, LV_COLOR_AQUA);
|
2022-04-22 16:26:38 -04:00
|
|
|
lv_obj_set_style_local_bg_opa(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, LV_OPA_40);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_obj_set_style_local_bg_color(btnm1, LV_BTNMATRIX_PART_BTN, LV_STATE_DISABLED, lv_color_hex(0x111111));
|
2021-06-13 05:47:12 -04:00
|
|
|
lv_obj_set_style_local_pad_all(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 0);
|
2021-07-29 14:49:06 -04:00
|
|
|
lv_obj_set_style_local_pad_inner(btnm1, LV_BTNMATRIX_PART_BG, LV_STATE_DEFAULT, 10);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
for (uint8_t i = 0; i < 6; i++) {
|
2021-07-16 04:55:29 -04:00
|
|
|
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_CLICK_TRIG);
|
2021-04-18 13:28:14 -04:00
|
|
|
if (applications[i].application == Apps::None) {
|
|
|
|
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_DISABLED);
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
|
|
|
}
|
2020-02-16 12:32:36 -05:00
|
|
|
|
|
|
|
btnm1->user_data = this;
|
|
|
|
lv_obj_set_event_cb(btnm1, event_handler);
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text_static(backgroundLabel, "");
|
|
|
|
|
2021-07-07 08:47:47 -04:00
|
|
|
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);
|
2020-02-16 12:32:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Tile::~Tile() {
|
2021-04-03 22:08:51 -04:00
|
|
|
lv_task_del(taskUpdate);
|
2020-02-16 12:32:36 -05:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
void Tile::UpdateScreen() {
|
2021-11-10 20:11:09 -05:00
|
|
|
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
2022-03-20 10:47:25 -04:00
|
|
|
lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
|
2021-04-03 22:08:51 -04:00
|
|
|
}
|
|
|
|
|
2021-07-25 13:55:21 -04:00
|
|
|
void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) {
|
|
|
|
if(obj != btnm1) return;
|
|
|
|
|
|
|
|
app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
|
|
|
|
running = false;
|
2020-02-16 12:32:36 -05:00
|
|
|
}
|