Skip to content

Commit f857a75

Browse files
committed
Fixes per Riksu9000's feedback
1 parent 2bf339a commit f857a75

7 files changed

Lines changed: 27 additions & 30 deletions

File tree

src/components/alarm/AlarmController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ void AlarmController::Init(System::SystemTask* systemTask) {
4343
this->systemTask = systemTask;
4444
}
4545

46-
void AlarmController::SetAlarm(uint8_t alarmHr, uint8_t alarmMin) {
46+
void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
4747
hours = alarmHr;
4848
minutes = alarmMin;
49-
state = AlarmState::Set;
50-
ScheduleAlarm();
5149
}
5250

5351
void AlarmController::ScheduleAlarm() {
@@ -84,6 +82,8 @@ void AlarmController::ScheduleAlarm() {
8482
alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime));
8583
auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count();
8684
app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this);
85+
86+
state = AlarmState::Set;
8787
}
8888

8989
uint32_t AlarmController::SecondsToAlarm() {

src/components/alarm/AlarmController.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace Pinetime {
3131
AlarmController(Controllers::DateTime& dateTimeController);
3232

3333
void Init(System::SystemTask* systemTask);
34-
void SetAlarm(uint8_t alarmHr, uint8_t alarmMin);
34+
void SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin);
35+
void ScheduleAlarm();
3536
void DisableAlarm();
3637
void SetOffAlarmNow();
3738
uint32_t SecondsToAlarm();
@@ -57,12 +58,11 @@ namespace Pinetime {
5758
private:
5859
Controllers::DateTime& dateTimeController;
5960
System::SystemTask* systemTask = nullptr;
60-
uint8_t hours;
61-
uint8_t minutes;
61+
uint8_t hours = 7;
62+
uint8_t minutes = 0;
6263
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
6364
AlarmState state = AlarmState::Not_Set;
6465
RecurType recurrence = RecurType::None;
65-
void ScheduleAlarm();
6666
};
6767
}
6868
}

src/components/motor/MotorController.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ void MotorController::StartRinging() {
4242
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
4343
}
4444

45-
// This function is the same as StartRinging(), but will ring even if notifications are turned off in Settings
46-
void MotorController::StartRingingDisregardSettings() {
47-
Ring(this);
48-
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
49-
}
50-
5145
void MotorController::StopRinging() {
5246
app_timer_stop(longVibTimer);
5347
nrf_gpio_pin_set(pinMotor);

src/components/motor/MotorController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace Pinetime {
1515
void RunForDuration(uint8_t motorDuration);
1616
void StartRinging();
1717
static void StopRinging();
18-
void StartRingingDisregardSettings();
1918

2019
private:
2120
static void Ring(void* p_context);

src/displayapp/screens/Alarm.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,31 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)
4646
lv_obj_set_size(btnHoursUp, 60, 40);
4747
lv_obj_align(btnHoursUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -85);
4848
txtHrUp = lv_label_create(btnHoursUp, nullptr);
49-
lv_label_set_text(txtHrUp, "+");
49+
lv_label_set_text_static(txtHrUp, "+");
5050

5151
btnHoursDown = lv_btn_create(lv_scr_act(), nullptr);
5252
btnHoursDown->user_data = this;
5353
lv_obj_set_event_cb(btnHoursDown, btnEventHandler);
5454
lv_obj_set_size(btnHoursDown, 60, 40);
5555
lv_obj_align(btnHoursDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, 35);
5656
txtHrDown = lv_label_create(btnHoursDown, nullptr);
57-
lv_label_set_text(txtHrDown, "-");
57+
lv_label_set_text_static(txtHrDown, "-");
5858

5959
btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr);
6060
btnMinutesUp->user_data = this;
6161
lv_obj_set_event_cb(btnMinutesUp, btnEventHandler);
6262
lv_obj_set_size(btnMinutesUp, 60, 40);
6363
lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, -85);
6464
txtMinUp = lv_label_create(btnMinutesUp, nullptr);
65-
lv_label_set_text(txtMinUp, "+");
65+
lv_label_set_text_static(txtMinUp, "+");
6666

