Skip to content

Commit bfe13d9

Browse files
committed
Fixes based on code reviews (formatting, UI code)
1 parent 1fb5757 commit bfe13d9

5 files changed

Lines changed: 133 additions & 89 deletions

File tree

src/components/alarm/AlarmController.cpp

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
//
2-
// Created by mrussell on 30.08.21.
3-
//
4-
// Copied from Florian's Timer app
5-
1+
/* Copyright (C) 2021 JF, Adam Pigg, Avamander
2+
This file is part of InfiniTime.
3+
InfiniTime is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published
5+
by the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
InfiniTime is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
You should have received a copy of the GNU General Public License
12+
along with this program. If not, see <https://www.gnu.org/licenses/>.
13+
*/
614
#include "AlarmController.h"
715
#include "systemtask/SystemTask.h"
816
#include "app_timer.h"
@@ -25,18 +33,19 @@ namespace {
2533
}
2634
}
2735

28-
void AlarmController::Init() {
36+
void AlarmController::Init(System::SystemTask* systemTask) {
2937
app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm);
38+
this->systemTask = systemTask;
3039
}
3140

3241
void AlarmController::SetAlarm(uint8_t alarmHr, uint8_t alarmMin) {
3342
hours = alarmHr;
3443
minutes = alarmMin;
3544
state = AlarmState::Set;
36-
scheduleAlarm();
45+
ScheduleAlarm();
3746
}
3847

39-
void AlarmController::scheduleAlarm() {
48+
void AlarmController::ScheduleAlarm() {
4049
// Determine the next time the alarm needs to go off and set the app_timer
4150
app_timer_stop(alarmAppTimer);
4251

@@ -83,36 +92,18 @@ void AlarmController::DisableAlarm() {
8392

8493
void AlarmController::SetOffAlarmNow() {
8594
state = AlarmState::Alerting;
86-
if (systemTask != nullptr) {
87-
systemTask->PushMessage(System::Messages::SetOffAlarm);
88-
}
95+
systemTask->PushMessage(System::Messages::SetOffAlarm);
8996
}
9097

9198
void AlarmController::StopAlerting() {
92-
if (systemTask != nullptr) {
93-
systemTask->PushMessage(System::Messages::StopRinging);
94-
}
99+
systemTask->PushMessage(System::Messages::StopRinging);
95100

96101
// Alarm state is off unless this is a recurring alarm
97102
if (recurrence == RecurType::None) {
98103
state = AlarmState::Not_Set;
99104
} else {
100105
state = AlarmState::Set;
101106
// set next instance
102-
scheduleAlarm();
107+
ScheduleAlarm();
103108
}
104109
}
105-
106-
void AlarmController::ToggleRecurrence() {
107-
if (recurrence == AlarmController::RecurType::None) {
108-
recurrence = AlarmController::RecurType::Daily;
109-
} else if (recurrence == AlarmController::RecurType::Daily) {
110-
recurrence = AlarmController::RecurType::Weekdays;
111-
} else {
112-
recurrence = AlarmController::RecurType::None;
113-
}
114-
}
115-
116-
void AlarmController::Register(Pinetime::System::SystemTask* systemTask) {
117-
this->systemTask = systemTask;
118-
}

src/components/alarm/AlarmController.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/* Copyright (C) 2021 JF, Adam Pigg, Avamander
2+
This file is part of InfiniTime.
3+
InfiniTime is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published
5+
by the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
InfiniTime is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
You should have received a copy of the GNU General Public License
12+
along with this program. If not, see <https://www.gnu.org/licenses/>.
13+
*/
114
#pragma once
215

316
#include <cstdint>
@@ -13,16 +26,14 @@ namespace Pinetime {
1326
public:
1427
AlarmController(Controllers::DateTime& dateTimeController);
1528

16-
void Init();
29+
void Init(System::SystemTask* systemTask);
1730
void SetAlarm(uint8_t alarmHr, uint8_t alarmMin);
1831
void DisableAlarm();
1932
void SetOffAlarmNow();
2033
uint32_t SecondsToAlarm();
2134
void StopAlerting();
22-
void Register(System::SystemTask* systemTask);
2335
enum class AlarmState { Not_Set, Set, Alerting };
2436
enum class RecurType { None, Daily, Weekdays };
25-
void ToggleRecurrence();
2637
uint8_t Hours() const {
2738
return hours;
2839
}
@@ -35,16 +46,19 @@ namespace Pinetime {
3546
RecurType Recurrence() const {
3647
return recurrence;
3748
}
49+
void SetRecurrence(RecurType recurType) {
50+
recurrence = recurType;
51+
}
3852

3953
private:
4054
Controllers::DateTime& dateTimeController;
4155
System::SystemTask* systemTask = nullptr;
4256
uint8_t hours;
4357
uint8_t minutes;
4458
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
45-
AlarmState state = AlarmState::Not_Set;
59+
AlarmState state = AlarmState::Not_Set;
4660
RecurType recurrence = RecurType::None;
47-
void scheduleAlarm();
61+
void ScheduleAlarm();
4862
};
4963
}
50-
}
64+
}

src/displayapp/screens/Alarm.cpp

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/* Copyright (C) 2021 JF, Adam Pigg, Avamander
2+
This file is part of InfiniTime.
3+
InfiniTime is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published
5+
by the Free Software Foundation, either version 3 of the License, or
6+
(at your option) any later version.
7+
InfiniTime is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
You should have received a copy of the GNU General Public License
12+
along with this program. If not, see <https://www.gnu.org/licenses/>.
13+
*/
114
#include "Alarm.h"
215
#include "Screen.h"
316
#include "Symbols.h"
@@ -21,66 +34,61 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)
2134
alarmMinutes = alarmController.Minutes();
2235
lv_label_set_text_fmt(time, "%02lu:%02lu", alarmHours, alarmMinutes);
2336

