Repository navigation
Expand file tree
/
Copy pathmatrix.rs
More file actions
76 lines (69 loc) · 1.86 KB
/
Copy pathmatrix.rs
File metadata and controls
76 lines (69 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::animations::*;
use crate::control::PwmFreqArg;
use crate::games::game_of_life::GameOfLifeState;
use crate::games::pong::PongState;
use crate::games::snake::SnakeState;
pub const WIDTH: usize = 9;
pub const HEIGHT: usize = 34;
pub const LEDS: usize = WIDTH * HEIGHT;
#[derive(Clone)]
pub struct Grid(pub [[u8; HEIGHT]; WIDTH]);
impl Default for Grid {
fn default() -> Self {
Grid([[0; HEIGHT]; WIDTH])
}
}
impl Grid {
pub fn rotate(&mut self, rotations: usize) {
for x in 0..WIDTH {
self.0[x].rotate_right(rotations);
}
}
}
pub struct LedmatrixState {
/// Currently displayed grid
pub grid: Grid,
/// Temporary buffer for building a new grid
pub col_buffer: Grid,
/// Whether the grid is currently being animated
pub animate: bool,
/// LED brightness out of 255
pub brightness: u8,
/// Current sleep state
pub sleeping: SleepState,
/// State of the current game, if any
pub game: Option<GameState>,
pub animation_period: u64,
/// Current LED PWM frequency
pub pwm_freq: PwmFreqArg,
/// Whether debug mode is active
///
/// In debug mode:
/// - Startup is instant, no animation
/// - Sleep/wake transition is instant, no animation/fading
/// - No automatic sleeping
pub debug_mode: bool,
pub upcoming_frames: Option<Animation>,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone)]
/// Whether asleep or not, if asleep contains data to restore previous LED grid
pub enum SleepState {
Awake,
Sleeping((Grid, u8)),
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum SleepReason {
Command,
SleepPin,
Timeout,
UsbSuspend,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone)]
/// State that's used for each game
pub enum GameState {
Snake(SnakeState),
Pong(PongState),
GameOfLife(GameOfLifeState),
}