summaryrefslogtreecommitdiff
path: root/src/displayapp/screens
diff options
context:
space:
mode:
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r--src/displayapp/screens/BatteryIcon.cpp3
-rw-r--r--src/displayapp/screens/BatteryIcon.h2
-rw-r--r--src/displayapp/screens/BatteryInfo.cpp38
-rw-r--r--src/displayapp/screens/BatteryInfo.h2
-rw-r--r--src/displayapp/screens/PineTimeStyle.cpp6
-rw-r--r--src/displayapp/screens/PineTimeStyle.h2
-rw-r--r--src/displayapp/screens/SystemInfo.cpp2
-rw-r--r--src/displayapp/screens/WatchFaceAnalog.cpp77
-rw-r--r--src/displayapp/screens/WatchFaceAnalog.h2
-rw-r--r--src/displayapp/screens/WatchFaceDigital.h2
10 files changed, 69 insertions, 67 deletions
diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp
index 6b54a305..bb6626a5 100644
--- a/src/displayapp/screens/BatteryIcon.cpp
+++ b/src/displayapp/screens/BatteryIcon.cpp
@@ -1,9 +1,10 @@
+#include <cstdint>
#include "BatteryIcon.h"
#include "Symbols.h"
using namespace Pinetime::Applications::Screens;
-const char* BatteryIcon::GetBatteryIcon(int batteryPercent) {
+const char* BatteryIcon::GetBatteryIcon(uint8_t batteryPercent) {
if (batteryPercent > 90)
return Symbols::batteryFull;
if (batteryPercent > 75)
diff --git a/src/displayapp/screens/BatteryIcon.h b/src/displayapp/screens/BatteryIcon.h
index 9c192ff7..b370b331 100644
--- a/src/displayapp/screens/BatteryIcon.h
+++ b/src/displayapp/screens/BatteryIcon.h
@@ -6,7 +6,7 @@ namespace Pinetime {
class BatteryIcon {
public:
static const char* GetUnknownIcon();
- static const char* GetBatteryIcon(int batteryPercent);
+ static const char* GetBatteryIcon(uint8_t batteryPercent);
static const char* GetPlugIcon(bool isCharging);
};
}
diff --git a/src/displayapp/screens/BatteryInfo.cpp b/src/displayapp/screens/BatteryInfo.cpp
index 5ea0b6ff..0ab47ebf 100644
--- a/src/displayapp/screens/BatteryInfo.cpp
+++ b/src/displayapp/screens/BatteryInfo.cpp
@@ -33,11 +33,7 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont
percent = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
- if (batteryPercent >= 0) {
- lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
- } else {
- lv_label_set_text(percent, "--%");
- }
+ lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT);
lv_obj_align(percent, nullptr, LV_ALIGN_CENTER, 0, -60);
@@ -69,28 +65,22 @@ void BatteryInfo::UpdateScreen() {
batteryPercent = batteryController.PercentRemaining();
batteryVoltage = batteryController.Voltage();
- if (batteryPercent >= 0) {
- if (batteryController.IsCharging() and batteryPercent < 100) {
- lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
- lv_label_set_text_static(status, "Battery charging");
- } else if (batteryPercent == 100) {
- lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
- lv_label_set_text_static(status, "Battery is fully charged");
- } else if (batteryPercent < 10) {
- lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
- lv_label_set_text_static(status, "Battery is low");
- } else {
- lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN);
- lv_label_set_text_static(status, "Battery discharging");
- }
-
- lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
-
+ if (batteryController.IsCharging() and batteryPercent < 100) {
+ lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
+ lv_label_set_text_static(status, "Charging");
+ } else if (batteryPercent == 100) {
+ lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE);
+ lv_label_set_text_static(status, "Fully charged");
+ } else if (batteryPercent < 10) {
+ lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
+ lv_label_set_text_static(status, "Battery low");
} else {
- lv_label_set_text_static(status, "Reading Battery status");
- lv_label_set_text(percent, "--%");
+ lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN);
+ lv_label_set_text_static(status, "Discharging");
}
+ lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
+
lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
diff --git a/src/displayapp/screens/BatteryInfo.h b/src/displayapp/screens/BatteryInfo.h
index 32115938..69793244 100644
--- a/src/displayapp/screens/BatteryInfo.h
+++ b/src/displayapp/screens/BatteryInfo.h
@@ -33,7 +33,7 @@ namespace Pinetime {
lv_task_t* taskUpdate;
- int8_t batteryPercent = -1;
+ uint8_t batteryPercent = 0;
uint16_t batteryVoltage = 0;
};
}
diff --git a/src/displayapp/screens/PineTimeStyle.cpp b/src/displayapp/screens/PineTimeStyle.cpp
index 678099c0..591f3a49 100644
--- a/src/displayapp/screens/PineTimeStyle.cpp
+++ b/src/displayapp/screens/PineTimeStyle.cpp
@@ -179,8 +179,8 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
lv_obj_align(stepGauge, sidebar, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_gauge_set_scale(stepGauge, 360, 11, 0);
lv_gauge_set_angle_offset(stepGauge, 180);
- lv_gauge_set_critical_value(stepGauge, (settingsController.GetStepsGoal() / 100));
- lv_gauge_set_range(stepGauge, 0, (settingsController.GetStepsGoal() / 100));
+ lv_gauge_set_critical_value(stepGauge, 100);
+ lv_gauge_set_range(stepGauge, 0, 100);
lv_gauge_set_value(stepGauge, 0, 0);
lv_obj_set_style_local_pad_right(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, 3);
@@ -328,7 +328,7 @@ bool PineTimeStyle::Refresh() {
stepCount = motionController.NbSteps();
motionSensorOk = motionController.IsSensorOk();
if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) {
- lv_gauge_set_value(stepGauge, 0, (stepCount.Get() / 100));
+ lv_gauge_set_value(stepGauge, 0, (stepCount.Get() / (settingsController.GetStepsGoal() / 100)));
lv_obj_realign(stepGauge);
if (stepCount.Get() > settingsController.GetStepsGoal()) {
lv_obj_set_style_local_line_color(stepGauge, LV_GAUGE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
diff --git a/src/displayapp/screens/PineTimeStyle.h b/src/displayapp/screens/PineTimeStyle.h
index 70794cc5..3b4ded1e 100644
--- a/src/displayapp/screens/PineTimeStyle.h
+++ b/src/displayapp/screens/PineTimeStyle.h
@@ -42,7 +42,7 @@ namespace Pinetime {
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0;
- DirtyValue<int> batteryPercentRemaining {};
+ DirtyValue<uint8_t> batteryPercentRemaining {};
DirtyValue<bool> bleState {};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
DirtyValue<bool> motionSensorOk {};
diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp
index 5ae3a595..f5bf0cc9 100644
--- a/src/displayapp/screens/SystemInfo.cpp
+++ b/src/displayapp/screens/SystemInfo.cpp
@@ -103,7 +103,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen1() {
}
std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
- auto batteryPercent = static_cast<uint8_t>(batteryController.PercentRemaining());
+ auto batteryPercent = batteryController.PercentRemaining();
auto resetReason = [this]() {
switch (watchdog.ResetReason()) {
case Drivers::Watchdog::ResetReasons::Watchdog:
diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp
index 0051408c..f1889379 100644
--- a/src/displayapp/screens/WatchFaceAnalog.cpp
+++ b/src/displayapp/screens/WatchFaceAnalog.cpp
@@ -5,27 +5,44 @@
#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 auto HOUR_LENGTH = 70;
+constexpr auto MINUTE_LENGTH = 90;
+constexpr auto SECOND_LENGTH = 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);
+}
-// ##
-static int16_t coordinate_x_relocate(int16_t x) {
- return ((x) + LV_HOR_RES / 2);
+int16_t coordinate_x_relocate(int16_t x) {
+ return (x + LV_HOR_RES / 2);
}
-// ##
-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);
+int16_t coordinate_y_relocate(int16_t y) {
+ return std::abs(y - LV_HOR_RES / 2);
}
+lv_point_t coordinate_relocate(int16_t radius, int16_t angle) {
+ return lv_point_t{
+ .x = coordinate_x_relocate(radius * static_cast<int32_t>(sine(angle)) / LV_TRIG_SCALE),
+ .y = coordinate_y_relocate(radius * static_cast<int32_t>(cosine(angle)) / LV_TRIG_SCALE)
+ };
+}
+
+} // namespace
+
WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app,
Controllers::DateTime& dateTimeController,
Controllers::Battery& batteryController,
@@ -123,15 +140,12 @@ void WatchFaceAnalog::UpdateClock() {
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] = coordinate_relocate(30, angle);
+ minute_point[1] = coordinate_relocate(MINUTE_LENGTH, 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] = coordinate_relocate(5, angle);
+ minute_point_trace[1] = coordinate_relocate(31, angle);
lv_line_set_points(minute_body, minute_point, 2);
lv_line_set_points(minute_body_trace, minute_point_trace, 2);
@@ -140,15 +154,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] = coordinate_relocate(30, angle);
+ hour_point[1] = coordinate_relocate(HOUR_LENGTH, angle);
+
+ hour_point_trace[0] = coordinate_relocate(5, angle);
+ hour_point_trace[1] = coordinate_relocate(31, angle);
lv_line_set_points(hour_body, hour_point, 2);
lv_line_set_points(hour_body_trace, hour_point_trace, 2);
@@ -156,16 +168,15 @@ 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] = coordinate_relocate(-20, angle);
+ second_point[1] = coordinate_relocate(SECOND_LENGTH, angle);
lv_line_set_points(second_body, second_point, 2);
}
}
bool WatchFaceAnalog::Refresh() {
-
batteryPercentRemaining = batteryController.PercentRemaining();
if (batteryPercentRemaining.IsUpdated()) {
auto batteryPercent = batteryPercentRemaining.Get();
diff --git a/src/displayapp/screens/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h
index 96225558..ac7f0ac5 100644
--- a/src/displayapp/screens/WatchFaceAnalog.h
+++ b/src/displayapp/screens/WatchFaceAnalog.h
@@ -48,7 +48,7 @@ namespace Pinetime {
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0;
- DirtyValue<float> batteryPercentRemaining {0};
+ DirtyValue<uint8_t> batteryPercentRemaining {0};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
DirtyValue<bool> notificationState {false};
diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h
index 246efc95..76c8d3dc 100644
--- a/src/displayapp/screens/WatchFaceDigital.h
+++ b/src/displayapp/screens/WatchFaceDigital.h
@@ -45,7 +45,7 @@ namespace Pinetime {
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0;
- DirtyValue<int> batteryPercentRemaining {};
+ DirtyValue<uint8_t> batteryPercentRemaining {};
DirtyValue<bool> bleState {};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
DirtyValue<bool> motionSensorOk {};