@@ -10,6 +10,8 @@ pub enum _CommandVals {
10
10
_Animate = 0x04 ,
11
11
_Panic = 0x05 ,
12
12
_Draw = 0x06 ,
13
+ _StageGreyCol = 0x07 ,
14
+ _DrawGreyColBuffer = 0x08 ,
13
15
}
14
16
15
17
pub enum PatternVals {
@@ -24,14 +26,24 @@ pub enum PatternVals {
24
26
}
25
27
26
28
pub enum Command {
29
+ /// Set brightness scaling
27
30
Brightness ( u8 ) ,
31
+ /// Display pre-programmed pattern
28
32
Pattern ( PatternVals ) ,
33
+ /// Reset into bootloader
29
34
BootloaderReset ,
35
+ /// Light up a percentage of the screen
30
36
Percentage ( u8 ) ,
37
+ /// Go to sleepe or wake up
31
38
Sleep ( bool ) ,
39
+ /// Start/stop animation (vertical scrolling)
32
40
Animate ( bool ) ,
41
+ /// Panic. Just to test what happens
33
42
Panic ,
34
- Draw ( [ u8 ; 39 ] ) ,
43
+ /// Draw black/white on the grid
44
+ Draw ( [ u8 ; DRAW_BYTES ] ) ,
45
+ StageGreyCol ( u8 , [ u8 ; HEIGHT ] ) ,
46
+ DrawGreyColBuffer ,
35
47
_Unknown,
36
48
}
37
49
@@ -68,14 +80,24 @@ pub fn parse_command(count: usize, buf: &[u8]) -> Option<Command> {
68
80
0x04 => Some ( Command :: Animate ( arg == 1 ) ) ,
69
81
0x05 => Some ( Command :: Panic ) ,
70
82
0x06 => {
71
- if count >= 3 + 39 {
72
- let mut bytes = [ 0 ; 39 ] ;
73
- bytes. clone_from_slice ( & buf[ 3 ..3 + 39 ] ) ;
83
+ if count >= 3 + DRAW_BYTES {
84
+ let mut bytes = [ 0 ; DRAW_BYTES ] ;
85
+ bytes. clone_from_slice ( & buf[ 3 ..3 + DRAW_BYTES ] ) ;
74
86
Some ( Command :: Draw ( bytes) )
75
87
} else {
76
88
None
77
89
}
78
90
}
91
+ 0x07 => {
92
+ if count >= 3 + 1 + HEIGHT {
93
+ let mut bytes = [ 0 ; HEIGHT ] ;
94
+ bytes. clone_from_slice ( & buf[ 4 ..4 + HEIGHT ] ) ;
95
+ Some ( Command :: StageGreyCol ( buf[ 3 ] , bytes) )
96
+ } else {
97
+ None
98
+ }
99
+ }
100
+ 0x08 => Some ( Command :: DrawGreyColBuffer ) ,
79
101
_ => None , //Some(Command::Unknown),
80
102
}
81
103
} else {
@@ -125,6 +147,15 @@ pub fn handle_command(command: &Command, state: &mut State, matrix: &mut Foo) {
125
147
Command :: Animate ( a) => state. animate = * a,
126
148
Command :: Panic => panic ! ( "Ahhh" ) ,
127
149
Command :: Draw ( vals) => state. grid = draw ( vals) ,
150
+ Command :: StageGreyCol ( col, vals) => {
151
+ draw_grey_col ( & mut state. col_buffer , * col, vals) ;
152
+ }
153
+ Command :: DrawGreyColBuffer => {
154
+ // Copy the staging buffer to the real grid and display it
155
+ state. grid = state. col_buffer . clone ( ) ;
156
+ // Zero the old staging buffer, just for good measure.
157
+ state. col_buffer = percentage ( 0 ) ;
158
+ }
128
159
_ => { }
129
160
}
130
161
}
0 commit comments