feat: extend photo countdown to five seconds
This commit is contained in:
@@ -31,7 +31,7 @@ impl Sequence {
|
|||||||
pub fn tick(&mut self, complete: bool, hand_present: bool, now: Instant) -> bool {
|
pub fn tick(&mut self, complete: bool, hand_present: bool, now: Instant) -> bool {
|
||||||
match self.phase {
|
match self.phase {
|
||||||
Phase::Tracking if complete => self.phase = Phase::Countdown(now),
|
Phase::Tracking if complete => self.phase = Phase::Countdown(now),
|
||||||
Phase::Countdown(start) if now.duration_since(start) >= Duration::from_secs(3) => {
|
Phase::Countdown(start) if now.duration_since(start) >= Duration::from_secs(5) => {
|
||||||
self.phase = Phase::AwaitingRelease;
|
self.phase = Phase::AwaitingRelease;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ impl Sequence {
|
|||||||
Phase::Countdown(start) => {
|
Phase::Countdown(start) => {
|
||||||
let elapsed = now.duration_since(start).as_secs_f32();
|
let elapsed = now.duration_since(start).as_secs_f32();
|
||||||
Presentation {
|
Presentation {
|
||||||
countdown: (3 - elapsed as i32).clamp(1, 3),
|
countdown: (5 - elapsed as i32).clamp(1, 5),
|
||||||
// The monitor lights the room: hold white illumination until
|
// The monitor lights the room: hold white illumination until
|
||||||
// the clean frame is captured and queued after the countdown.
|
// the clean frame is captured and queued after the countdown.
|
||||||
flash_opacity: 0.95,
|
flash_opacity: 0.95,
|
||||||
@@ -229,7 +229,7 @@ mod tests {
|
|||||||
assert!(sequence.tracking());
|
assert!(sequence.tracking());
|
||||||
assert!(!sequence.tick(true, true, start));
|
assert!(!sequence.tick(true, true, start));
|
||||||
assert!(!sequence.tracking());
|
assert!(!sequence.tracking());
|
||||||
assert_eq!(sequence.presentation(start).countdown, 3);
|
assert_eq!(sequence.presentation(start).countdown, 5);
|
||||||
assert_eq!(sequence.presentation(start).flash_opacity, 0.95);
|
assert_eq!(sequence.presentation(start).flash_opacity, 0.95);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sequence
|
sequence
|
||||||
@@ -237,34 +237,44 @@ mod tests {
|
|||||||
.flash_opacity,
|
.flash_opacity,
|
||||||
0.95
|
0.95
|
||||||
);
|
);
|
||||||
for (ms, number) in [(999, 3), (1000, 2), (1999, 2), (2000, 1), (2999, 1)] {
|
for (ms, number) in [
|
||||||
|
(999, 5),
|
||||||
|
(1000, 4),
|
||||||
|
(1999, 4),
|
||||||
|
(2000, 3),
|
||||||
|
(2999, 3),
|
||||||
|
(3000, 2),
|
||||||
|
(3999, 2),
|
||||||
|
(4000, 1),
|
||||||
|
(4999, 1),
|
||||||
|
] {
|
||||||
let now = start + Duration::from_millis(ms);
|
let now = start + Duration::from_millis(ms);
|
||||||
// Lowering the hand must not cancel an already-started countdown.
|
// Lowering the hand must not cancel an already-started countdown.
|
||||||
assert!(!sequence.tick(false, false, now));
|
assert!(!sequence.tick(false, false, now));
|
||||||
assert_eq!(sequence.presentation(now).countdown, number);
|
assert_eq!(sequence.presentation(now).countdown, number);
|
||||||
assert_eq!(sequence.presentation(now).flash_opacity, 0.95);
|
assert_eq!(sequence.presentation(now).flash_opacity, 0.95);
|
||||||
}
|
}
|
||||||
assert!(sequence.tick(true, true, start + Duration::from_secs(3)));
|
assert!(sequence.tick(true, true, start + Duration::from_secs(5)));
|
||||||
assert!(
|
assert!(
|
||||||
sequence
|
sequence
|
||||||
.presentation(start + Duration::from_secs(3))
|
.presentation(start + Duration::from_secs(5))
|
||||||
.awaiting_release
|
.awaiting_release
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sequence
|
sequence
|
||||||
.presentation(start + Duration::from_secs(3))
|
.presentation(start + Duration::from_secs(5))
|
||||||
.countdown,
|
.countdown,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sequence
|
sequence
|
||||||
.presentation(start + Duration::from_secs(3))
|
.presentation(start + Duration::from_secs(5))
|
||||||
.flash_opacity,
|
.flash_opacity,
|
||||||
0.0
|
0.0
|
||||||
);
|
);
|
||||||
assert!(!sequence.tick(true, true, start + Duration::from_secs(4)));
|
assert!(!sequence.tick(true, true, start + Duration::from_secs(6)));
|
||||||
assert!(!sequence.tracking());
|
assert!(!sequence.tracking());
|
||||||
assert!(!sequence.tick(false, false, start + Duration::from_secs(5)));
|
assert!(!sequence.tick(false, false, start + Duration::from_secs(7)));
|
||||||
assert!(sequence.tracking());
|
assert!(sequence.tracking());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user