2022-02-20 13:20:43 +01:00
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
|
#include "displayapp/screens/WatchFaceTerminal.h"
|
|
|
|
|
#include "displayapp/screens/BatteryIcon.h"
|
|
|
|
|
#include "displayapp/screens/NotificationIcon.h"
|
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
|
|
|
|
#include "components/battery/BatteryController.h"
|
|
|
|
|
#include "components/ble/BleController.h"
|
|
|
|
|
#include "components/ble/NotificationManager.h"
|
|
|
|
|
#include "components/heartrate/HeartRateController.h"
|
|
|
|
|
#include "components/motion/MotionController.h"
|
|
|
|
|
#include "components/settings/Settings.h"
|
|
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
// for the LV "recolor" feature within labels
|
|
|
|
|
#define R_LTGREY(str) "#aaaaaa " str "#"
|
|
|
|
|
#define R_LTPINK(str) "#ffaaaa " str "#"
|
|
|
|
|
|
|
|
|
|
// convert a row number (rows of text) to a y-coordinate
|
|
|
|
|
lv_coord_t y_ofs(int8_t row) {
|
|
|
|
|
return row * 22 + 11;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make a label representing a terminal output text
|
|
|
|
|
lv_obj_t* mkoutput(int8_t row) {
|
|
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, y_ofs(row));
|
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make a label representing a terminal prompt with command 'cmd'
|
|
|
|
|
lv_obj_t* mkprompt(int8_t row, const char *cmd) {
|
|
|
|
|
lv_obj_t* label = mkoutput(row);
|
|
|
|
|
lv_label_set_text_fmt(label, R_LTPINK("%s") R_LTGREY("@") R_LTPINK("watch") R_LTGREY(":~") " $ %s", Pinetime::Applications::OwnerTextShort, cmd);
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 22:36:38 +02:00
|
|
|
WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
|
2023-02-23 22:16:44 +02:00
|
|
|
const Controllers::Battery& batteryController,
|
2023-02-23 22:24:07 +02:00
|
|
|
const Controllers::Ble& bleController,
|
2022-09-22 13:43:00 +02:00
|
|
|
Controllers::NotificationManager& notificationManager,
|
2022-02-20 13:20:43 +01:00
|
|
|
Controllers::Settings& settingsController,
|
|
|
|
|
Controllers::HeartRateController& heartRateController,
|
|
|
|
|
Controllers::MotionController& motionController)
|
2023-02-22 22:18:15 +02:00
|
|
|
: currentDateTime {{}},
|
2022-02-20 13:20:43 +01:00
|
|
|
dateTimeController {dateTimeController},
|
|
|
|
|
batteryController {batteryController},
|
|
|
|
|
bleController {bleController},
|
2022-09-22 13:43:00 +02:00
|
|
|
notificationManager {notificationManager},
|
2022-02-20 13:20:43 +01:00
|
|
|
settingsController {settingsController},
|
|
|
|
|
heartRateController {heartRateController},
|
|
|
|
|
motionController {motionController} {
|
|
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
notificationIcon = mkoutput(-5);
|
|
|
|
|
|
|
|
|
|
label_prompt_1 = mkprompt(-4, "now");
|
2022-02-20 13:20:43 +01:00
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
label_time = mkoutput(-3);
|
2022-02-20 13:20:43 +01:00
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
label_date = mkoutput(-2);
|
2022-02-20 13:20:43 +01:00
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
batteryValue = mkoutput(-1);
|
2022-02-20 13:20:43 +01:00
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
stepValue = mkoutput(0);
|
2022-02-20 13:20:43 +01:00
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
heartbeatValue = mkoutput(1);
|
2022-02-20 13:20:43 +01:00
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
connectState = mkoutput(2);
|
2022-02-20 13:20:43 +01:00
|
|
|
|
2024-05-10 10:43:46 +01:00
|
|
|
label_prompt_2 = mkprompt(3, "_");
|
2022-02-20 13:20:43 +01:00
|
|
|
|
|
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WatchFaceTerminal::~WatchFaceTerminal() {
|
|
|
|
|
lv_task_del(taskRefresh);
|
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchFaceTerminal::Refresh() {
|
|
|
|
|
powerPresent = batteryController.IsPowerPresent();
|
|
|
|
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
2022-02-20 15:06:28 +02:00
|
|
|
if (batteryPercentRemaining.IsUpdated() || powerPresent.IsUpdated()) {
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_fmt(batteryValue, R_LTGREY("batt=")"#387b54 %d%%", batteryPercentRemaining.Get());
|
2022-02-20 15:06:28 +02:00
|
|
|
if (batteryController.IsPowerPresent()) {
|
|
|
|
|
lv_label_ins_text(batteryValue, LV_LABEL_POS_LAST, " Charging");
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bleState = bleController.IsConnected();
|
2022-02-20 15:40:49 +01:00
|
|
|
bleRadioEnabled = bleController.IsRadioEnabled();
|
|
|
|
|
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {
|
2022-05-09 17:16:08 +02:00
|
|
|
if (!bleRadioEnabled.Get()) {
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Disabled#");
|
2022-02-20 13:20:43 +01:00
|
|
|
} else {
|
2022-02-20 15:40:49 +01:00
|
|
|
if (bleState.Get()) {
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Connected#");
|
2022-02-20 15:40:49 +01:00
|
|
|
} else {
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Disconnected#");
|
2022-02-20 15:40:49 +01:00
|
|
|
}
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 13:43:00 +02:00
|
|
|
notificationState = notificationManager.AreNewNotificationsAvailable();
|
2022-02-20 13:20:43 +01:00
|
|
|
if (notificationState.IsUpdated()) {
|
|
|
|
|
if (notificationState.Get()) {
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_static(notificationIcon, "You have messages.");
|
2022-02-20 13:20:43 +01:00
|
|
|
} else {
|
2022-03-05 13:01:50 +01:00
|
|
|
lv_label_set_text_static(notificationIcon, "");
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 13:19:09 +02:00
|
|
|
currentDateTime = std::chrono::time_point_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime());
|
2022-02-20 13:20:43 +01:00
|
|
|
if (currentDateTime.IsUpdated()) {
|
2023-03-03 13:19:09 +02:00
|
|
|
uint8_t hour = dateTimeController.Hours();
|
|
|
|
|
uint8_t minute = dateTimeController.Minutes();
|
|
|
|
|
uint8_t second = dateTimeController.Seconds();
|
|
|
|
|
|
|
|
|
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
2024-05-10 09:15:46 +01:00
|
|
|
char ampmChar[3] = "am";
|
2023-03-03 13:19:09 +02:00
|
|
|
if (hour == 0) {
|
|
|
|
|
hour = 12;
|
|
|
|
|
} else if (hour == 12) {
|
2024-05-10 09:15:46 +01:00
|
|
|
ampmChar[0] = 'p';
|
2023-03-03 13:19:09 +02:00
|
|
|
} else if (hour > 12) {
|
|
|
|
|
hour = hour - 12;
|
2024-05-10 09:15:46 +01:00
|
|
|
ampmChar[0] = 'p';
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_fmt(label_time, R_LTGREY("time=")"#11cc55 %1d:%02d:%02d %s#", hour, minute, second, ampmChar);
|
2023-03-03 13:19:09 +02:00
|
|
|
} else {
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_fmt(label_time, R_LTGREY("time=")"#11cc55 %02d:%02d:%02d", hour, minute, second);
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-12 13:01:22 +01:00
|
|
|
currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
|
2023-03-03 13:19:09 +02:00
|
|
|
if (currentDate.IsUpdated()) {
|
|
|
|
|
uint16_t year = dateTimeController.Year();
|
|
|
|
|
Controllers::DateTime::Months month = dateTimeController.Month();
|
|
|
|
|
uint8_t day = dateTimeController.Day();
|
2024-05-10 10:43:46 +01:00
|
|
|
lv_label_set_text_fmt(label_date, R_LTGREY("date=")"#007fff %04d-%02d-%02d#", short(year), char(month), char(day));
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
heartbeat = heartRateController.HeartRate();
|
|
|
|
|
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
|
|
|
|
|
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
|
|
|
|
|
if (heartbeatRunning.Get()) {
|
2024-08-26 14:19:06 +01:00
|
|
|
auto val = heartbeat.Get();
|
|
|
|
|
if (val)
|
|
|
|
|
lv_label_set_text_fmt(heartbeatValue, R_LTGREY("puls=")"#ee3311 %d bpm#", val);
|
|
|
|
|
else
|
|
|
|
|
lv_label_set_text_static(heartbeatValue, R_LTGREY("puls=")"#ee3311 ...#");
|
2022-02-20 13:20:43 +01:00
|
|
|
} else {
|
2024-08-26 14:19:06 +01:00
|
|
|
lv_label_set_text_static(heartbeatValue, R_LTGREY("puls=---"));
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stepCount = motionController.NbSteps();
|
2023-04-05 21:46:15 +03:00
|
|
|
if (stepCount.IsUpdated()) {
|
2024-08-27 22:07:49 +01:00
|
|
|
if (stepCount.Get()) {
|
|
|
|
|
lv_label_set_text_fmt(stepValue, R_LTGREY("step=")"#ee3377 %lu steps#", stepCount.Get());
|
|
|
|
|
} else {
|
|
|
|
|
lv_label_set_text_static(stepValue, R_LTGREY("step=---"));
|
|
|
|
|
}
|
2022-02-20 13:20:43 +01:00
|
|
|
}
|
|
|
|
|
}
|