fix for week number and days till the end of the year

+ formating (clang)
This commit is contained in:
ITCactus 2022-05-25 13:44:25 +02:00
parent e7c0b2c5c2
commit cfaafc1fe2
4 changed files with 48 additions and 52 deletions

View file

@ -20,10 +20,13 @@ CheckboxList::CheckboxList(const uint8_t screenID,
const char* optionsTitle, const char* optionsTitle,
const char* optionsSymbol, const char* optionsSymbol,
void (Controllers::Settings::*SetOptionIndex)(uint8_t), void (Controllers::Settings::*SetOptionIndex)(uint8_t),
uint8_t (Controllers::Settings::*GetOptionIndex )() const, uint8_t (Controllers::Settings::*GetOptionIndex)() const,
std::array<const char*, MAXLISTITEMS> options) std::array<const char*, MAXLISTITEMS> options)
: Screen(app), screenID {screenID}, settingsController {settingsController}, : Screen(app),
SetOptionIndex {SetOptionIndex}, GetOptionIndex {GetOptionIndex}, screenID {screenID},
settingsController {settingsController},
SetOptionIndex {SetOptionIndex},
GetOptionIndex {GetOptionIndex},
options {options} { options {options} {
settingsController.SetWatchfacesMenu(screenID); settingsController.SetWatchfacesMenu(screenID);
@ -87,7 +90,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
lv_obj_set_event_cb(cbOption[i], event_handler); lv_obj_set_event_cb(cbOption[i], event_handler);
SetRadioButtonStyle(cbOption[i]); SetRadioButtonStyle(cbOption[i]);
if (static_cast<unsigned int>((settingsController.*GetOptionIndex)() - MAXLISTITEMS*screenID) == i) { if (static_cast<unsigned int>((settingsController.*GetOptionIndex)() - MAXLISTITEMS * screenID) == i) {
lv_checkbox_set_checked(cbOption[i], true); lv_checkbox_set_checked(cbOption[i], true);
} }
} }
@ -105,7 +108,7 @@ void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (strcmp(options[i], "")) { if (strcmp(options[i], "")) {
if (object == cbOption[i]) { if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true); lv_checkbox_set_checked(cbOption[i], true);
(settingsController.*SetOptionIndex)(MAXLISTITEMS*screenID + i); (settingsController.*SetOptionIndex)(MAXLISTITEMS * screenID + i);
} else { } else {
lv_checkbox_set_checked(cbOption[i], false); lv_checkbox_set_checked(cbOption[i], false);
} }

View file

@ -16,13 +16,13 @@
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app, WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app,
Controllers::DateTime& dateTimeController, Controllers::DateTime& dateTimeController,
Controllers::Battery& batteryController, Controllers::Battery& batteryController,
Controllers::Ble& bleController, Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager, Controllers::NotificationManager& notificatioManager,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController, Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController) Controllers::MotionController& motionController)
: Screen(app), : Screen(app),
currentDateTime {{}}, currentDateTime {{}},
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
@ -33,7 +33,6 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app,
heartRateController {heartRateController}, heartRateController {heartRateController},
motionController {motionController} { motionController {motionController} {
label_battery_vallue = lv_label_create(lv_scr_act(), nullptr); label_battery_vallue = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(label_battery_vallue, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); lv_obj_align(label_battery_vallue, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
@ -163,7 +162,7 @@ WatchFaceCasioStyleG7710::~WatchFaceCasioStyleG7710() {
lv_style_reset(&style_line); lv_style_reset(&style_line);
lv_style_reset(&style_border); lv_style_reset(&style_border);
lv_obj_clean(lv_scr_act()); lv_obj_clean(lv_scr_act());
} }
@ -240,30 +239,30 @@ void WatchFaceCasioStyleG7710::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) { if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
// 24h mode: ddmmyyyy, first DOW=Monday; // 24h mode: ddmmyyyy, first DOW=Monday;
lv_label_set_text_fmt( lv_label_set_text_fmt(label_date, "%3d-%2d", day, month);
label_date, "%3d-%2d", day, month); weekNumberFormat = "%V"; // Replaced by the week number of the year (Monday as the first day of the week) as a decimal number
weekNumberFormat = "%V"; // Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday] // [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered
// week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January
// 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday]
} else { } else {
// 12h mode: mmddyyyy, first DOW=Sunday; // 12h mode: mmddyyyy, first DOW=Sunday;
lv_label_set_text_fmt( lv_label_set_text_fmt(label_date, "%3d-%2d", month, day);
label_date, "%3d-%2d", month, day); weekNumberFormat = "%U"; // Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the
weekNumberFormat = "%U"; // Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday] // first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
} }
uint8_t weekNumber; uint8_t weekNumber;
uint16_t dayOfYearNumber, daysTillEndOfYearNumber; uint16_t dayOfYearNumber, daysTillEndOfYearNumber;
std::tm date = {}; time_t ttTime =
date.tm_year = year - 1900; std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(currentDateTime.Get()));
date.tm_mon = static_cast<unsigned>(yearMonthDay.month()) - 1; tm* tmTime = std::localtime(&ttTime);
date.tm_mday = day + 1;
std::mktime( &date );
dayOfYearNumber = date.tm_yday; dayOfYearNumber = tmTime->tm_yday + 1; // tm_yday day of year [0,365] => yday+1
daysTillEndOfYearNumber = yearMonthDay.year().is_leap() ? 366 : 365 - dayOfYearNumber; daysTillEndOfYearNumber = (yearMonthDay.year().is_leap() ? 366 : 365) - dayOfYearNumber;
char buffer[8]; char buffer[8];
strftime(buffer, 8, weekNumberFormat, &date); strftime(buffer, 8, weekNumberFormat, tmTime);
weekNumber = atoi(buffer); weekNumber = atoi(buffer);
lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString()); lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString());

