@@ -7,6 +7,9 @@ use crate::lotus_led_hal as bsp;
7
7
use crate :: mapping:: * ;
8
8
use crate :: { lotus:: LotusLedMatrix , Grid } ;
9
9
10
+ pub const WIDTH : usize = 9 ;
11
+ pub const HEIGHT : usize = 34 ;
12
+
10
13
pub type Foo = LotusLedMatrix <
11
14
bsp:: hal:: I2C <
12
15
I2C1 ,
@@ -18,26 +21,26 @@ pub type Foo = LotusLedMatrix<
18
21
> ;
19
22
20
23
pub fn draw ( bytes : & [ u8 ; 39 ] ) -> Grid {
21
- let mut grid: Grid = [ [ 0 ; 34 ] ; 9 ] ;
24
+ let mut grid = Grid :: default ( ) ;
22
25
23
- for y in 0 ..34 {
24
- for x in 0 ..9 {
25
- let index = x + 9 * y;
26
+ for y in 0 ..HEIGHT {
27
+ for x in 0 ..WIDTH {
28
+ let index = x + WIDTH * y;
26
29
let byte = index / 8 ;
27
30
let bit = index % 8 ;
28
31
let val = if bytes[ byte] & ( 1 << bit) > 0 {
29
32
0xFF
30
33
} else {
31
34
0x00
32
35
} ;
33
- grid[ 8 - x] [ y] = val;
36
+ grid. 0 [ 8 - x] [ y] = val;
34
37
}
35
38
}
36
39
37
40
grid
38
41
}
39
42
pub fn display_sleep ( ) -> Grid {
40
- [
43
+ Grid ( [
41
44
[
42
45
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
43
46
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -83,11 +86,11 @@ pub fn display_sleep() -> Grid {
83
86
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
84
87
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
85
88
] ,
86
- ]
89
+ ] )
87
90
}
88
91
89
92
pub fn display_panic ( ) -> Grid {
90
- let grid : Grid = [
93
+ Grid ( [
91
94
[
92
95
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
93
96
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -133,13 +136,11 @@ pub fn display_panic() -> Grid {
133
136
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
134
137
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
135
138
] ,
136
- ] ;
137
-
138
- grid
139
+ ] )
139
140
}
140
141
141
142
pub fn display_lotus ( ) -> Grid {
142
- let mut grid: Grid = [ [ 0 ; 34 ] ; 9 ] ;
143
+ let mut grid = Grid :: default ( ) ;
143
144
144
145
display_letter ( 26 , & mut grid, CAP_L ) ;
145
146
display_letter ( 20 , & mut grid, CAP_O ) ;
@@ -151,7 +152,7 @@ pub fn display_lotus() -> Grid {
151
152
}
152
153
153
154
pub fn display_lotus2 ( ) -> Grid {
154
- [
155
+ Grid ( [
155
156
[
156
157
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
157
158
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -197,107 +198,112 @@ pub fn display_lotus2() -> Grid {
197
198
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
198
199
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
199
200
] ,
200
- ]
201
+ ] )
201
202
}
202
203
203
204
pub fn display_letter ( pos : usize , grid : & mut Grid , letter : SingleDisplayData ) {
204
- for x in 0 ..8 {
205
- for y in 0 ..8 {
205
+ let letter_size = 8 ;
206
+ for x in 0 ..letter_size {
207
+ for y in 0 ..letter_size {
206
208
let val = if letter[ x] & ( 1 << y) > 0 { 0xFF } else { 0 } ;
207
- grid[ 8 - x] [ y + pos] = val;
209
+ grid. 0 [ letter_size - x] [ y + pos] = val;
208
210
}
209
211
}
210
212
}
211
213
212
214
/// Gradient getting brighter from top to bottom
213
215
pub fn gradient ( ) -> Grid {
214
- let mut grid: Grid = [ [ 0 ; 34 ] ; 9 ] ;
215
- for y in 0 ..34 {
216
- for x in 0 ..9 {
217
- grid[ x] [ y] = ( 1 * ( y + 1 ) ) as u8 ;
216
+ let gradient_drop = 1 ; // Brightness drop between rows
217
+ let mut grid = Grid :: default ( ) ;
218
+ for y in 0 ..HEIGHT {
219
+ for x in 0 ..WIDTH {
220
+ grid. 0 [ x] [ y] = ( gradient_drop * ( y + 1 ) ) as u8 ;
218
221
}
219
222
}
220
223
grid
221
224
}
222
225
223
226
/// Fill a percentage of the rows from the bottom up
224
227
pub fn percentage ( percentage : u16 ) -> Grid {
225
- let mut grid: Grid = [ [ 0 ; 34 ] ; 9 ] ;
226
- let first_row = 34 * percentage / 100 ;
227
- for y in ( 34 - first_row) ..34 {
228
- for x in 0 ..9 {
229
- grid[ x] [ y as usize ] = 0xFF ;
228
+ let mut grid = Grid :: default ( ) ;
229
+ let first_row = HEIGHT * ( percentage as usize ) / 100 ;
230
+ for y in ( HEIGHT - first_row) ..HEIGHT {
231
+ for x in 0 ..WIDTH {
232
+ grid. 0 [ x] [ y] = 0xFF ;
230
233
}
231
234
}
232
235
grid
233
236
}
234
237
235
238
/// Double sided gradient, bright in the middle, dim top and bottom
236
239
pub fn double_gradient ( ) -> Grid {
237
- let mut grid: Grid = [ [ 0 ; 34 ] ; 9 ] ;
238
- for y in 0 ..( 34 / 2 ) {
239
- for x in 0 ..9 {
240
- grid[ x] [ y] = ( 1 * ( y + 1 ) ) as u8 ;
240
+ let gradient_drop = 1 ; // Brightness drop between rows
241
+ let mut grid = Grid :: default ( ) ;
242
+ for y in 0 ..( HEIGHT / 2 ) {
243
+ for x in 0 ..WIDTH {
244
+ grid. 0 [ x] [ y] = ( gradient_drop * ( y + 1 ) ) as u8 ;
241
245
}
242
246
}
243
- for y in ( 34 / 2 ) ..34 {
244
- for x in 0 ..9 {
245
- grid[ x] [ y] = 34 - ( 1 * ( y + 1 ) ) as u8 ;
247
+ for y in ( HEIGHT / 2 ) ..HEIGHT {
248
+ for x in 0 ..WIDTH {
249
+ grid. 0 [ x] [ y] = ( HEIGHT - gradient_drop * ( y + 1 ) ) as u8 ;
246
250
}
247
251
}
248
252
grid
249
253
}
250
254
251
- pub fn fill_grid ( grid : Grid , matrix : & mut Foo ) {
252
- for y in 0 ..34 {
253
- for x in 0 ..9 {
254
- matrix
255
- . device
256
- . pixel ( x, y, grid[ x as usize ] [ y as usize ] )
257
- . unwrap ( ) ;
255
+ pub fn fill_grid ( grid : & Grid , matrix : & mut Foo ) {
256
+ for y in 0 ..HEIGHT {
257
+ for x in 0 ..WIDTH {
258
+ matrix. device . pixel ( x as u8 , y as u8 , grid. 0 [ x] [ y] ) . unwrap ( ) ;
258
259
}
259
260
}
260
261
}
261
262
262
- pub fn fill_grid_pixels ( grid : Grid , matrix : & mut Foo ) {
263
+ pub fn fill_grid_pixels ( grid : & Grid , matrix : & mut Foo ) {
264
+ // B4 LEDs on the first page, 0xAB on the second page
263
265
let mut brightnesses = [ 0x00 ; 0xB4 + 0xAB ] ;
264
- for y in 0 ..34 {
265
- for x in 0 ..9 {
266
- let ( register, page) = ( matrix. device . calc_pixel ) ( x, y) ;
267
- brightnesses[ ( page * 0xAA + register) as usize ] = grid[ x as usize ] [ y as usize ] ;
266
+ for y in 0 ..HEIGHT {
267
+ for x in 0 ..WIDTH {
268
+ let ( register, page) = ( matrix. device . calc_pixel ) ( x as u8 , y as u8 ) ;
269
+ brightnesses[ ( page * 0xAA + register) as usize ] = grid. 0 [ x ] [ y] ;
268
270
}
269
271
}
270
272
matrix. device . fill_matrix ( & brightnesses) . unwrap ( ) ;
271
273
}
272
274
273
275
pub fn full_brightness ( matrix : & mut Foo ) {
274
276
// Fills every pixel individually
275
- matrix. fill_brightness ( 0xFF ) . unwrap ( ) ;
277
+ // matrix.fill_brightness(0xFF).unwrap();
276
278
277
279
// Fills full page at once
278
- // matrix.device.fill(0xFF).unwrap();
280
+ matrix. device . fill ( 0xFF ) . unwrap ( ) ;
279
281
}
280
282
281
283
pub fn zigzag ( ) -> Grid {
282
- let mut grid: Grid = [ [ 0 ; 34 ] ; 9 ] ;
284
+ let mut grid = Grid :: default ( ) ;
285
+
283
286
// 1st Right to left
284
- for i in 0 ..9 {
285
- grid[ i] [ i] = 0xFF ;
287
+ for i in 0 ..WIDTH {
288
+ grid. 0 [ i] [ i] = 0xFF ;
286
289
}
287
290
// 1st Left to right
288
- for i in 0 ..9 {
289
- grid[ 8 - i] [ 9 + i] = 0xFF ;
291
+ for i in 0 ..WIDTH {
292
+ grid. 0 [ WIDTH - 1 - i] [ WIDTH + i] = 0xFF ;
290
293
}
291
294
// 2nd right to left
292
- for i in 0 ..9 {
293
- grid[ i] [ 18 + i] = 0xFF ;
295
+ for i in 0 ..WIDTH {
296
+ grid. 0 [ i] [ 2 * WIDTH + i] = 0xFF ;
294
297
}
295
298
// 2nd left to right
296
- for i in 0 ..9 {
297
- if 27 + i < 34 {
298
- grid[ 8 - i] [ 27 + i] = 0xFF ;
299
+ for i in 0 ..WIDTH {
300
+ if 3 * WIDTH + i < HEIGHT {
301
+ grid. 0 [ WIDTH - 1 - i] [ 3 * WIDTH + i] = 0xFF ;
299
302
}
300
303
}
301
- grid[ 1 ] [ 33 ] = 0xFF ;
304
+
305
+ // Finish it off nicely
306
+ grid. 0 [ 1 ] [ 33 ] = 0xFF ;
307
+
302
308
grid
303
309
}
0 commit comments