Skip to content

Commit cf9e149

Browse files
committed
Merge with develop and fix conflicts from timaios:set-datetime-manually.
2 parents 977faeb + 3e9c30a commit cf9e149

10 files changed

Lines changed: 508 additions & 8 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: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,34 @@ const char* DateTime::DayOfWeekShortToStringLow() {
107107
return DateTime::DaysStringShortLow[static_cast<uint8_t>(dayOfWeek)];
108108
}
109109

110+
const char* DateTime::MonthShortToString(Months month) {
111+
return DateTime::MonthsString[static_cast<uint8_t>(month)];
112+
}
113+
114+
const char* DateTime::MonthShortToStringLow(Months month) {
115+
return DateTime::MonthsStringLow[static_cast<uint8_t>(month)];
116+
}
117+
118+
const char* DateTime::MonthsToStringLow(Months month) {
119+
return DateTime::MonthsLow[static_cast<uint8_t>(month)];
120+
}
121+
122+
const char* DateTime::DayOfWeekToString(Days dayOfWeek) {
123+
return DateTime::DaysString[static_cast<uint8_t>(dayOfWeek)];
124+
}
125+
126+
const char* DateTime::DayOfWeekShortToString(Days dayOfWeek) {
127+
return DateTime::DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
128+
}
129+
130+
const char* DateTime::DayOfWeekToStringLow(Days dayOfWeek) {
131+
return DateTime::DaysStringLow[static_cast<uint8_t>(dayOfWeek)];
132+
}
133+
134+
const char* DateTime::DayOfWeekShortToStringLow(Days dayOfWeek) {
135+
return DateTime::DaysStringShortLow[static_cast<uint8_t>(dayOfWeek)];
136+
}
137+
110138
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
111139
this->systemTask = systemTask;
112140
}
@@ -124,4 +152,4 @@ char const* DateTime::MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY",
124152
char const* DateTime::MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
125153

126154
char const* DateTime::MonthsLow[] = {
127-
"--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
155+
"--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

src/components/datetime/DateTimeController.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ namespace Pinetime {
6666
const char* DayOfWeekToStringLow();
6767
const char* DayOfWeekShortToStringLow();
6868

69+
static const char* MonthShortToString(Months month);
70+
static const char* MonthShortToStringLow(Months month);
71+
static const char* MonthsToStringLow(Months month);
72+
static const char* DayOfWeekToString(Days dayOfWeek);
73+
static const char* DayOfWeekShortToString(Days dayOfWeek);
74+
static const char* DayOfWeekToStringLow(Days dayOfWeek);
75+
static const char* DayOfWeekShortToStringLow(Days dayOfWeek);
76+
6977
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const {
7078
return currentDateTime;
7179
}
@@ -101,4 +109,4 @@ namespace Pinetime {
101109
static char const* MonthsLow[];
102110
};
103111
}
104-
}
112+
}

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

0 commit comments

Comments
 (0)