File tree Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,25 @@ use crate::patterns::*;
9
9
// - [ ] Each one has a number of frames
10
10
// - [ ] Each one might have a different frame-rate
11
11
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
+
12
31
pub struct ZigZagIterator {
13
32
frames : usize ,
14
33
current_frame : usize ,
Original file line number Diff line number Diff line change @@ -47,11 +47,7 @@ pub struct LedmatrixState {
47
47
/// - Sleep/wake transition is instant, no animation/fading
48
48
/// - No automatic sleeping
49
49
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 > ,
55
51
}
56
52
57
53
#[ allow( clippy:: large_enum_variant) ]
Original file line number Diff line number Diff line change @@ -235,13 +235,18 @@ fn main() -> ! {
235
235
animation_period : 31_250 , // 31,250 us = 32 FPS
236
236
pwm_freq : PwmFreqArg :: P29k ,
237
237
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 ,
242
239
} ;
243
240
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 {
245
250
// If no startup animation, render another pattern
246
251
// Lighting up every second column is a good pattern to test for noise.
247
252
state. grid = every_nth_col ( 2 ) ;
You can’t perform that action at this time.
0 commit comments