6767
btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr);
6868
btnMinutesDown->user_data = this;
6969
lv_obj_set_event_cb(btnMinutesDown, btnEventHandler);
7070
lv_obj_set_size(btnMinutesDown, 60, 40);
7171
lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, 35);
7272
txtMinDown = lv_label_create(btnMinutesDown, nullptr);
73-
lv_label_set_text(txtMinDown, "-");
73+
lv_label_set_text_static(txtMinDown, "-");
7474

7575
btnEnable = lv_btn_create(lv_scr_act(), nullptr);
7676
btnEnable->user_data = this;
@@ -94,7 +94,7 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)
9494
lv_obj_set_size(btnInfo, 50, 40);
9595
lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 0, -85);
9696
txtInfo = lv_label_create(btnInfo, nullptr);
97-
lv_label_set_text(txtInfo, "i");
97+
lv_label_set_text_static(txtInfo, "i");
9898
}
9999

100100
Alarm::~Alarm() {
@@ -110,7 +110,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
110110
} else if (alarmController.State() == AlarmController::AlarmState::Set) {
111111
alarmController.DisableAlarm();
112112
} else {
113-
alarmController.SetAlarm(alarmHours, alarmMinutes);
113+
alarmController.ScheduleAlarm();
114114
}
115115
SetEnableButtonState();
116116
return;
@@ -128,8 +128,6 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
128128
}
129129
// If any other button was pressed, disable the alarm
130130
// this is to make it clear that the alarm won't be set until it is turned back on
131-
// this avoids calling the AlarmController to change the alarm time every time the user hits minute-up or minute-down;
132-
// can just do it once when the alarm is re-enabled
133131
if (alarmController.State() == AlarmController::AlarmState::Set) {
134132
alarmController.DisableAlarm();
135133
SetEnableButtonState();
@@ -140,7 +138,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
140138
} else {
141139
alarmMinutes++;
142140
}
143-
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
141+
UpdateAlarmTime();
144142
return;
145143
}
146144
if (obj == btnMinutesDown) {
@@ -149,7 +147,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
149147
} else {
150148
alarmMinutes--;
151149
}
152-
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
150+
UpdateAlarmTime();
153151
return;
154152
}
155153
if (obj == btnHoursUp) {
@@ -158,7 +156,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
158156
} else {
159157
alarmHours++;
160158
}
161-
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
159+
UpdateAlarmTime();
162160
return;
163161
}
164162
if (obj == btnHoursDown) {
@@ -167,7 +165,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
167165
} else {
168166
alarmHours--;
169167
}
170-
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
168+
UpdateAlarmTime();
171169
return;
172170
}
173171
if (obj == btnRecur) {
@@ -176,6 +174,11 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
176174
}
177175
}
178176

177+
void Alarm::UpdateAlarmTime() {
178+
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
179+
alarmController.SetAlarmTime(alarmHours, alarmMinutes);
180+
}
181+
179182
void Alarm::SetAlerting() {
180183
SetEnableButtonState();
181184
}

src/displayapp/screens/Alarm.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace Pinetime {
3434

3535
private:
3636
bool running;
37-
uint8_t alarmHours = 0;
38-
uint8_t alarmMinutes = 0;
37+
uint8_t alarmHours;
38+
uint8_t alarmMinutes;
3939
Controllers::AlarmController& alarmController;
4040

4141
lv_obj_t *time, *btnEnable, *txtEnable, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp, *txtMinDown,
@@ -47,7 +47,8 @@ namespace Pinetime {
4747
void SetAlarm();
4848
void ShowInfo();
4949
void ToggleRecurrence();
50+
void UpdateAlarmTime();
5051
};
5152
};
5253
};
53-
}
54+
}

src/systemtask/SystemTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void SystemTask::Work() {
282282
if (isSleeping && !isWakingUp) {
283283
GoToRunning();
284284
}
285-
motorController.StartRingingDisregardSettings();
285+
motorController.StartRinging();
286286
displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered);
287287
break;
288288
case Messages::StopRinging:

0 commit comments

Comments
 (0)