Skip to content

Commit ee649c1

Browse files
committed
dynamic update timer based on uart
1 parent 34250ea commit ee649c1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/bin/meeting_sign.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,23 @@ async fn main(spawner: Spawner) {
139139
.spawn(uart_timeout_monitor(state_publisher_2, state_subscriber_1))
140140
.ok();
141141

142+
let mut loop_timeout_duration = UART_COMMUNICATION_TIMEOUT;
143+
142144
// Main loop
143145
loop {
144146
match select(
145147
state_subscriber_2.next_message_pure(),
146-
Timer::after(UART_COMMUNICATION_TIMEOUT),
148+
Timer::after(loop_timeout_duration),
147149
)
148150
.await
149151
{
150152
Either::First(state) => match state {
151153
MeetingSignState::NoUart => {
152-
info!("Initial state changed to NoUart.");
154+
info!("State changed to NoUart.");
153155
leds.lock().await.set_ratio_low(ProgressRatio(u8::MAX / 2));
154156
}
155157
MeetingSignState::Uart(instruction) => {
156-
info!("Initial state changed to Uart.");
158+
info!("State changed to Uart.");
157159
match instruction {
158160
MeetingSignInstruction::On(progress_ratio) => {
159161
leds.lock().await.set_ratio_low(progress_ratio)
@@ -167,13 +169,17 @@ async fn main(spawner: Spawner) {
167169
}
168170
},
169171
Either::Second(_) => {
170-
info!("No initial state change detected within {}s, initializing LEDs according to builtin timer...",
171-
UART_COMMUNICATION_TIMEOUT.as_secs());
172+
info!(
173+
"No state change detected within {}s, displaying LEDs according to builtin timer...",
174+
loop_timeout_duration.as_secs()
175+
);
176+
loop_timeout_duration = Duration::from_secs(60); // Increase the timeout now
172177

173-
// leds.lock().await.display_builtin_timer();
174178
leds.lock().await.set_pattern_array(&[
175179
false, true, true, false, false, false, true, true, false,
176180
]);
181+
Timer::after(Duration::from_secs(1)).await;
182+
leds.lock().await.display_builtin_timer();
177183
}
178184
}
179185
}

0 commit comments

Comments
 (0)