|
9 | 9 | using namespace Pinetime::Applications::Screens; |
10 | 10 |
|
11 | 11 | namespace { |
12 | | - constexpr int16_t POS_X_HOURS = -72; |
13 | | - constexpr int16_t POS_X_MINUTES = 0; |
14 | | - constexpr int16_t POS_X_SECONDS = 72; |
15 | | - constexpr int16_t POS_Y_PLUS = -50; |
16 | | - constexpr int16_t POS_Y_TEXT = -6; |
17 | | - constexpr int16_t POS_Y_MINUS = 40; |
18 | | - constexpr int16_t OFS_Y_COLON = -2; |
| 12 | + constexpr int16_t POS_Y_TEXT = -7; |
19 | 13 |
|
20 | | - void event_handler(lv_obj_t* obj, lv_event_t event) { |
| 14 | + void SetTimeEventHandler(lv_obj_t* obj, lv_event_t event) { |
21 | 15 | auto* screen = static_cast<SettingSetTime*>(obj->user_data); |
22 | | - screen->HandleButtonPress(obj, event); |
| 16 | + if (event == LV_EVENT_CLICKED) { |
| 17 | + screen->SetTime(); |
| 18 | + } |
| 19 | + } |
| 20 | + void ValueChangedHandler(void* userData) { |
| 21 | + auto* screen = static_cast<SettingSetTime*>(userData); |
| 22 | + screen->UpdateScreen(); |
23 | 23 | } |
24 | 24 | } |
25 | 25 |
|
26 | 26 | SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app, |
27 | 27 | Pinetime::Controllers::DateTime& dateTimeController, |
28 | 28 | Pinetime::Controllers::Settings& settingsController) |
29 | 29 | : Screen(app), dateTimeController {dateTimeController}, settingsController {settingsController} { |
| 30 | + |
30 | 31 | lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); |
31 | 32 | lv_label_set_text_static(title, "Set current time"); |
32 | 33 | lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); |
33 | 34 | lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); |
34 | 35 |
|
35 | 36 | lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); |
36 | 37 | lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); |
37 | | - |
38 | 38 | lv_label_set_text_static(icon, Symbols::clock); |
39 | 39 | lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); |
40 | 40 | lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); |
41 | 41 |
|
42 | | - hoursValue = static_cast<int>(dateTimeController.Hours()); |
43 | | - lblHours = lv_label_create(lv_scr_act(), nullptr); |
44 | | - lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); |
45 | | - lv_label_set_text_fmt(lblHours, "%02d", hoursValue); |
46 | | - lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); |
47 | | - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); |
48 | | - lv_obj_set_auto_realign(lblHours, true); |
49 | | - |
50 | | - lv_obj_t* lblColon1 = lv_label_create(lv_scr_act(), nullptr); |
51 | | - lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); |
52 | | - lv_label_set_text_static(lblColon1, ":"); |
53 | | - lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); |
54 | | - lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_HOURS + POS_X_MINUTES) / 2, POS_Y_TEXT + OFS_Y_COLON); |
| 42 | + lv_obj_t* staticLabel = lv_label_create(lv_scr_act(), nullptr); |
| 43 | + lv_obj_set_style_local_text_font(staticLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); |
| 44 | + lv_label_set_text_static(staticLabel, "00:00:00"); |
| 45 | + lv_obj_align(staticLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, POS_Y_TEXT); |
55 | 46 |
|
56 | | - minutesValue = static_cast<int>(dateTimeController.Minutes()); |
57 | | - lblMinutes = lv_label_create(lv_scr_act(), nullptr); |
58 | | - lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); |
59 | | - lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); |
60 | | - lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); |
61 | | - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); |
62 | | - lv_obj_set_auto_realign(lblMinutes, true); |
63 | | - |
64 | | - lv_obj_t* lblColon2 = lv_label_create(lv_scr_act(), nullptr); |
65 | | - lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); |
66 | | - lv_label_set_text_static(lblColon2, ":"); |
67 | | - lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); |
68 | | - lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON); |
| 47 | + hourCounter.Create(); |
| 48 | + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { |
| 49 | + hourCounter.EnableTwelveHourMode(); |
| 50 | + } |
| 51 | + hourCounter.SetValue(dateTimeController.Hours()); |
| 52 | + lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_CENTER, -75, POS_Y_TEXT); |
| 53 | + hourCounter.SetValueChangedEventCallback(this, ValueChangedHandler); |
69 | 54 |
|
70 | | - lv_obj_t* lblSeconds = lv_label_create(lv_scr_act(), nullptr); |
71 | | - lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); |
72 | | - lv_label_set_text_static(lblSeconds, "00"); |
73 | | - lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); |
74 | | - lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT); |
| 55 | + minuteCounter.Create(); |
| 56 | + minuteCounter.SetValue(dateTimeController.Minutes()); |
| 57 | + lv_obj_align(minuteCounter.GetObject(), nullptr, LV_ALIGN_CENTER, 0, POS_Y_TEXT); |
| 58 | + minuteCounter.SetValueChangedEventCallback(this, ValueChangedHandler); |
75 | 59 |
|
76 | 60 | lblampm = lv_label_create(lv_scr_act(), nullptr); |
77 | 61 | lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); |
78 | 62 | lv_label_set_text_static(lblampm, " "); |
79 | | - lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER); |
80 | | - lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_PLUS); |
81 | | - |
82 | | - btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr); |
83 | | - btnHoursPlus->user_data = this; |
84 | | - lv_obj_set_size(btnHoursPlus, 50, 40); |
85 | | - lv_obj_align(btnHoursPlus, lv_scr_act(), LV_ALIGN_CENTER, -72, -50); |
86 | | - lv_obj_set_style_local_value_str(btnHoursPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); |
87 | | - lv_obj_set_event_cb(btnHoursPlus, event_handler); |
88 | | - |
89 | | - btnHoursMinus = lv_btn_create(lv_scr_act(), nullptr); |
90 | | - btnHoursMinus->user_data = this; |
91 | | - lv_obj_set_size(btnHoursMinus, 50, 40); |
92 | | - lv_obj_align(btnHoursMinus, lv_scr_act(), LV_ALIGN_CENTER, -72, 40); |
93 | | - lv_obj_set_style_local_value_str(btnHoursMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); |
94 | | - lv_obj_set_event_cb(btnHoursMinus, event_handler); |
95 | | - |
96 | | - btnMinutesPlus = lv_btn_create(lv_scr_act(), nullptr); |
97 | | - btnMinutesPlus->user_data = this; |
98 | | - lv_obj_set_size(btnMinutesPlus, 50, 40); |
99 | | - lv_obj_align(btnMinutesPlus, lv_scr_act(), LV_ALIGN_CENTER, 0, -50); |
100 | | - lv_obj_set_style_local_value_str(btnMinutesPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); |
101 | | - lv_obj_set_event_cb(btnMinutesPlus, event_handler); |
102 | | - |
103 | | - btnMinutesMinus = lv_btn_create(lv_scr_act(), nullptr); |
104 | | - btnMinutesMinus->user_data = this; |
105 | | - lv_obj_set_size(btnMinutesMinus, 50, 40); |
106 | | - lv_obj_align(btnMinutesMinus, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); |
107 | | - lv_obj_set_style_local_value_str(btnMinutesMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); |
108 | | - lv_obj_set_event_cb(btnMinutesMinus, event_handler); |
| 63 | + lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 75, -50); |
109 | 64 |
|
110 | 65 | btnSetTime = lv_btn_create(lv_scr_act(), nullptr); |
111 | 66 | btnSetTime->user_data = this; |
112 | | - lv_obj_set_size(btnSetTime, 120, 48); |
| 67 | + lv_obj_set_size(btnSetTime, 120, 50); |
113 | 68 | lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); |
114 | 69 | lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); |
115 | | - lv_obj_set_event_cb(btnSetTime, event_handler); |
| 70 | + lv_obj_set_style_local_bg_color(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x38, 0x38, 0x38)); |
| 71 | + lv_obj_set_style_local_bg_color(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_MAKE(0x18, 0x18, 0x18)); |
| 72 | + lv_obj_set_style_local_value_color(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_GRAY); |
| 73 | + lv_obj_set_event_cb(btnSetTime, SetTimeEventHandler); |
116 | 74 |
|
117 | | - SetHourLabels(); |
| 75 | + UpdateScreen(); |
| 76 | + lv_obj_set_state(btnSetTime, LV_STATE_DISABLED); |
118 | 77 | } |
119 | 78 |
|
120 | 79 | SettingSetTime::~SettingSetTime() { |
121 | 80 | lv_obj_clean(lv_scr_act()); |
122 | 81 | } |
123 | 82 |
|
124 | | -void SettingSetTime::SetHourLabels() { |
| 83 | +void SettingSetTime::UpdateScreen() { |
125 | 84 | if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { |
126 | | - switch (hoursValue) { |
127 | | - case 0: |
128 | | - lv_label_set_text_static(lblHours, "12"); |
129 | | - lv_label_set_text_static(lblampm, "AM"); |
130 | | - break; |
131 | | - case 1 ... 11: |
132 | | - lv_label_set_text_fmt(lblHours, "%02d", hoursValue); |
133 | | - lv_label_set_text_static(lblampm, "AM"); |
134 | | - break; |
135 | | - case 12: |
136 | | - lv_label_set_text_static(lblHours, "12"); |
137 | | - lv_label_set_text_static(lblampm, "PM"); |
138 | | - break; |
139 | | - case 13 ... 23: |
140 | | - lv_label_set_text_fmt(lblHours, "%02d", hoursValue - 12); |
141 | | - lv_label_set_text_static(lblampm, "PM"); |
142 | | - break; |
| 85 | + if (hourCounter.GetValue() >= 12) { |
| 86 | + lv_label_set_text_static(lblampm, "PM"); |
| 87 | + } else { |
| 88 | + lv_label_set_text_static(lblampm, "AM"); |
143 | 89 | } |
144 | | - } else { |
145 | | - lv_label_set_text_fmt(lblHours, "%02d", hoursValue); |
146 | 90 | } |
| 91 | + lv_obj_set_state(btnSetTime, LV_STATE_DEFAULT); |
147 | 92 | } |
148 | 93 |
|
149 | | -void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) { |
150 | | - if (event != LV_EVENT_CLICKED) |
151 | | - return; |
152 | | - |
153 | | - if (object == btnHoursPlus) { |
154 | | - hoursValue++; |
155 | | - if (hoursValue > 23) { |
156 | | - hoursValue = 0; |
157 | | - } |
158 | | - SetHourLabels(); |
159 | | - lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); |
160 | | - } else if (object == btnHoursMinus) { |
161 | | - hoursValue--; |
162 | | - if (hoursValue < 0) { |
163 | | - hoursValue = 23; |
164 | | - } |
165 | | - SetHourLabels(); |
166 | | - lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); |
167 | | - } else if (object == btnMinutesPlus) { |
168 | | - minutesValue++; |
169 | | - if (minutesValue > 59) { |
170 | | - minutesValue = 0; |
171 | | - } |
172 | | - lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); |
173 | | - lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); |
174 | | - } else if (object == btnMinutesMinus) { |
175 | | - minutesValue--; |
176 | | - if (minutesValue < 0) { |
177 | | - minutesValue = 59; |
178 | | - } |
179 | | - lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); |
180 | | - lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); |
181 | | - } else if (object == btnSetTime) { |
182 | | - NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); |
183 | | - dateTimeController.SetTime(dateTimeController.Year(), |
184 | | - static_cast<uint8_t>(dateTimeController.Month()), |
185 | | - dateTimeController.Day(), |
186 | | - static_cast<uint8_t>(dateTimeController.DayOfWeek()), |
187 | | - static_cast<uint8_t>(hoursValue), |
188 | | - static_cast<uint8_t>(minutesValue), |
189 | | - 0, |
190 | | - nrf_rtc_counter_get(portNRF_RTC_REG)); |
191 | | - lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED); |
192 | | - } |
| 94 | +void SettingSetTime::SetTime() { |
| 95 | + const int hoursValue = hourCounter.GetValue(); |
| 96 | + const int minutesValue = minuteCounter.GetValue(); |
| 97 | + NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); |
| 98 | + dateTimeController.SetTime(dateTimeController.Year(), |
| 99 | + static_cast<uint8_t>(dateTimeController.Month()), |
| 100 | + dateTimeController.Day(), |
| 101 | + static_cast<uint8_t>(dateTimeController.DayOfWeek()), |
| 102 | + static_cast<uint8_t>(hoursValue), |
| 103 | + static_cast<uint8_t>(minutesValue), |
| 104 | + 0, |
| 105 | + nrf_rtc_counter_get(portNRF_RTC_REG)); |
| 106 | + lv_obj_set_state(btnSetTime, LV_STATE_DISABLED); |
193 | 107 | } |
0 commit comments