#include "displayapp/screens/WatchFaceDigital.h" #include #include #include #include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BleIcon.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/motion/MotionController.h" #include "components/settings/Settings.h" #include "displayapp/fonts/neofont.h" using namespace Pinetime::Applications::Screens; WatchFaceDigital::WatchFaceDigital(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, Controllers::Ble& bleController, Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, Controllers::MotionController& motionController, System::SystemTask& systemTask) : Screen(app), systemTask {systemTask}, currentDateTime {{}}, dateTimeController {dateTimeController}, batteryController {batteryController}, bleController {bleController}, notificatioManager {notificatioManager}, settingsController {settingsController}, motionController {motionController} { batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(batteryIcon, "B##%%"); lv_obj_set_style_local_text_font(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); batteryPlug = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFF00)); lv_label_set_text_static(batteryPlug, ""); lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); bleIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x0082FC)); lv_label_set_text_static(bleIcon, Symbols::bluetooth); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); notificationIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); label_date = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); lv_obj_set_style_local_text_font(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont2); label_temp = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color( label_temp, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222)); lv_obj_set_style_local_text_font( label_temp, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont15); lv_label_set_text_fmt(label_temp, "??°C"); lv_obj_align(label_temp, lv_scr_act(), LV_ALIGN_CENTER, 60, -60); label_time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont3); lv_label_set_text_fmt(label_time, "??:??"); lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); label_time_sec = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(label_time_sec, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); lv_obj_set_style_local_text_font(label_time_sec, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont2); lv_label_set_text_fmt(label_time_sec, ":??"); lv_obj_align(label_time_sec, label_time, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); label_time_ampm = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(label_time_ampm, ""); lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55); backgroundLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_click(backgroundLabel, true); 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, ""); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); } WatchFaceDigital::~WatchFaceDigital() { lv_task_del(taskRefresh); lv_obj_clean(lv_scr_act()); } void WatchFaceDigital::Refresh() { powerPresent = batteryController.IsPowerPresent(); if (powerPresent.IsUpdated()) { lv_label_set_text_static(batteryPlug, (powerPresent.Get() ? "PWR" : "")); } batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated()) { auto batteryPercent = batteryPercentRemaining.Get(); if (batteryPercent == 100) { lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); } else { lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); } lv_label_set_text_fmt(batteryIcon, "B%d%%", batteryPercent); } bleState = bleController.IsConnected(); if (bleState.IsUpdated()) { lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get())); } lv_obj_realign(batteryIcon); lv_obj_realign(batteryPlug); lv_obj_realign(bleIcon); notificationState = notificatioManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } #ifndef INFINISIM temperature = systemTask.motionSensor.getTemperature(); if (temperature.IsUpdated()) { lv_obj_set_style_local_text_color( label_temp, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); lv_label_set_text_fmt(label_temp, "%d°C"); #if 0 lv_label_set_text_fmt(label_temp, "T%d [%d,%d]", ((int)(systemTask.motionSensor.temperature_last_read_value+23)), ((int)(systemTask.motionSensor.temperature_last_result)), ((int)(systemTask.motionSensor.temperature_read_counter)) ); #endif } #endif currentDateTime = dateTimeController.CurrentDateTime(); if (currentDateTime.IsUpdated()) { auto newDateTime = currentDateTime.Get(); auto dp = date::floor(newDateTime); auto time = date::make_time(newDateTime - dp); auto yearMonthDay = date::year_month_day(dp); auto year = static_cast(yearMonthDay.year()); auto month = static_cast(static_cast(yearMonthDay.month())); auto day = static_cast(yearMonthDay.day()); auto dayOfWeek = static_cast(date::weekday(yearMonthDay).iso_encoding()); uint8_t hour = time.hours().count(); uint8_t minute = time.minutes().count(); uint8_t second = time.seconds().count(); if (displayedHour != hour || displayedMinute != minute) { displayedHour = hour; displayedMinute = minute; 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(label_time_ampm, ampmChar); lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute); // lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); } else { lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); // lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } } if (displayedSecond != second) { displayedSecond = second; lv_label_set_text_fmt(label_time_sec, ":%02d", second); } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { lv_label_set_text_fmt( label_date, "%s %d %s %d", dateTimeController.DayOfWeekShortToString(), day, dateTimeController.MonthShortToString(), year); } else { lv_label_set_text_fmt( label_date, "%s %s %d %d", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString(), day, year); } lv_obj_realign(label_date); currentYear = year; currentMonth = month; currentDayOfWeek = dayOfWeek; currentDay = day; } } }