diff options
Diffstat (limited to 'src/displayapp/screens')
| -rw-r--r-- | src/displayapp/screens/Clock.h | 52 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog24.cpp | 233 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog24.h | 90 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.cpp | 55 | ||||
| -rw-r--r-- | src/displayapp/screens/WatchFaceDigital.h | 5 |
5 files changed, 52 insertions, 383 deletions
diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h new file mode 100644 index 0000000..5001dce --- /dev/null +++ b/src/displayapp/screens/Clock.h @@ -0,0 +1,52 @@ +#pragma once + +#include <lvgl/src/lv_core/lv_obj.h> +#include <chrono> +#include <cstdint> +#include <memory> +#include "displayapp/screens/Screen.h" +#include "components/datetime/DateTimeController.h" +#include "systemtask/SystemTask.h" + +namespace Pinetime { + namespace Controllers { + class Settings; + class Battery; + class Ble; + class NotificationManager; + class MotionController; + } + + namespace Applications { + namespace Screens { + class Clock : public Screen { + public: + Clock(DisplayApp* app, + Controllers::DateTime& dateTimeController, + Controllers::Battery& batteryController, + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager, + Controllers::Settings& settingsController, + Controllers::MotionController& motionController, + System::SystemTask& systemTask); + ~Clock() override; + + bool OnTouchEvent(TouchEvents event) override; + bool OnButtonPushed() override; + + System::SystemTask& systemTask; + private: + Controllers::DateTime& dateTimeController; + Controllers::Battery& batteryController; + Controllers::Ble& bleController; + Controllers::NotificationManager& notificatioManager; + Controllers::Settings& settingsController; + Controllers::MotionController& motionController; + + std::unique_ptr<Screen> screen; + std::unique_ptr<Screen> WatchFaceDigitalScreen(); + std::unique_ptr<Screen> WatchFaceTerminalScreen(); + }; + } + } +} diff --git a/src/displayapp/screens/WatchFaceAnalog24.cpp b/src/displayapp/screens/WatchFaceAnalog24.cpp deleted file mode 100644 index cc29eb3..0000000 --- a/src/displayapp/screens/WatchFaceAnalog24.cpp +++ /dev/null @@ -1,233 +0,0 @@ -#include "displayapp/screens/WatchFaceAnalog24.h" -#include <cmath> -#include <lvgl/lvgl.h> -#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<int32_t>(Sine(angle)) / LV_TRIG_SCALE), - .y = CoordinateYRelocate(radius * static_cast<int32_t>(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) - : Screen(app), - currentDateTime {{}}, - dateTimeController {dateTimeController}, - batteryController {batteryController}, - bleController {bleController}, - notificationManager {notificationManager}, - settingsController {settingsController} { - - 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, NULL, 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); - - 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, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - - // Date - Day / Week day - - // label_date_day = lv_label_create(lv_scr_act(), NULL); - // lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xf0a500)); - // lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day()); - // lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER); - // lv_obj_align(label_date_day, NULL, LV_ALIGN_CENTER, 50, 0); - - // minute_body = lv_line_create(lv_scr_act(), NULL); - // minute_body_trace = lv_line_create(lv_scr_act(), NULL); - // hour_body = lv_line_create(lv_scr_act(), NULL); - hour_body_trace = lv_line_create(lv_scr_act(), NULL); - // second_body = lv_line_create(lv_scr_act(), NULL); - - // lv_style_init(&second_line_style); - // lv_style_set_line_width(&second_line_style, LV_STATE_DEFAULT, 3); - // lv_style_set_line_color(&second_line_style, LV_STATE_DEFAULT, LV_COLOR_GREEN); - // lv_style_set_line_rounded(&second_line_style, LV_STATE_DEFAULT, true); - // lv_obj_add_style(second_body, LV_LINE_PART_MAIN, &second_line_style); - - // lv_style_init(&minute_line_style); - // lv_style_set_line_width(&minute_line_style, LV_STATE_DEFAULT, 7); - // lv_style_set_line_color(&minute_line_style, LV_STATE_DEFAULT, LV_COLOR_WHITE); - // lv_style_set_line_rounded(&minute_line_style, LV_STATE_DEFAULT, true); - // lv_obj_add_style(minute_body, LV_LINE_PART_MAIN, &minute_line_style); - - // lv_style_init(&minute_line_style_trace); - // lv_style_set_line_width(&minute_line_style_trace, LV_STATE_DEFAULT, 3); - // lv_style_set_line_color(&minute_line_style_trace, LV_STATE_DEFAULT, LV_COLOR_WHITE); - // lv_style_set_line_rounded(&minute_line_style_trace, LV_STATE_DEFAULT, false); - // lv_obj_add_style(minute_body_trace, LV_LINE_PART_MAIN, &minute_line_style_trace); - - // lv_style_init(&hour_line_style); - // lv_style_set_line_width(&hour_line_style, LV_STATE_DEFAULT, 7); - // lv_style_set_line_color(&hour_line_style, LV_STATE_DEFAULT, LV_COLOR_WHITE); - // lv_style_set_line_rounded(&hour_line_style, LV_STATE_DEFAULT, true); - // lv_obj_add_style(hour_body, LV_LINE_PART_MAIN, &hour_line_style); - - 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); - - taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); - UpdateClock(); -} - -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() { - hour = dateTimeController.Hours(); - 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(); - } - } - - 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 - } -} diff --git a/src/displayapp/screens/WatchFaceAnalog24.h b/src/displayapp/screens/WatchFaceAnalog24.h deleted file mode 100644 index 25233af..0000000 --- a/src/displayapp/screens/WatchFaceAnalog24.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once - -#include <lvgl/src/lv_core/lv_obj.h> -#include <chrono> -#include <cstdint> -#include <memory> -#include "displayapp/screens/Screen.h" -#include "components/datetime/DateTimeController.h" -#include "components/battery/BatteryController.h" -#include "components/ble/BleController.h" -#include "components/ble/NotificationManager.h" - -namespace Pinetime { - namespace Controllers { - class Settings; - class Battery; - class Ble; - class NotificationManager; - } - namespace Applications { - namespace Screens { - - class WatchFaceAnalog24 : public Screen { - public: - WatchFaceAnalog24(DisplayApp* app, - Controllers::DateTime& dateTimeController, - Controllers::Battery& batteryController, - Controllers::Ble& bleController, - Controllers::NotificationManager& notificationManager, - Controllers::Settings& settingsController); - - ~WatchFaceAnalog24() override; - - void Refresh() override; - - private: - uint8_t sHour, sMinute; // , sSecond; - uint8_t hour; - uint8_t minute; - // uint8_t second; - - Pinetime::Controllers::DateTime::Months month; - uint8_t day; - Pinetime::Controllers::DateTime::Days dayOfWeek; - - Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown; - Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; - uint8_t currentDay = 0; - - DirtyValue<uint8_t> batteryPercentRemaining {0}; - DirtyValue<bool> isCharging {}; - DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime; - DirtyValue<bool> notificationState {false}; - - // lv_obj_t* hour_body; - lv_obj_t* hour_body_trace; - // lv_obj_t* minute_body; - // lv_obj_t* minute_body_trace; - // lv_obj_t* second_body; - - // lv_point_t hour_point[2]; - lv_point_t hour_point_trace[2]; - // lv_point_t minute_point[2]; - // lv_point_t minute_point_trace[2]; - // lv_point_t second_point[2]; - - // lv_style_t hour_line_style; - lv_style_t hour_line_style_trace; - // lv_style_t minute_line_style; - // lv_style_t minute_line_style_trace; - // lv_style_t second_line_style; - - // lv_obj_t* label_date_day; - lv_obj_t* batteryIcon; - lv_obj_t* notificationIcon; - - Controllers::DateTime& dateTimeController; - Controllers::Battery& batteryController; - Controllers::Ble& bleController; - Controllers::NotificationManager& notificationManager; - Controllers::Settings& settingsController; - - void UpdateClock(); - void SetBatteryIcon(); - - lv_task_t* taskRefresh; - }; - } - } -} diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index a184c77..68c6acb 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -15,41 +15,6 @@ #include "displayapp/fonts/neofont.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<int32_t>(Sine(angle)) / LV_TRIG_SCALE), - .y = CoordinateYRelocate(radius * static_cast<int32_t>(Cosine(angle)) / LV_TRIG_SCALE) - }; -} - -} - WatchFaceDigital::WatchFaceDigital(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, @@ -68,10 +33,6 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, settingsController {settingsController}, motionController {motionController} { - 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, NULL, LV_ALIGN_CENTER, 0, 0); - 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); @@ -160,13 +121,6 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text_static(backgroundLabel, ""); - 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); - taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); } @@ -240,15 +194,6 @@ void WatchFaceDigital::Refresh() { uint8_t second = time.seconds().count(); if (displayedHour != hour || displayedMinute != minute) { - { - auto const angle = (hour * 15 + minute / 4); - - 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); - } displayedHour = hour; displayedMinute = minute; bool hide_pm = true; diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 97c479f..8382996 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -56,7 +56,6 @@ namespace Pinetime { DirtyValue<uint32_t> stepCount {}; DirtyValue<bool> notificationState {}; - lv_obj_t* bg_clock_img; lv_obj_t* label_temp; lv_obj_t* label_time; lv_obj_t* label_time_sec; @@ -73,10 +72,6 @@ namespace Pinetime { lv_obj_t* stepValue; lv_obj_t* notificationIcon; - lv_obj_t* hour_body_trace; - lv_point_t hour_point_trace[2]; - lv_style_t hour_line_style_trace; - Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; |
