summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/WatchFaceAnalog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/displayapp/screens/WatchFaceAnalog.cpp')
-rw-r--r--src/displayapp/screens/WatchFaceAnalog.cpp93
1 files changed, 48 insertions, 45 deletions
diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp
index 02f1fc2a..621929b8 100644
--- a/src/displayapp/screens/WatchFaceAnalog.cpp
+++ b/src/displayapp/screens/WatchFaceAnalog.cpp
@@ -5,39 +5,55 @@
#include "Symbols.h"
#include "NotificationIcon.h"
-#include <cmath>
-
LV_IMG_DECLARE(bg_clock);
using namespace Pinetime::Applications::Screens;
-#define HOUR_LENGTH 70
-#define MINUTE_LENGTH 90
-#define SECOND_LENGTH 110
-#define PI 3.14159265358979323846
+namespace {
+constexpr int16_t HourLength = 70;
+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);
+}
-// ##
-static int16_t coordinate_x_relocate(int16_t x) {
- return ((x) + 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)
+ };
}
-// ##
-static int16_t coordinate_y_relocate(int16_t y) {
- return (((y) -LV_HOR_RES / 2) < 0) ? (0 - ((y) -LV_HOR_RES / 2)) : ((y) -LV_HOR_RES / 2);
}
WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app,
Controllers::DateTime& dateTimeController,
Controllers::Battery& batteryController,
Controllers::Ble& bleController,
- Controllers::NotificationManager& notificatioManager,
+ Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController)
: Screen(app),
currentDateTime {{}},
dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},
- notificatioManager {notificatioManager},
+ notificationManager {notificationManager},
settingsController {settingsController} {
settingsController.SetClockFace(1);
@@ -106,7 +122,6 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app,
}
WatchFaceAnalog::~WatchFaceAnalog() {
-
lv_style_reset(&hour_line_style);
lv_style_reset(&hour_line_style_trace);
lv_style_reset(&minute_line_style);
@@ -117,21 +132,17 @@ WatchFaceAnalog::~WatchFaceAnalog() {
}
void WatchFaceAnalog::UpdateClock() {
-
hour = dateTimeController.Hours();
minute = dateTimeController.Minutes();
second = dateTimeController.Seconds();
if (sMinute != minute) {
- minute_point[0].x = coordinate_x_relocate(30 * sin(minute * 6 * PI / 180));
- minute_point[0].y = coordinate_y_relocate(30 * cos(minute * 6 * PI / 180));
- minute_point[1].x = coordinate_x_relocate(MINUTE_LENGTH * sin(minute * 6 * PI / 180));
- minute_point[1].y = coordinate_y_relocate(MINUTE_LENGTH * cos(minute * 6 * PI / 180));
+ auto const angle = minute * 6;
+ minute_point[0] = CoordinateRelocate(30, angle);
+ minute_point[1] = CoordinateRelocate(MinuteLength, angle);
- minute_point_trace[0].x = coordinate_x_relocate(5 * sin(minute * 6 * PI / 180));
- minute_point_trace[0].y = coordinate_y_relocate(5 * cos(minute * 6 * PI / 180));
- minute_point_trace[1].x = coordinate_x_relocate(31 * sin(minute * 6 * PI / 180));
- minute_point_trace[1].y = coordinate_y_relocate(31 * cos(minute * 6 * PI / 180));
+ 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);
@@ -140,15 +151,13 @@ void WatchFaceAnalog::UpdateClock() {
if (sHour != hour || sMinute != minute) {
sHour = hour;
sMinute = minute;
- hour_point[0].x = coordinate_x_relocate(30 * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
- hour_point[0].y = coordinate_y_relocate(30 * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
- hour_point[1].x = coordinate_x_relocate(HOUR_LENGTH * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
- hour_point[1].y = coordinate_y_relocate(HOUR_LENGTH * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
+ auto const angle = (hour * 30 + minute / 2);
- hour_point_trace[0].x = coordinate_x_relocate(5 * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
- hour_point_trace[0].y = coordinate_y_relocate(5 * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
- hour_point_trace[1].x = coordinate_x_relocate(31 * sin((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
- hour_point_trace[1].y = coordinate_y_relocate(31 * cos((((hour > 12 ? hour - 12 : hour) * 30) + (minute * 0.5)) * PI / 180));
+ hour_point[0] = CoordinateRelocate(30, angle);
+ hour_point[1] = CoordinateRelocate(HourLength, angle);
+
+ hour_point_trace[0] = CoordinateRelocate(5, angle);
+ hour_point_trace[1] = CoordinateRelocate(31, angle);
lv_line_set_points(hour_body, hour_point, 2);
lv_line_set_points(hour_body_trace, hour_point_trace, 2);
@@ -156,35 +165,30 @@ void WatchFaceAnalog::UpdateClock() {
if (sSecond != second) {
sSecond = second;
- second_point[0].x = coordinate_x_relocate(20 * sin((180 + second * 6) * PI / 180));
- second_point[0].y = coordinate_y_relocate(20 * cos((180 + second * 6) * PI / 180));
- second_point[1].x = coordinate_x_relocate(SECOND_LENGTH * sin(second * 6 * PI / 180));
- second_point[1].y = coordinate_y_relocate(SECOND_LENGTH * cos(second * 6 * PI / 180));
+ 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);
}
}
bool WatchFaceAnalog::Refresh() {
-
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
}
- notificationState = notificatioManager.AreNewNotificationsAvailable();
+ notificationState = notificationManager.AreNewNotificationsAvailable();
if (notificationState.IsUpdated()) {
- if (notificationState.Get() == true)
- lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true));
- else
- lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false));
+ lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
}
currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) {
-
month = dateTimeController.Month();
day = dateTimeController.Day();
dayOfWeek = dateTimeController.DayOfWeek();
@@ -192,7 +196,6 @@ bool WatchFaceAnalog::Refresh() {
UpdateClock();
if ((month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
-
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), day);
currentMonth = month;
@@ -202,4 +205,4 @@ bool WatchFaceAnalog::Refresh() {
}
return true;
-} \ No newline at end of file
+}