24-
lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
37+
lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -25);
2538

2639
btnHoursUp = lv_btn_create(lv_scr_act(), nullptr);
2740
btnHoursUp->user_data = this;
2841
lv_obj_set_event_cb(btnHoursUp, btnEventHandler);
29-
lv_obj_align(btnHoursUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -80);
30-
lv_obj_set_height(btnHoursUp, 40);
31-
lv_obj_set_width(btnHoursUp, 60);
42+
lv_obj_set_size(btnHoursUp, 60, 40);
43+
lv_obj_align(btnHoursUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -85);
3244
txtHrUp = lv_label_create(btnHoursUp, nullptr);
3345
lv_label_set_text(txtHrUp, "+");
3446

3547
btnHoursDown = lv_btn_create(lv_scr_act(), nullptr);
3648
btnHoursDown->user_data = this;
3749
lv_obj_set_event_cb(btnHoursDown, btnEventHandler);
38-
lv_obj_align(btnHoursDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, +40);
39-
lv_obj_set_height(btnHoursDown, 40);
40-
lv_obj_set_width(btnHoursDown, 60);
50+
lv_obj_set_size(btnHoursDown, 60, 40);
51+
lv_obj_align(btnHoursDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, 35);
4152
txtHrDown = lv_label_create(btnHoursDown, nullptr);
4253
lv_label_set_text(txtHrDown, "-");
4354

4455
btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr);
4556
btnMinutesUp->user_data = this;
4657
lv_obj_set_event_cb(btnMinutesUp, btnEventHandler);
47-
lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, -80);
48-
lv_obj_set_height(btnMinutesUp, 40);
49-
lv_obj_set_width(btnMinutesUp, 60);
58+
lv_obj_set_size(btnMinutesUp, 60, 40);
59+
lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, -85);
5060
txtMinUp = lv_label_create(btnMinutesUp, nullptr);
5161
lv_label_set_text(txtMinUp, "+");
5262

5363
btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr);
5464
btnMinutesDown->user_data = this;
5565
lv_obj_set_event_cb(btnMinutesDown, btnEventHandler);
56-
lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, +40);
57-
lv_obj_set_height(btnMinutesDown, 40);
58-
lv_obj_set_width(btnMinutesDown, 60);
66+
lv_obj_set_size(btnMinutesDown, 60, 40);
67+
lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, 35);
5968
txtMinDown = lv_label_create(btnMinutesDown, nullptr);
6069
lv_label_set_text(txtMinDown, "-");
6170

