forked from saibatizoku/sensehat-screen-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clip.rs
48 lines (41 loc) · 1.44 KB
/
clip.rs
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
#[cfg(feature = "default")]
extern crate sensehat_screen;
#[cfg(feature = "default")]
use sensehat_screen::Offset;
#[cfg(feature = "default")]
use sensehat_screen::{font_to_pixel_frame, PixelColor, PixelFrame, Screen, FONT_COLLECTION};
#[cfg(not(feature = "default"))]
fn main() {
unimplemented!("This examples needs the 'default' features.");
}
#[cfg(feature = "default")]
fn main() {
let mut screen = Screen::open("/dev/fb1").unwrap();
let letters = "a e i o u ";
let letter_color = PixelColor::YELLOW.dim(0.5);
let frames = letters
.chars()
.map(|sym| {
let font = FONT_COLLECTION.get(sym).unwrap();
font_to_pixel_frame(font.byte_array(), letter_color)
})
.collect::<Vec<PixelFrame>>();
// create a sequence of clips that will scroll each character-whitespace pair
// from appearing to move from right to left.
let frame_reel: Vec<PixelFrame> = frames.chunks(2).fold(Vec::new(), |mut v, chunk| match chunk
.len()
{
2 => {
let clip = chunk[0].build_clip(&chunk[1]);
for i in 0..=8 {
v.push(clip.offset(Offset::left(i)));
}
v
}
_ => panic!("this frame reel will only display &str of even length (divisible by 2)"),
});
for frame in &frame_reel {
screen.write_frame(&frame.frame_line());
::std::thread::sleep(::std::time::Duration::from_millis(750));
}
}