Skip to content

Commit 92aeae7

Browse files
committed
Merge branch 'timaios-set-datetime-manually' into develop
2 parents 977faeb + f2357b3 commit 92aeae7

10 files changed

Lines changed: 458 additions & 54 deletions

File tree

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ list(APPEND SOURCE_FILES
433433
displayapp/screens/settings/SettingDisplay.cpp
434434
displayapp/screens/settings/SettingSteps.cpp
435435
displayapp/screens/settings/SettingPineTimeStyle.cpp
436+
displayapp/screens/settings/SettingSetDate.cpp
437+
displayapp/screens/settings/SettingSetTime.cpp
436438

437439
## Watch faces
438440
displayapp/icons/bg_clock.c

src/components/datetime/DateTimeController.cpp

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
using namespace Pinetime::Controllers;
77

8+
namespace {
9+
char const* DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
10+
char const* MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
11+
char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
12+
}
13+
814
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
915
this->currentDateTime = t;
1016
UpdateTime(previousSystickCounter); // Update internal state without updating the time
@@ -80,48 +86,18 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
8086
}
8187

8288
const char* DateTime::MonthShortToString() {
83-
return DateTime::MonthsString[static_cast<uint8_t>(month)];
84-
}
85-
86-
const char* DateTime::MonthShortToStringLow() {
87-
return DateTime::MonthsStringLow[static_cast<uint8_t>(month)];
88-
}
89-
90-
const char* DateTime::MonthsToStringLow() {
91-
return DateTime::MonthsLow[static_cast<uint8_t>(month)];
92-
}
93-
94-
const char* DateTime::DayOfWeekToString() {
95-
return DateTime::DaysString[static_cast<uint8_t>(dayOfWeek)];
89+
return MonthsString[static_cast<uint8_t>(month)];
9690
}
9791

9892
const char* DateTime::DayOfWeekShortToString() {
99-
return DateTime::DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
93+
return DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
10094
}
10195

102-
const char* DateTime::DayOfWeekToStringLow() {
103-
return DateTime::DaysStringLow[static_cast<uint8_t>(dayOfWeek)];
104-
}
105-
106-
const char* DateTime::DayOfWeekShortToStringLow() {
107-
return DateTime::DaysStringShortLow[static_cast<uint8_t>(dayOfWeek)];
96+
const char* DateTime::MonthShortToStringLow(Months month) {
97+
return MonthsStringLow[static_cast<uint8_t>(month)];
10898
}
10999

110100
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
111101
this->systemTask = systemTask;
112102
}
113103

114-
char const* DateTime::DaysStringLow[] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
115-
116-
char const* DateTime::DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
117-
118-
char const* DateTime::DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
119-
120-
char const* DateTime::DaysString[] = {"--", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"};
121-
122-
char const* DateTime::MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
123-
124-
char const* DateTime::MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
125-
126-
char const* DateTime::MonthsLow[] = {
127-
"--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

src/components/datetime/DateTimeController.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ namespace Pinetime {
5959
}
6060

6161
const char* MonthShortToString();
62-
const char* MonthShortToStringLow();
63-
const char* MonthsToStringLow();
64-
const char* DayOfWeekToString();
6562
const char* DayOfWeekShortToString();
66-
const char* DayOfWeekToStringLow();
67-
const char* DayOfWeekShortToStringLow();
63+
static const char* MonthShortToStringLow(Months month);
6864

6965
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const {
7066
return currentDateTime;
@@ -91,14 +87,6 @@ namespace Pinetime {
9187

9288
bool isMidnightAlreadyNotified = false;
9389
System::SystemTask* systemTask = nullptr;
94-
95-
static char const* DaysString[];
96-
static char const* DaysStringShort[];
97-
static char const* DaysStringLow[];
98-
static char const* DaysStringShortLow[];
99-
static char const* MonthsString[];
100-
static char const* MonthsStringLow[];
101-
static char const* MonthsLow[];
10290
};
10391
}
104-
}
92+
}

src/displayapp/Apps.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ namespace Pinetime {
3232
SettingDisplay,
3333
SettingWakeUp,
3434
SettingSteps,
35-
SettingPineTimeStyle
35+
SettingPineTimeStyle,
36+
SettingSetDate,
37+
SettingSetTime
3638
};
3739
}
3840
}

src/displayapp/DisplayApp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "displayapp/screens/settings/SettingDisplay.h"
4545
#include "displayapp/screens/settings/SettingSteps.h"
4646
#include "displayapp/screens/settings/SettingPineTimeStyle.h"
47+
#include "displayapp/screens/settings/SettingSetDate.h"
48+
#include "displayapp/screens/settings/SettingSetTime.h"
4749

4850
#include "libs/lv_conf.h"
4951