6271
btnEnable = lv_btn_create(lv_scr_act(), nullptr);
6372
btnEnable->user_data = this;
6473
lv_obj_set_event_cb(btnEnable, btnEventHandler);
65-
lv_obj_align(btnEnable, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 3, -10);
66-
lv_obj_set_height(btnEnable, 40);
74+
lv_obj_set_size(btnEnable, 115, 50);
75+
lv_obj_align(btnEnable, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
6776
txtEnable = lv_label_create(btnEnable, nullptr);
68-
setEnableButtonState();
77+
SetEnableButtonState();
6978

7079
btnRecur = lv_btn_create(lv_scr_act(), nullptr);
7180
btnRecur->user_data = this;
7281
lv_obj_set_event_cb(btnRecur, btnEventHandler);
73-
lv_obj_align(btnRecur, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -3, -10);
74-
lv_obj_set_height(btnRecur, 40);
82+
lv_obj_set_size(btnRecur, 115, 50);
83+
lv_obj_align(btnRecur, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
7584
txtRecur = lv_label_create(btnRecur, nullptr);
76-
setRecurButtonState();
85+
SetRecurButtonState();
7786

7887
btnInfo = lv_btn_create(lv_scr_act(), nullptr);
7988
btnInfo->user_data = this;
8089
lv_obj_set_event_cb(btnInfo, btnEventHandler);
81-
lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 30, -80);
82-
lv_obj_set_height(btnInfo, 40);
83-
lv_obj_set_width(btnInfo, 30);
90+
lv_obj_set_size(btnInfo, 50, 40);
91+
lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 0, -85);
8492
txtInfo = lv_label_create(btnInfo, nullptr);
8593
lv_label_set_text(txtInfo, "i");
8694
}
@@ -100,11 +108,11 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
100108
} else {
101109
alarmController.SetAlarm(alarmHours, alarmMinutes);
102110
}
103-
setEnableButtonState();
111+
SetEnableButtonState();
104112
return;
105113
}
106114
if (obj == btnInfo) {
107-
showInfo();
115+
ShowInfo();
108116
return;
109117
}
110118
if (obj == btnMessage) {
@@ -120,7 +128,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
120128
// can just do it once when the alarm is re-enabled
121129
if (alarmController.State() == AlarmController::AlarmState::Set) {
122130
alarmController.DisableAlarm();
123-
setEnableButtonState();
131+
SetEnableButtonState();
124132
}
125133
if (obj == btnMinutesUp) {
126134
if (alarmMinutes >= 59) {
@@ -159,17 +167,16 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
159167
return;
160168
}
161169
if (obj == btnRecur) {
162-
alarmController.ToggleRecurrence();
163-
setRecurButtonState();
170+
ToggleRecurrence();
164171
}
165172
}
166173
}
167174

168175
void Alarm::SetAlerting() {
169-
setEnableButtonState();
176+
SetEnableButtonState();
170177
}
171178

172-
void Alarm::setEnableButtonState() {
179+
void Alarm::SetEnableButtonState() {
173180
switch (alarmController.State()) {
174181
case AlarmController::AlarmState::Set:
175182
lv_label_set_text(txtEnable, "ON");
@@ -185,7 +192,7 @@ void Alarm::setEnableButtonState() {
185192
}
186193
}
187194

188-
void Alarm::showInfo() {
195+
void Alarm::ShowInfo() {
189196
btnMessage = lv_btn_create(lv_scr_act(), nullptr);
190197
btnMessage->user_data = this;
191198
lv_obj_set_event_cb(btnMessage, btnEventHandler);
@@ -210,7 +217,7 @@ void Alarm::showInfo() {
210217
}
211218
}
212219

213-
void Alarm::setRecurButtonState() {
220+
void Alarm::SetRecurButtonState() {
214221
using Pinetime::Controllers::AlarmController;
215222
switch (alarmController.Recurrence()) {
216223
case AlarmController::RecurType::None:
@@ -220,6 +227,21 @@ void Alarm::setRecurButtonState() {
220227
lv_label_set_text(txtRecur, "DAILY");
221228
break;
222229
case AlarmController::RecurType::Weekdays:
223-
lv_label_set_text(txtRecur, "WKDAYS");
230+
lv_label_set_text(txtRecur, "MON-FRI");
224231
}
225-
}
232+
}
233+
234+
void Alarm::ToggleRecurrence() {
235+
using Pinetime::Controllers::AlarmController;
236+
switch (alarmController.Recurrence()) {
237+
case AlarmController::RecurType::None:
238+
alarmController.SetRecurrence(AlarmController::RecurType::Daily);
239+
break;
240+
case AlarmController::RecurType::Daily:
241+
alarmController.SetRecurrence(AlarmController::RecurType::Weekdays);
242+
break;
243+
case AlarmController::RecurType::Weekdays:
244+
alarmController.SetRecurrence(AlarmController::RecurType::None);
245+
}
246+
SetRecurButtonState();
247+
}

0 commit comments

Comments
 (0)