#include "displayapp/screens/WatchFaceAnalog24.h" #include #include #include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BleIcon.h" #include "displayapp/screens/Symbols.h" #include "displayapp/screens/NotificationIcon.h" #include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; LV_IMG_DECLARE(bg_analog24); namespace { constexpr int16_t HourLength = 30; // constexpr int16_t MinuteLength = 90; // constexpr int16_t SecondLength = 110; // sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor const auto LV_TRIG_SCALE = _lv_trigo_sin(90); int16_t Cosine(int16_t angle) { return _lv_trigo_sin(angle + 90); } int16_t Sine(int16_t angle) { return _lv_trigo_sin(angle); } int16_t CoordinateXRelocate(int16_t x) { return (x + LV_HOR_RES / 2); } int16_t CoordinateYRelocate(int16_t y) { return std::abs(y - LV_HOR_RES / 2); } lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) { return lv_point_t{ .x = CoordinateXRelocate(radius * static_cast(Sine(angle)) / LV_TRIG_SCALE), .y = CoordinateYRelocate(radius * static_cast(Cosine(angle)) / LV_TRIG_SCALE) }; } } WatchFaceAnalog24::WatchFaceAnalog24(Pinetime::Applications::DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, Controllers::Ble& bleController, Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, Controllers::MotionController& motionController) : Screen(app), currentDateTime {{}}, dateTimeController {dateTimeController}, batteryController {batteryController}, bleController {bleController}, notificationManager {notificationManager}, settingsController {settingsController}, heartRateController {heartRateController}, motionController {motionController} { sHour = 99; sMinute = 99; // sSecond = 99; lv_obj_t* bg_clock_img = lv_img_create(lv_scr_act(), NULL); lv_img_set_src(bg_clock_img, &bg_analog24); lv_obj_align(bg_clock_img, nullptr, LV_ALIGN_CENTER, 0, 0); batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(batteryIcon, Symbols::batteryHalf); lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); lv_obj_set_auto_realign(batteryIcon, true); 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, batteryIcon, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0); lv_obj_set_auto_realign(bleIcon, true); notificationIcon = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); // Date - Day / Week day hour_body_trace = lv_line_create(lv_scr_act(), NULL); lv_style_init(&hour_line_style_trace); lv_style_set_line_width(&hour_line_style_trace, LV_STATE_DEFAULT, 3); lv_style_set_line_color(&hour_line_style_trace, LV_STATE_DEFAULT, LV_COLOR_LIME); lv_style_set_line_rounded(&hour_line_style_trace, LV_STATE_DEFAULT, false); lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace); heartbeatValue = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xAA1111)); lv_label_set_text_static(heartbeatValue, ""); lv_obj_align(heartbeatValue, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_obj_set_auto_realign(heartbeatValue, true); heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); lv_obj_align(heartbeatIcon, heartbeatValue, LV_ALIGN_OUT_TOP_LEFT, 0, 0); lv_obj_set_auto_realign(heartbeatIcon, true); stepValue = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00AAA8)); lv_label_set_text_static(stepValue, "0"); lv_obj_align(stepValue, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lv_obj_set_auto_realign(stepValue, true); stepIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x007775)); lv_label_set_text_static(stepIcon, Symbols::shoe); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_TOP_RIGHT, 0, 0); lv_obj_set_auto_realign(stepIcon, true); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); } WatchFaceAnalog24::~WatchFaceAnalog24() { lv_task_del(taskRefresh); // lv_style_reset(&hour_line_style); lv_style_reset(&hour_line_style_trace); // lv_style_reset(&minute_line_style); // lv_style_reset(&minute_line_style_trace); // lv_style_reset(&second_line_style); lv_obj_clean(lv_scr_act()); } void WatchFaceAnalog24::UpdateClock() { uint8_t hour = dateTimeController.Hours(); uint8_t minute = dateTimeController.Minutes(); // second = dateTimeController.Seconds(); // if (sMinute != minute) { // auto const angle = minute * 6; // minute_point[0] = CoordinateRelocate(30, angle); // minute_point[1] = CoordinateRelocate(MinuteLength, angle); // minute_point_trace[0] = CoordinateRelocate(5, angle); // minute_point_trace[1] = CoordinateRelocate(31, angle); // lv_line_set_points(minute_body, minute_point, 2); // lv_line_set_points(minute_body_trace, minute_point_trace, 2); // } if (sHour != hour || sMinute != minute) { sHour = hour; sMinute = minute; auto const angle = (hour * 15 + minute / 4); // hour_point[0] = CoordinateRelocate(30, angle); // hour_point[1] = CoordinateRelocate(HourLength, angle); hour_point_trace[0] = CoordinateRelocate(-20, angle); hour_point_trace[1] = CoordinateRelocate(121, angle); // lv_line_set_points(hour_body, hour_point, 2); lv_line_set_points(hour_body_trace, hour_point_trace, 2); } // if (sSecond != second) { // sSecond = second; // auto const angle = second * 6; // second_point[0] = CoordinateRelocate(-20, angle); // second_point[1] = CoordinateRelocate(SecondLength, angle); // lv_line_set_points(second_body, second_point, 2); // } } void WatchFaceAnalog24::SetBatteryIcon() { 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(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); } void WatchFaceAnalog24::Refresh() { isCharging = batteryController.IsCharging(); if (isCharging.IsUpdated()) { if (isCharging.Get()) { lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); lv_label_set_text(batteryIcon, Symbols::plug); } else { SetBatteryIcon(); } } if (!isCharging.Get()) { batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated()) { SetBatteryIcon(); } } bleState = bleController.IsConnected(); if (bleState.IsUpdated()) { lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get())); } notificationState = notificationManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } currentDateTime = dateTimeController.CurrentDateTime(); if (currentDateTime.IsUpdated()) { month = dateTimeController.Month(); day = dateTimeController.Day(); dayOfWeek = dateTimeController.DayOfWeek(); UpdateClock(); #if 0 if ((month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), day); currentMonth = month; currentDayOfWeek = dayOfWeek; currentDay = day; } #endif } heartbeat = heartRateController.HeartRate(); heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { if (heartbeatRunning.Get()) { lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x770505)); lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get()); } else { lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); lv_label_set_text_static(heartbeatValue, ""); } } stepCount = motionController.NbSteps(); motionSensorOk = motionController.IsSensorOk(); if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) { lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get()); } }