Skip to content

Commit 04636e1

Browse files
committed
ledmatrix: Display random startup animation
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 95afbdd commit 04636e1

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

fl16-inputmodules/src/animations.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ use crate::patterns::*;
99
// - [ ] Each one has a number of frames
1010
// - [ ] Each one might have a different frame-rate
1111

12+
pub enum Animation {
13+
ZigZag(ZigZagIterator),
14+
Gof(GameOfLifeIterator),
15+
Percentage(StartupPercentageIterator),
16+
Breathing(BreathingIterator),
17+
}
18+
impl Iterator for Animation {
19+
type Item = Grid;
20+
21+
fn next(&mut self) -> Option<Self::Item> {
22+
match self {
23+
Animation::ZigZag(x) => x.next(),
24+
Animation::Gof(x) => x.next(),
25+
Animation::Percentage(x) => x.next(),
26+
Animation::Breathing(x) => x.next(),
27+
}
28+
}
29+
}
30+
1231
pub struct ZigZagIterator {
1332
frames: usize,
1433
current_frame: usize,

fl16-inputmodules/src/matrix.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ pub struct LedmatrixState {
4747
/// - Sleep/wake transition is instant, no animation/fading
4848
/// - No automatic sleeping
4949
pub debug_mode: bool,
50-
//pub upcoming_frames: dyn Iterator<Item = Grid>,
51-
//pub upcoming_frames: Option<ZigZagIterator>,
52-
//pub upcoming_frames: Option<StartupPercentageIterator>,
53-
//pub upcoming_frames: Option<GameOfLifeIterator>,
54-
pub upcoming_frames: Option<BreathingIterator>,
50+
pub upcoming_frames: Option<Animation>,
5551
}
5652

5753
#[allow(clippy::large_enum_variant)]

ledmatrix/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,18 @@ fn main() -> ! {
235235
animation_period: 31_250, // 31,250 us = 32 FPS
236236
pwm_freq: PwmFreqArg::P29k,
237237
debug_mode: false,
238-
//upcoming_frames: Some(StartupPercentageIterator::new()),
239-
//upcoming_frames: Some(ZigZagIterator::new(34)),
240-
//upcoming_frames: Some(GameOfLifeIterator::new(GameOfLifeStartParam::Glider, 60)),
241-
upcoming_frames: Some(BreathingIterator::new(64)),
238+
upcoming_frames: None,
242239
};
243240
state.debug_mode = dip1.is_low().unwrap();
244-
if !show_startup_animation(&state) {
241+
if show_startup_animation(&state) {
242+
state.upcoming_frames = Some(match get_random_byte(&rosc) % 4 {
243+
0 => Animation::Percentage(StartupPercentageIterator::new()),
244+
1 => Animation::ZigZag(ZigZagIterator::new(34)),
245+
2 => Animation::Gof(GameOfLifeIterator::new(GameOfLifeStartParam::Glider, 60)),
246+
3 => Animation::Breathing(BreathingIterator::new(64)),
247+
_ => unreachable!(),
248+
});
249+
} else {
245250
// If no startup animation, render another pattern
246251
// Lighting up every second column is a good pattern to test for noise.
247252
state.grid = every_nth_col(2);

0 commit comments

Comments
 (0)