@@ -365,6 +367,14 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
365367
currentScreen = std::make_unique<Screens::SettingSteps>(this, settingsController);
366368
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
367369
break;
370+
case Apps::SettingSetDate:
371+
currentScreen = std::make_unique<Screens::SettingSetDate>(this, dateTimeController);
372+
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
373+
break;
374+
case Apps::SettingSetTime:
375+
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController);
376+
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
377+
break;
368378
case Apps::SettingPineTimeStyle:
369379
currentScreen = std::make_unique<Screens::SettingPineTimeStyle>(this, settingsController);
370380
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#include "SettingSetDate.h"
2+
#include <lvgl/lvgl.h>
3+
#include <hal/nrf_rtc.h>
4+
#include <nrf_log.h>
5+
#include "displayapp/DisplayApp.h"
6+
#include "displayapp/screens/Symbols.h"
7+
8+
using namespace Pinetime::Applications::Screens;
9+
10+
namespace {
11+
constexpr int16_t POS_X_DAY = -72;
12+
constexpr int16_t POS_X_MONTH = 0;
13+
constexpr int16_t POS_X_YEAR = 72;
14+
constexpr int16_t POS_Y_PLUS = -50;
15+
constexpr int16_t POS_Y_TEXT = -6;
16+
constexpr int16_t POS_Y_MINUS = 40;
17+
18+
void event_handler(lv_obj_t * obj, lv_event_t event) {
19+
auto* screen = static_cast<SettingSetDate *>(obj->user_data);
20+
screen->HandleButtonPress(obj, event);
21+
}
22+
}
23+
24+
SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) :
25+
Screen(app),
26+
dateTimeController {dateTimeController} {
27+
lv_obj_t * title = lv_label_create(lv_scr_act(), nullptr);
28+
lv_label_set_text_static(title, "Set current date");
29+
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
30+
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);
31+
32+
lv_obj_t * icon = lv_label_create(lv_scr_act(), nullptr);
33+
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
34+
35+
lv_label_set_text_static(icon, Symbols::clock);
36+
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
37+
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
38+
39+
dayValue = static_cast<int>(dateTimeController.Day());
40+
lblDay = lv_label_create(lv_scr_act(), nullptr);
41+
lv_label_set_text_fmt(lblDay, "%d", dayValue);
42+
lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER);
43+
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
44+
lv_obj_set_auto_realign(lblDay, true);
45+
46+
monthValue = static_cast<int>(dateTimeController.Month());
47+
lblMonth = lv_label_create(lv_scr_act(), nullptr);
48+
UpdateMonthLabel();
49+
lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER);
50+
lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT);
51+
lv_obj_set_auto_realign(lblMonth, true);
52+
53+
yearValue = static_cast<int>(dateTimeController.Year());
54+
if (yearValue < 2021)
55+
yearValue = 2021;
56+
lblYear = lv_label_create(lv_scr_act(), nullptr);
57+
lv_label_set_text_fmt(lblYear, "%d", yearValue);
58+
lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER);
59+
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
60+
lv_obj_set_auto_realign(lblYear, true);
61+
62+
btnDayPlus = lv_btn_create(lv_scr_act(), nullptr);
63+
btnDayPlus->user_data = this;
64+
lv_obj_set_size(btnDayPlus, 50, 40);
65+
lv_obj_align(btnDayPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_PLUS);
66+
lv_obj_set_style_local_value_str(btnDayPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
67+
lv_obj_set_event_cb(btnDayPlus, event_handler);
68+
69+
btnDayMinus = lv_btn_create(lv_scr_act(), nullptr);
70+
btnDayMinus->user_data = this;
71+
lv_obj_set_size(btnDayMinus, 50, 40);
72+
lv_obj_align(btnDayMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_MINUS);
73+
lv_obj_set_style_local_value_str(btnDayMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
74+
lv_obj_set_event_cb(btnDayMinus, event_handler);
75+
76+
btnMonthPlus = lv_btn_create(lv_scr_act(), nullptr);
77+
btnMonthPlus->user_data = this;
78+
lv_obj_set_size(btnMonthPlus, 50, 40);
79+
lv_obj_align(btnMonthPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_PLUS);
80+
lv_obj_set_style_local_value_str(btnMonthPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
81+
lv_obj_set_event_cb(btnMonthPlus, event_handler);
82+
83+
btnMonthMinus = lv_btn_create(lv_scr_act(), nullptr);
84+
btnMonthMinus->user_data = this;
85+
lv_obj_set_size(btnMonthMinus, 50, 40);
86+
lv_obj_align(btnMonthMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_MINUS);
87+
lv_obj_set_style_local_value_str(btnMonthMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
88+
lv_obj_set_event_cb(btnMonthMinus, event_handler);
89+
90+
btnYearPlus = lv_btn_create(lv_scr_act(), nullptr);
91+
btnYearPlus->user_data = this;
92+
lv_obj_set_size(btnYearPlus, 50, 40);
93+
lv_obj_align(btnYearPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_PLUS);
94+
lv_obj_set_style_local_value_str(btnYearPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
95+
lv_obj_set_event_cb(btnYearPlus, event_handler);
96+
97+
btnYearMinus = lv_btn_create(lv_scr_act(), nullptr);
98+
btnYearMinus->user_data = this;
99+
lv_obj_set_size(btnYearMinus, 50, 40);
100+
lv_obj_align(btnYearMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_MINUS);
101+
lv_obj_set_style_local_value_str(btnYearMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
102+
lv_obj_set_event_cb(btnYearMinus, event_handler);
103+
104+
btnSetTime = lv_btn_create(lv_scr_act(), nullptr);
105+
btnSetTime->user_data = this;
106+
lv_obj_set_size(btnSetTime, 120, 48);
107+
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
108+
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
109+
lv_obj_set_event_cb(btnSetTime, event_handler);
110+
}
111+
112+
SettingSetDate::~SettingSetDate() {
113+
lv_obj_clean(lv_scr_act());
114+
}
115+
116+
void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
117+
if (event != LV_EVENT_CLICKED)
118+
return;
119+
120+
if (object == btnDayPlus) {
121+
dayValue++;
122+
if (dayValue > MaximumDayOfMonth())
123+
dayValue = 1;
124+
lv_label_set_text_fmt(lblDay, "%d", dayValue);
125+
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
126+
} else if (object == btnDayMinus) {
127+
dayValue--;
128+
if (dayValue < 1)
129+
dayValue = MaximumDayOfMonth();
130+
lv_label_set_text_fmt(lblDay, "%d", dayValue);
131+
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
132+
} else if (object == btnMonthPlus) {
133+
monthValue++;
134+
if (monthValue > 12)
135+
monthValue = 1;
136+
UpdateMonthLabel();
137+
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
138+
CheckDay();
139+
} else if (object == btnMonthMinus) {
140+
monthValue--;
141+
if (monthValue < 1)
142+
monthValue = 12;
143+
UpdateMonthLabel();
144+
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
145+
CheckDay();
146+
} else if (object == btnYearPlus) {
147+
yearValue++;
148+
lv_label_set_text_fmt(lblYear, "%d", yearValue);
149+
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
150+
CheckDay();
151+
} else if (object == btnYearMinus) {
152+
yearValue--;
153+
lv_label_set_text_fmt(lblYear, "%d", yearValue);
154+
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
155+
CheckDay();
156+
} else if (object == btnSetTime) {
157+
NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue);
158+
dateTimeController.SetTime(static_cast<uint16_t>(yearValue),
159+
static_cast<uint8_t>(monthValue),
160+
static_cast<uint8_t>(dayValue),
161+
0,
162+
dateTimeController.Hours(),
163+
dateTimeController.Minutes(),
164+
dateTimeController.Seconds(),
165+
nrf_rtc_counter_get(portNRF_RTC_REG));
166+
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
167+
}
168+
}
169+
170+
int SettingSetDate::MaximumDayOfMonth() const {
171+
switch (monthValue) {
172+
case 2:
173+
if ((((yearValue % 4) == 0) && ((yearValue % 100) != 0)) || ((yearValue % 400) == 0))
174+
return 29;
175+
return 28;
176+
case 4:
177+
case 6:
178+
case 9:
179+
case 11:
180+
return 30;
181+
default:
182+
return 31;
183+
}
184+
}
185+
186+
void SettingSetDate::CheckDay() {
187+
int maxDay = MaximumDayOfMonth();
188+
if (dayValue > maxDay) {
189+
dayValue = maxDay;
190+
lv_label_set_text_fmt(lblDay, "%d", dayValue);
191+
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
192+
}
193+
}
194+
195+
void SettingSetDate::UpdateMonthLabel() {
196+
lv_label_set_text_static(
197+
lblMonth, Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast<Pinetime::Controllers::DateTime::Months>(monthValue)));
198+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <lvgl/lvgl.h>
5+
#include "components/datetime/DateTimeController.h"
6+
#include "displayapp/screens/Screen.h"
7+
8+
namespace Pinetime {
9+
namespace Applications {
10+
namespace Screens {
11+
class SettingSetDate : public Screen{
12+
public:
13+
SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController);
14+
~SettingSetDate() override;
15+
16+
void HandleButtonPress(lv_obj_t *object, lv_event_t event);
17+
18+
private:
19+
Controllers::DateTime& dateTimeController;
20+
21+
int dayValue;
22+
int monthValue;
23+
int yearValue;
24+
lv_obj_t * lblDay;
25+
lv_obj_t * lblMonth;
26+
lv_obj_t * lblYear;
27+
lv_obj_t * btnDayPlus;
28+
lv_obj_t * btnDayMinus;
29+
lv_obj_t * btnMonthPlus;
30+
lv_obj_t * btnMonthMinus;
31+
lv_obj_t * btnYearPlus;
32+
lv_obj_t * btnYearMinus;
33+
lv_obj_t * btnSetTime;
34+
35+
int MaximumDayOfMonth() const;
36+
void CheckDay();
37+
void UpdateMonthLabel();
38+
};
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)