Skip to content

Commit 026527d

Browse files
committed
alarm: Long press to stop alarm
This change prevents accidentally turning off alarm by ensuring that there is a deliberate long press, similar to resetting the Timer app.
1 parent 7b39d81 commit 026527d

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

src/displayapp/screens/Alarm.cpp

+45-4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
7474
lv_label_set_text_static(colonLabel, ":");
7575
lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29);
7676

77+
progressStop = lv_bar_create(lv_scr_act(), nullptr);
78+
lv_bar_set_range(progressStop, 0, 240);
79+
lv_bar_set_value(progressStop, 0, LV_ANIM_OFF);
80+
lv_obj_set_size(progressStop, 240, 50);
81+
lv_obj_align(progressStop, nullptr, LV_ALIGN_CENTER, 0, 0);
82+
lv_obj_set_style_local_bg_color(progressStop, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
83+
7784
btnStop = lv_btn_create(lv_scr_act(), nullptr);
7885
btnStop->user_data = this;
7986
lv_obj_set_event_cb(btnStop, btnEventHandler);
@@ -122,12 +129,27 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
122129
} else {
123130
SetSwitchState(LV_ANIM_OFF);
124131
}
132+
133+
taskRefresh = lv_task_create(RefreshTaskCallback, 50, LV_TASK_PRIO_MID, this);
134+
}
135+
136+
void Alarm::Refresh() {
137+
if (stopBtnPressing && xTaskGetTickCount() > stopBtnPressTime + pdMS_TO_TICKS(150)) {
138+
stopPosition += 15;
139+
if (stopPosition > 240) {
140+
ResetStopProgress();
141+
StopAlerting();
142+
} else {
143+
UpdateStopProgress();
144+
}
145+
}
125146
}
126147

127148
Alarm::~Alarm() {
128149
if (alarmController.IsAlerting()) {
129150
StopAlerting();
130151
}
152+
lv_task_del(taskRefresh);
131153
lv_obj_clean(lv_scr_act());
132154
alarmController.SaveAlarm();
133155
}
@@ -139,12 +161,31 @@ void Alarm::DisableAlarm() {
139161
}
140162
}
141163

164+
void Alarm::StopButtonPressed() {
165+
stopBtnPressTime = xTaskGetTickCount();
166+
stopBtnPressing = true;
167+
}
168+
169+
void Alarm::ResetStopProgress() {
170+
stopBtnPressing = false;
171+
stopPosition = 0;
172+
UpdateStopProgress();
173+
}
174+
175+
void Alarm::UpdateStopProgress() {
176+
lv_bar_set_value(progressStop, stopPosition, LV_ANIM_OFF);
177+
}
178+
142179
void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
143-
if (event == LV_EVENT_CLICKED) {
144-
if (obj == btnStop) {
145-
StopAlerting();
146-
return;
180+
if (obj == btnStop) {
181+
if (event == LV_EVENT_PRESSED) {
182+
StopButtonPressed();
183+
} else if (event == LV_EVENT_RELEASED || event == LV_EVENT_PRESS_LOST) {
184+
ResetStopProgress();
147185
}
186+
return;
187+
}
188+
if (event == LV_EVENT_CLICKED) {
148189
if (obj == btnInfo) {
149190
ShowInfo();
150191
return;

src/displayapp/screens/Alarm.h

+10
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ namespace Pinetime {
3535
System::SystemTask& systemTask,
3636
Controllers::MotorController& motorController);
3737
~Alarm() override;
38+
void Refresh() override;
3839
void SetAlerting();
3940
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
4041
bool OnButtonPushed() override;
4142
bool OnTouchEvent(TouchEvents event) override;
4243
void OnValueChanged();
4344
void StopAlerting();
45+
void StopButtonPressed();
46+
void ResetStopProgress();
4447

4548
private:
4649
Controllers::AlarmController& alarmController;
@@ -51,6 +54,7 @@ namespace Pinetime {
5154
lv_obj_t* lblampm = nullptr;
5255
lv_obj_t* txtMessage = nullptr;
5356
lv_obj_t* btnMessage = nullptr;
57+
lv_task_t* taskRefresh = nullptr;
5458
lv_task_t* taskStopAlarm = nullptr;
5559

5660
enum class EnableButtonState { On, Off, Alerting };
@@ -62,8 +66,14 @@ namespace Pinetime {
6266
void HideInfo();
6367
void ToggleRecurrence();
6468
void UpdateAlarmTime();
69+
void UpdateStopProgress();
6570
Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_76);
6671
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
72+
73+
lv_obj_t* progressStop;
74+
bool stopBtnPressing = false;
75+
TickType_t stopBtnPressTime = 0;
76+
lv_coord_t stopPosition = 0;
6777
};
6878
}
6979

0 commit comments

Comments
 (0)