Add Setting to display UTC. Change Clockfaces to actually do it

This commit is contained in:
uli 2022-05-28 14:34:13 +02:00
parent 961ef6ca77
commit ed346fc465
7 changed files with 85 additions and 47 deletions

View File

@ -8,7 +8,7 @@ namespace Pinetime {
namespace Controllers { namespace Controllers {
class Settings { class Settings {
public: public:
enum class ClockType : uint8_t { H24, H12 }; enum class ClockType : uint8_t { H24, H12, UTC };
enum class Notification : uint8_t { ON, OFF }; enum class Notification : uint8_t { ON, OFF };
enum class ChimesOption : uint8_t { None, Hours, HalfHours }; enum class ChimesOption : uint8_t { None, Hours, HalfHours };
enum class WakeUpMode : uint8_t { enum class WakeUpMode : uint8_t {

View File

@ -1,5 +1,6 @@
#include "displayapp/screens/WatchFaceAnalog.h" #include "displayapp/screens/WatchFaceAnalog.h"
#include <cmath> #include <cmath>
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BatteryIcon.h"
#include "displayapp/screens/BleIcon.h" #include "displayapp/screens/BleIcon.h"
@ -12,35 +13,33 @@ LV_IMG_DECLARE(bg_clock);
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
namespace { namespace {
constexpr int16_t HourLength = 70; constexpr int16_t HourLength = 70;
constexpr int16_t MinuteLength = 90; constexpr int16_t MinuteLength = 90;
constexpr int16_t SecondLength = 110; constexpr int16_t SecondLength = 110;
// sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor // sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor
const auto LV_TRIG_SCALE = _lv_trigo_sin(90); const auto LV_TRIG_SCALE = _lv_trigo_sin(90);
int16_t Cosine(int16_t angle) { int16_t Cosine(int16_t angle) {
return _lv_trigo_sin(angle + 90); return _lv_trigo_sin(angle + 90);
} }
int16_t Sine(int16_t angle) { int16_t Sine(int16_t angle) {
return _lv_trigo_sin(angle); return _lv_trigo_sin(angle);
} }
int16_t CoordinateXRelocate(int16_t x) { int16_t CoordinateXRelocate(int16_t x) {
return (x + LV_HOR_RES / 2); return (x + LV_HOR_RES / 2);
} }
int16_t CoordinateYRelocate(int16_t y) { int16_t CoordinateYRelocate(int16_t y) {
return std::abs(y - LV_HOR_RES / 2); return std::abs(y - LV_HOR_RES / 2);
} }
lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) { lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) {
return lv_point_t{ return lv_point_t {.x = CoordinateXRelocate(radius * static_cast<int32_t>(Sine(angle)) / LV_TRIG_SCALE),
.x = CoordinateXRelocate(radius * static_cast<int32_t>(Sine(angle)) / LV_TRIG_SCALE), .y = CoordinateYRelocate(radius * static_cast<int32_t>(Cosine(angle)) / LV_TRIG_SCALE)};
.y = CoordinateYRelocate(radius * static_cast<int32_t>(Cosine(angle)) / LV_TRIG_SCALE) }
};
}
} }
@ -145,6 +144,15 @@ void WatchFaceAnalog::UpdateClock() {
uint8_t minute = dateTimeController.Minutes(); uint8_t minute = dateTimeController.Minutes();
uint8_t second = dateTimeController.Seconds(); uint8_t second = dateTimeController.Seconds();
if (settingsController.GetClockType() == Controllers::Settings::ClockType::UTC) {
auto utcDateTime = dateTimeController.UTCDateTime();
auto dp = date::floor<date::days>(utcDateTime);
auto time = date::make_time(utcDateTime - dp);
hour = time.hours().count();
minute = time.minutes().count();
second = time.seconds().count();
}
if (sMinute != minute) { if (sMinute != minute) {
auto const angle = minute * 6; auto const angle = minute * 6;
minute_point[0] = CoordinateRelocate(30, angle); minute_point[0] = CoordinateRelocate(30, angle);

View File

@ -120,6 +120,10 @@ void WatchFaceDigital::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (settingsController.GetClockType() == Controllers::Settings::ClockType::UTC) {
currentDateTime = dateTimeController.UTCDateTime();
}
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); auto newDateTime = currentDateTime.Get();
@ -159,12 +163,19 @@ void WatchFaceDigital::Refresh() {
} }
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { switch (settingsController.GetClockType()) {
lv_label_set_text_fmt( default:
label_date, "%s %d %s %d", dateTimeController.DayOfWeekShortToString(), day, dateTimeController.MonthShortToString(), year); case Controllers::Settings::ClockType::H24:
} else { lv_label_set_text_fmt(
lv_label_set_text_fmt( label_date, "%s %d %s %d", dateTimeController.DayOfWeekShortToString(), day, dateTimeController.MonthShortToString(), year);
label_date, "%s %s %d %d", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString(), day, year); break;
case Controllers::Settings::ClockType::H12:
lv_label_set_text_fmt(
label_date, "%s %s %d %d", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString(), day, year);
case Controllers::Settings::ClockType::UTC:
lv_label_set_text_fmt(
label_date, "%d-%d-%d", year, static_cast<uint8_t>(month), day);
break;
} }
lv_obj_realign(label_date); lv_obj_realign(label_date);

View File

@ -383,6 +383,11 @@ void WatchFacePineTimeStyle::Refresh() {
} }
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (settingsController.GetClockType() == Controllers::Settings::ClockType::UTC) {
currentDateTime = dateTimeController.UTCDateTime();
}
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); auto newDateTime = currentDateTime.Get();

View File

@ -89,7 +89,7 @@ void WatchFaceTerminal::Refresh() {
bleState = bleController.IsConnected(); bleState = bleController.IsConnected();
bleRadioEnabled = bleController.IsRadioEnabled(); bleRadioEnabled = bleController.IsRadioEnabled();
if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) { if (bleState.IsUpdated() || bleRadioEnabled.IsUpdated()) {
if(!bleRadioEnabled.Get()) { if (!bleRadioEnabled.Get()) {
lv_label_set_text_static(connectState, "[STAT]#0082fc Disabled#"); lv_label_set_text_static(connectState, "[STAT]#0082fc Disabled#");
} else { } else {
if (bleState.Get()) { if (bleState.Get()) {
@ -111,6 +111,10 @@ void WatchFaceTerminal::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (settingsController.GetClockType() == Controllers::Settings::ClockType::UTC) {
currentDateTime = dateTimeController.UTCDateTime();
}
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); auto newDateTime = currentDateTime.Get();
@ -132,24 +136,29 @@ void WatchFaceTerminal::Refresh() {
displayedMinute = minute; displayedMinute = minute;
displayedSecond = second; displayedSecond = second;
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { switch (settingsController.GetClockType()) {
char ampmChar[3] = "AM"; case Controllers::Settings::ClockType::H12: {
if (hour == 0) { char ampmChar[3] = "AM";
hour = 12; if (hour == 0) {
} else if (hour == 12) { hour = 12;
ampmChar[0] = 'P'; } else if (hour == 12) {
} else if (hour > 12) { ampmChar[0] = 'P';
hour = hour - 12; } else if (hour > 12) {
ampmChar[0] = 'P'; hour = hour - 12;
} ampmChar[0] = 'P';
lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d %s#", hour, minute, second, ampmChar); }
} else { lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d %s#", hour, minute, second, ampmChar);
lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d", hour, minute, second); } break;
case Controllers::Settings::ClockType::H24:
lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d", hour, minute, second);
break;
case Controllers::Settings::ClockType::UTC:
lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02dZ", hour, minute, second);
} }
} }
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
lv_label_set_text_fmt(label_date, "[DATE]#007fff %04d.%02d.%02d#", short(year), char(month), char(day)); lv_label_set_text_fmt(label_date, "[DATE]#007fff %04d-%02d-%02d#", short(year), char(month), char(day));
currentYear = year; currentYear = year;
currentMonth = month; currentMonth = month;

View File

@ -14,7 +14,7 @@ namespace {
} }
} }
constexpr std::array<const char*, 2> SettingTimeFormat::options; constexpr std::array<const char*, 3> SettingTimeFormat::options;
SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: Screen(app), settingsController {settingsController} { : Screen(app), settingsController {settingsController} {
@ -54,6 +54,8 @@ SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pi
lv_checkbox_set_checked(cbOption[0], true); lv_checkbox_set_checked(cbOption[0], true);
} else if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { } else if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
lv_checkbox_set_checked(cbOption[1], true); lv_checkbox_set_checked(cbOption[1], true);
} else if (settingsController.GetClockType() == Controllers::Settings::ClockType::UTC) {
lv_checkbox_set_checked(cbOption[2], true);
} }
} }
@ -74,6 +76,9 @@ void SettingTimeFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (i == 1) { if (i == 1) {
settingsController.SetClockType(Controllers::Settings::ClockType::H24); settingsController.SetClockType(Controllers::Settings::ClockType::H24);
}; };
if (i == 2) {
settingsController.SetClockType(Controllers::Settings::ClockType::UTC);
};
} else { } else {
lv_checkbox_set_checked(cbOption[i], false); lv_checkbox_set_checked(cbOption[i], false);

View File

@ -20,7 +20,7 @@ namespace Pinetime {
void UpdateSelected(lv_obj_t* object, lv_event_t event); void UpdateSelected(lv_obj_t* object, lv_event_t event);
private: private:
static constexpr std::array<const char*, 2> options = {" 12-hour", " 24-hour"}; static constexpr std::array<const char*, 3> options = {" 12-hour", " 24-hour", " UTC"};
Controllers::Settings& settingsController; Controllers::Settings& settingsController;
lv_obj_t* cbOption[options.size()]; lv_obj_t* cbOption[options.size()];
}; };