-
-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
alarm: Long press to stop alarm #2222
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,13 @@ Alarm::Alarm(Controllers::AlarmController& alarmController, | |
lv_label_set_text_static(colonLabel, ":"); | ||
lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); | ||
|
||
progressStop = lv_bar_create(lv_scr_act(), nullptr); | ||
lv_bar_set_range(progressStop, 0, 240); | ||
lv_bar_set_value(progressStop, 0, LV_ANIM_OFF); | ||
lv_obj_set_size(progressStop, 240, 50); | ||
lv_obj_align(progressStop, nullptr, LV_ALIGN_CENTER, 0, 0); | ||
lv_obj_set_style_local_bg_color(progressStop, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE); | ||
|
||
btnStop = lv_btn_create(lv_scr_act(), nullptr); | ||
btnStop->user_data = this; | ||
lv_obj_set_event_cb(btnStop, btnEventHandler); | ||
|
@@ -122,12 +129,27 @@ Alarm::Alarm(Controllers::AlarmController& alarmController, | |
} else { | ||
SetSwitchState(LV_ANIM_OFF); | ||
} | ||
|
||
taskRefresh = lv_task_create(RefreshTaskCallback, 50, LV_TASK_PRIO_MID, this); | ||
} | ||
|
||
void Alarm::Refresh() { | ||
if (stopBtnPressing && xTaskGetTickCount() > stopBtnPressTime + pdMS_TO_TICKS(150)) { | ||
stopPosition += 15; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we calculate elapsed ticks with |
||
if (stopPosition > 240) { | ||
ResetStopProgress(); | ||
StopAlerting(); | ||
} else { | ||
UpdateStopProgress(); | ||
} | ||
} | ||
} | ||
|
||
Alarm::~Alarm() { | ||
if (alarmController.IsAlerting()) { | ||
StopAlerting(); | ||
} | ||
lv_task_del(taskRefresh); | ||
lv_obj_clean(lv_scr_act()); | ||
alarmController.SaveAlarm(); | ||
} | ||
|
@@ -139,12 +161,31 @@ void Alarm::DisableAlarm() { | |
} | ||
} | ||
|
||
void Alarm::StopButtonPressed() { | ||
stopBtnPressTime = xTaskGetTickCount(); | ||
stopBtnPressing = true; | ||
} | ||
|
||
void Alarm::ResetStopProgress() { | ||
stopBtnPressing = false; | ||
stopPosition = 0; | ||
UpdateStopProgress(); | ||
} | ||
|
||
void Alarm::UpdateStopProgress() { | ||
lv_bar_set_value(progressStop, stopPosition, LV_ANIM_OFF); | ||
} | ||
|
||
void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { | ||
if (event == LV_EVENT_CLICKED) { | ||
if (obj == btnStop) { | ||
StopAlerting(); | ||
return; | ||
if (obj == btnStop) { | ||
if (event == LV_EVENT_PRESSED) { | ||
StopButtonPressed(); | ||
} else if (event == LV_EVENT_RELEASED || event == LV_EVENT_PRESS_LOST) { | ||
ResetStopProgress(); | ||
} | ||
return; | ||
} | ||
if (event == LV_EVENT_CLICKED) { | ||
if (obj == btnInfo) { | ||
ShowInfo(); | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xTaskGetTickCount() - stopBtnPressTime > pdMS_TO_TICKS(150)
is tolerant to tick count wraparoundShould we start showing the bar earlier than 150ms, as you need to hold the button to dismiss it. In fact, would it be better with no delay at all? A long press isn't super intuitive, so giving immediate feedback will make it clearer that holding it is needed IMO