@@ -74,6 +74,14 @@ 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 , progressBarSize);
79+ lv_bar_set_value (progressStop, 0 , LV_ANIM_OFF);
80+ lv_obj_set_size (progressStop, progressBarSize, 10 );
81+ lv_obj_align (progressStop, nullptr , LV_ALIGN_IN_TOP_MID, 0 , 0 );
82+ lv_obj_set_style_local_bg_color (progressStop, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
83+ lv_obj_set_hidden (progressStop, true );
84+
7785 btnStop = lv_btn_create (lv_scr_act (), nullptr );
7886 btnStop->user_data = this ;
7987 lv_obj_set_event_cb (btnStop, btnEventHandler);
@@ -122,12 +130,28 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
122130 } else {
123131 SetSwitchState (LV_ANIM_OFF);
124132 }
133+
134+ taskRefresh = lv_task_create (RefreshTaskCallback, 50 , LV_TASK_PRIO_MID, this );
135+ }
136+
137+ void Alarm::Refresh () {
138+ if (stopBtnPressTime.has_value ()) {
139+ TickType_t elapsed = xTaskGetTickCount () - stopBtnPressTime.value ();
140+ if (elapsed >= longPressTimeout) {
141+ ResetStopProgress ();
142+ StopAlerting ();
143+ } else {
144+ lv_coord_t stopPosition = (elapsed * progressBarSize) / longPressTimeout;
145+ UpdateStopProgress (stopPosition);
146+ }
147+ }
125148}
126149
127150Alarm::~Alarm () {
128151 if (alarmController.IsAlerting ()) {
129152 StopAlerting ();
130153 }
154+ lv_task_del (taskRefresh);
131155 lv_obj_clean (lv_scr_act ());
132156 alarmController.SaveAlarm ();
133157}
@@ -139,12 +163,32 @@ void Alarm::DisableAlarm() {
139163 }
140164}
141165
166+ void Alarm::StopButtonPressed () {
167+ stopBtnPressTime = xTaskGetTickCount ();
168+ UpdateStopProgress (0 );
169+ lv_obj_set_hidden (progressStop, false );
170+ }
171+
172+ void Alarm::ResetStopProgress () {
173+ stopBtnPressTime = std::nullopt ;
174+ UpdateStopProgress (0 );
175+ lv_obj_set_hidden (progressStop, true );
176+ }
177+
178+ void Alarm::UpdateStopProgress (lv_coord_t stopPosition) {
179+ lv_bar_set_value (progressStop, progressBarSize - stopPosition, LV_ANIM_OFF);
180+ }
181+
142182void Alarm::OnButtonEvent (lv_obj_t * obj, lv_event_t event) {
143- if (event == LV_EVENT_CLICKED) {
144- if (obj == btnStop) {
145- StopAlerting ();
146- return ;
183+ if (obj == btnStop) {
184+ if (event == LV_EVENT_PRESSED) {
185+ StopButtonPressed ();
186+ } else if (event == LV_EVENT_RELEASED || event == LV_EVENT_PRESS_LOST) {
187+ ResetStopProgress ();
147188 }
189+ return ;
190+ }
191+ if (event == LV_EVENT_CLICKED) {
148192 if (obj == btnInfo) {
149193 ShowInfo ();
150194 return ;
0 commit comments