#include #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; // 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, Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, Controllers::MotionController& motionController) : currentDateTime {{}}, dateTimeController {dateTimeController}, batteryController {batteryController}, bleController {bleController}, notificationManager {notificationManager}, settingsController {settingsController}, heartRateController {heartRateController}, motionController {motionController} { notificationIcon = mkoutput(-5); label_prompt_1 = mkprompt(-4, "now"); label_time = mkoutput(-3); label_date = mkoutput(-2); batteryValue = mkoutput(-1); stepValue = mkoutput(0); heartbeatValue = mkoutput(1); connectState = mkoutput(2); label_prompt_2 = mkprompt(3, "_"); 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(); if (batteryPercentRemaining.IsUpdated() || powerPresent.IsUpdated()) { 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"); } } bleState = bleController.IsConnected(); bleRadioEnabled = bleController.IsRadioEnabled(); if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) { if (!bleRadioEnabled.Get()) { lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Disabled#"); } else { if (bleState.Get()) { lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Connected#"); } else { lv_label_set_text_static(connectState, R_LTGREY("stat=")"#0082fc Disconnected#"); } } } notificationState = notificationManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { if (notificationState.Get()) { lv_label_set_text_static(notificationIcon, "You have messages."); } else { lv_label_set_text_static(notificationIcon, ""); } } currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); if (currentDateTime.IsUpdated()) { uint8_t hour = dateTimeController.Hours(); uint8_t minute = dateTimeController.Minutes(); uint8_t second = dateTimeController.Seconds(); if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { char ampmChar[3] = "am"; if (hour == 0) { hour = 12; } else if (hour == 12) { ampmChar[0] = 'p'; } else if (hour > 12) { hour = hour - 12; ampmChar[0] = 'p'; } 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, R_LTGREY("time=")"#11cc55 %02d:%02d:%02d", hour, minute, second); } currentDate = std::chrono::time_point_cast(currentDateTime.Get()); if (currentDate.IsUpdated()) { uint16_t year = dateTimeController.Year(); Controllers::DateTime::Months month = dateTimeController.Month(); uint8_t day = dateTimeController.Day(); lv_label_set_text_fmt(label_date, R_LTGREY("date=")"#007fff %04d-%02d-%02d#", short(year), char(month), char(day)); } } heartbeat = heartRateController.HeartRate(); heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { if (heartbeatRunning.Get()) { 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 ...#"); } else { lv_label_set_text_static(heartbeatValue, R_LTGREY("puls=---")); } } stepCount = motionController.NbSteps(); if (stepCount.IsUpdated()) { 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=---")); } } }