@@ -68,99 +68,63 @@ impl ControlPanelState {
6868 . draw ( & mut self . display , self . usb_power_2 . output_level ( ) )
6969 . unwrap ( ) ;
7070 }
71- UISection :: MeetingSign => match direction {
72- MovementDirection :: Clockwise => {
73- match self . meeting_sign_power . output_level ( ) {
74- Level :: High => {
75- info ! ( "Meeting Sign is already running" ) ;
76- match self . meeting_sign_completion {
77- None => {
78- self . meeting_sign_power . set_high ( ) ;
79- self . meeting_sign_completion =
80- Some ( Instant :: now ( ) + Self :: MEETING_SIGN_INTERVAL ) ;
81- error ! (
82- "Meeting sign completion is None, but power is high."
83- ) ;
84- }
85- Some ( instant) => {
86- if instant < Instant :: now ( ) {
87- self . meeting_sign_power . set_high ( ) ;
88- self . meeting_sign_completion =
89- Some ( Instant :: now ( ) + Self :: MEETING_SIGN_INTERVAL ) ;
90- error ! ( "Meeting sign completion was before NOW." ) ;
91- } else if instant + Self :: MEETING_SIGN_INTERVAL
92- < Instant :: now ( ) + Self :: MEETING_SIGN_MAX_DURATION
93- {
94- self . meeting_sign_power . set_high ( ) ;
95- self . meeting_sign_completion =
96- Some ( instant + Self :: MEETING_SIGN_INTERVAL ) ;
97- info ! (
98- "Meeting sign timer increased by {}s." ,
99- Self :: MEETING_SIGN_INTERVAL . as_secs( )
100- ) ;
101- } else {
102- info ! ( "Meeting sign timer would exceed max duration, not increasing." ) ;
103- }
104- }
105- }
106- }
107- Level :: Low => {
108- self . meeting_sign_power . set_high ( ) ;
109- self . meeting_sign_completion =
110- Some ( Instant :: now ( ) + Self :: MEETING_SIGN_INTERVAL ) ;
111- info ! ( "Meeting Sign turned on" ) ;
112- info ! ( "Meeting Sign timer started" ) ;
113- }
114- } ;
115- self . check_meeting_sign_timer ( ) . unwrap ( ) ;
116- }
117- MovementDirection :: CounterClockwise => {
118- match self . meeting_sign_power . output_level ( ) {
119- Level :: High => {
120- info ! ( "Meeting Sign is already running" ) ;
121- match self . meeting_sign_completion {
122- None => {
123- self . meeting_sign_power . set_low ( ) ;
124- error ! (
125- "Meeting sign completion is None, but power is high."
126- ) ;
127- }
128- Some ( instant) => {
129- if instant < Instant :: now ( ) {
130- self . meeting_sign_power . set_low ( ) ;
131- error ! ( "Meeting sign completion was before NOW, but power is high." ) ;
132- } else if instant - Self :: MEETING_SIGN_INTERVAL
133- < Instant :: now ( )
134- {
135- self . meeting_sign_power . set_low ( ) ;
136- self . meeting_sign_completion = None ;
137- info ! (
138- "Meeting sign turned off and completion set to None."
139- ) ;
140- } else {
141- self . meeting_sign_completion =
142- Some ( instant - Self :: MEETING_SIGN_INTERVAL ) ;
143- info ! (
144- "Decreasing Meeting Sign timer by {}s." ,
145- Self :: MEETING_SIGN_INTERVAL . as_secs( )
146- ) ;
147- }
148- }
149- }
150- self . check_meeting_sign_timer ( ) . unwrap ( ) ;
151- }
152- Level :: Low => {
153- info ! ( "Meeting sign is already off" ) ;
154- }
155- } ;
156- }
157- } ,
71+ UISection :: MeetingSign => {
72+ self . process_meeting_sign_change ( direction) . unwrap ( ) ;
73+ }
15874 } ,
15975 } ;
16076
16177 self . display . flush ( ) . unwrap ( ) ;
16278 }
16379
80+ fn process_meeting_sign_change (
81+ & mut self ,
82+ direction : MovementDirection ,
83+ ) -> Result < ( ) , <DisplayType as DrawTarget >:: Error > {
84+ let now = Instant :: now ( ) ;
85+
86+ match ( direction, self . meeting_sign_completion ) {
87+ ( MovementDirection :: Clockwise , None ) => {
88+ self . meeting_sign_power . set_high ( ) ;
89+ self . meeting_sign_completion = Some ( now + Self :: MEETING_SIGN_INTERVAL ) ;
90+ self . check_meeting_sign_timer ( ) ?;
91+ info ! ( "Starting meeting sign timer from None" ) ;
92+ }
93+ ( MovementDirection :: Clockwise , Some ( end) ) => {
94+ // If the stored end is before (less than) now, we use now as the base time
95+ let proposed_end = end. max ( now) + Self :: MEETING_SIGN_INTERVAL ;
96+
97+ if proposed_end > now + Self :: MEETING_SIGN_MAX_DURATION {
98+ info ! ( "Meeting sign timer would exceed max duration, not increasing" ) ;
99+ return Ok ( ( ) ) ;
100+ }
101+
102+ self . meeting_sign_power . set_high ( ) ;
103+ self . meeting_sign_completion = Some ( proposed_end) ;
104+ self . check_meeting_sign_timer ( ) ?;
105+ info ! ( "Meeting sign timer increased" , ) ;
106+ }
107+ ( MovementDirection :: CounterClockwise , None ) => {
108+ info ! ( "Meeting sign is already off, nothing to do" ) ;
109+ }
110+ ( MovementDirection :: CounterClockwise , Some ( end) ) => {
111+ if end - Self :: MEETING_SIGN_INTERVAL < now {
112+ self . meeting_sign_power . set_low ( ) ;
113+ self . meeting_sign_completion = None ;
114+ info ! ( "Meeting sign turned off and completion set to None" ) ;
115+ } else {
116+ self . meeting_sign_completion = Some ( end - Self :: MEETING_SIGN_INTERVAL ) ;
117+ info ! (
118+ "Decreasing Meeting Sign timer by {}s." ,
119+ Self :: MEETING_SIGN_INTERVAL . as_secs( )
120+ ) ;
121+ }
122+ self . check_meeting_sign_timer ( ) ?;
123+ }
124+ } ;
125+ Ok ( ( ) )
126+ }
127+
164128 pub fn rotary_encoder_press ( & mut self ) {
165129 match self . ui_selection_mode {
166130 UISelectionMode :: Menu => {
@@ -233,29 +197,38 @@ impl ControlPanelState {
233197 }
234198
235199 pub fn check_meeting_sign_timer ( & mut self ) -> Result < ( ) , <DisplayType as DrawTarget >:: Error > {
200+ let now = Instant :: now ( ) ;
201+
236202 match (
237203 self . meeting_sign_power . output_level ( ) ,
238204 self . meeting_sign_completion ,
239205 ) {
240- ( Level :: Low , None ) => { }
206+ ( Level :: Low , None ) => {
207+ // No action needed
208+ MeetingSignUI . draw_progress ( & mut self . display , ProgressRatio ( 0 ) ) ?;
209+ }
241210 ( Level :: Low , Some ( _) ) => {
242211 error ! ( "Meeting Sign is not on, but completion is set to something" ) ;
212+ // This should not happen, but if it does, we can reset the state
213+ self . meeting_sign_completion = None ;
214+ MeetingSignUI . draw_progress ( & mut self . display , ProgressRatio ( 0 ) ) ?;
243215 }
244216 ( Level :: High , None ) => {
245217 error ! ( "Meeting Sign is on, but completion is None" ) ;
246218 // This should not happen, but if it does, we can reset the state
247219 self . meeting_sign_power . set_low ( ) ;
248220 self . meeting_sign_completion = None ;
221+ MeetingSignUI . draw_progress ( & mut self . display , ProgressRatio ( 0 ) ) ?;
249222 }
250- ( Level :: High , Some ( instant ) ) => {
251- if instant < Instant :: now ( ) {
223+ ( Level :: High , Some ( end ) ) => {
224+ if end < now {
252225 self . meeting_sign_power . set_low ( ) ;
253226 self . meeting_sign_completion = None ;
254227 info ! ( "Meeting Sign timer has completed" ) ;
255228 MeetingSignUI . draw_progress ( & mut self . display , ProgressRatio ( 0 ) ) ?;
256229 } else {
257230 let ratio = ProgressRatio :: from_durations (
258- & ( instant - Instant :: now ( ) ) ,
231+ & ( end - now) ,
259232 & Self :: MEETING_SIGN_MAX_DURATION ,
260233 )
261234 . unwrap ( ) ;
@@ -656,6 +629,11 @@ impl MeetingSignUI {
656629
657630 Self :: PROGRESS_OUTLINE . draw_styled ( & PrimitiveStyle :: with_fill ( BinaryColor :: Off ) , target) ?;
658631
632+ // If the ratio is 0, do not draw the bar
633+ if ratio == ProgressRatio ( 0 ) {
634+ return Ok ( ( ) ) ;
635+ }
636+
659637 RoundedRectangle :: with_equal_corners (
660638 Rectangle :: new (
661639 Self :: PROGRESS_PT ,
0 commit comments