View file

@ -25,13 +25,13 @@ namespace Pinetime {
class WatchFaceCasioStyleG7710 : public Screen { class WatchFaceCasioStyleG7710 : public Screen {
public: public:
WatchFaceCasioStyleG7710(DisplayApp* app, WatchFaceCasioStyleG7710(DisplayApp* app,
Controllers::DateTime& dateTimeController, Controllers::DateTime& dateTimeController,
Controllers::Battery& batteryController, Controllers::Battery& batteryController,
Controllers::Ble& bleController, Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager, Controllers::NotificationManager& notificatioManager,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController, Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController); Controllers::MotionController& motionController);
~WatchFaceCasioStyleG7710() override; ~WatchFaceCasioStyleG7710() override;
void Refresh() override; void Refresh() override;
@ -62,7 +62,7 @@ namespace Pinetime {
lv_point_t line_date_points[3] {{0, 5}, {135, 5}, {140, 0}}; lv_point_t line_date_points[3] {{0, 5}, {135, 5}, {140, 0}};
lv_point_t line_time_points[3] {{0, 0}, {230, 0}, {235, 5}}; lv_point_t line_time_points[3] {{0, 0}, {230, 0}, {235, 5}};
lv_color_t color_text = lv_color_hex(0x98B69A); lv_color_t color_text = lv_color_hex(0x98B69A);
lv_style_t style_line; lv_style_t style_line;
lv_style_t style_border; lv_style_t style_border;

View file

@ -17,14 +17,12 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine
settingsController {settingsController}, settingsController {settingsController},
screens {app, screens {app,
settingsController.GetWatchfacesMenu(), settingsController.GetWatchfacesMenu(),
{ {[this]() -> std::unique_ptr<Screen> {
[this]() -> std::unique_ptr<Screen> { return CreateScreen1();
return CreateScreen1(); },
}, [this]() -> std::unique_ptr<Screen> {
[this]() -> std::unique_ptr<Screen> { return CreateScreen2();
return CreateScreen2(); }},
}
},
Screens::ScreenListModes::UpDown} { Screens::ScreenListModes::UpDown} {
} }
@ -39,16 +37,12 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() { std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
std::array<const char*, 4> watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; std::array<const char*, 4> watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"};
return std::make_unique<Screens::CheckboxList>(0, 2, app, settingsController, title, return std::make_unique<Screens::CheckboxList>(
symbol, &Controllers::Settings::SetClockFace, 0, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces);
&Controllers::Settings::GetClockFace,
watchfaces);
} }
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() { std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
std::array<const char*, 4> watchfaces {" Casio G7710", "", "", ""}; std::array<const char*, 4> watchfaces {" Casio G7710", "", "", ""};
return std::make_unique<Screens::CheckboxList>(1, 2, app, settingsController, title, return std::make_unique<Screens::CheckboxList>(
symbol, &Controllers::Settings::SetClockFace, 1, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces);
&Controllers::Settings::GetClockFace,
watchfaces);
} }