1
0
Fork 0

Terminal: tweak text, colour, lower case; refactor source

This commit is contained in:
Julian Foad 2024-05-10 10:43:46 +01:00
parent 118d23cd4c
commit b572e2ec91

View file

@ -12,6 +12,30 @@
using namespace Pinetime::Applications::Screens;
// 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;
}
WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
@ -27,40 +51,24 @@ WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
settingsController {settingsController},
heartRateController {heartRateController},
motionController {motionController} {
batteryValue = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(batteryValue, true);
lv_obj_align(batteryValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
connectState = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(connectState, true);
lv_obj_align(connectState, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 40);
notificationIcon = mkoutput(-5);
notificationIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_LEFT_MID, 0, -100);
label_prompt_1 = mkprompt(-4, "now");
label_date = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(label_date, true);
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -40);
label_time = mkoutput(-3);
label_prompt_1 = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(label_prompt_1, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -80);
lv_label_set_text_fmt(label_prompt_1, "%s@watch:~ $ now", Pinetime::Applications::OwnerTextShort);
label_date = mkoutput(-2);
label_prompt_2 = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(label_prompt_2, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);
lv_label_set_text_fmt(label_prompt_2, "%s@watch:~ $", Pinetime::Applications::OwnerTextShort);
batteryValue = mkoutput(-1);
label_time = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(label_time, true);
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -60);
stepValue = mkoutput(0);
heartbeatValue = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(heartbeatValue, true);
lv_obj_align(heartbeatValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 20);
heartbeatValue = mkoutput(1);
stepValue = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(stepValue, true);
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0);
connectState = mkoutput(2);
label_prompt_2 = mkprompt(3, "_");
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
Refresh();
@ -75,7 +83,7 @@ void WatchFaceTerminal::Refresh() {
powerPresent = batteryController.IsPowerPresent();
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated() || powerPresent.IsUpdated()) {
lv_label_set_text_fmt(batteryValue, "[BATT]#387b54 %d%%", batteryPercentRemaining.Get());
lv_label_set_text_fmt(batteryValue, R_LTGREY("batt=")"#387b54 %d%%", batteryPercentRemaining.Get());
if (batteryController.IsPowerPresent()) {
lv_label_ins_text(batteryValue, LV_LABEL_POS_LAST, " Charging");
}
@ -85,12 +93,12 @@ void WatchFaceTerminal::Refresh() {
bleRadioEnabled = bleController.IsRadioEnabled();
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {
if (!bleRadioEnabled.Get()) {
lv_label_set_text_static(connectState, "[STAT]#0082fc Disabled#");
lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Disabled#");
} else {
if (bleState.Get()) {
lv_label_set_text_static(connectState, "[STAT]#0082fc Connected#");
lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Connected#");
} else {
lv_label_set_text_static(connectState, "[STAT]#0082fc Disconnected#");
lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Disconnected#");
}
}
}
@ -98,7 +106,7 @@ void WatchFaceTerminal::Refresh() {
notificationState = notificationManager.AreNewNotificationsAvailable();
if (notificationState.IsUpdated()) {
if (notificationState.Get()) {
lv_label_set_text_static(notificationIcon, "You have mail.");
lv_label_set_text_static(notificationIcon, "You have messages.");
} else {
lv_label_set_text_static(notificationIcon, "");
}
@ -120,9 +128,9 @@ void WatchFaceTerminal::Refresh() {
hour = hour - 12;
ampmChar[0] = 'p';
}
lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d %s#", hour, minute, second, ampmChar);
lv_label_set_text_fmt(label_time, R_LTGREY("time=")"#11cc55 %1d:%02d:%02d %s#", hour, minute, second, ampmChar);
} else {
lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d", hour, minute, second);
lv_label_set_text_fmt(label_time, R_LTGREY("time=")"#11cc55 %02d:%02d:%02d", hour, minute, second);
}
currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
@ -130,7 +138,7 @@ void WatchFaceTerminal::Refresh() {
uint16_t year = dateTimeController.Year();
Controllers::DateTime::Months month = dateTimeController.Month();
uint8_t day = dateTimeController.Day();
lv_label_set_text_fmt(label_date, "[DATE]#007fff %04d-%02d-%02d#", short(year), char(month), char(day));
lv_label_set_text_fmt(label_date, R_LTGREY("date=")"#007fff %04d-%02d-%02d#", short(year), char(month), char(day));
}
}
@ -138,14 +146,14 @@ void WatchFaceTerminal::Refresh() {
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
if (heartbeatRunning.Get()) {
lv_label_set_text_fmt(heartbeatValue, "[L_HR]#ee3311 %d bpm#", heartbeat.Get());
lv_label_set_text_fmt(heartbeatValue, R_LTGREY("puls=")"#ee3311 %d bpm#", heartbeat.Get());
} else {
lv_label_set_text_static(heartbeatValue, "[L_HR]#ee3311 ---#");
lv_label_set_text_static(heartbeatValue, R_LTGREY("puls=")"#ee3311 ---#");
}
}
stepCount = motionController.NbSteps();
if (stepCount.IsUpdated()) {
lv_label_set_text_fmt(stepValue, "[STEP]#ee3377 %lu steps#", stepCount.Get());
lv_label_set_text_fmt(stepValue, R_LTGREY("step=")"#ee3377 %lu steps#", stepCount.Get());
}
}