sensehat_screen/
lib.rs

1//! A Rust library for the Raspberry Pi Sense HAT LED Screen
2//! ========================================================
3//!
4//! The [Raspberry Pi Sense HAT](https://www.raspberrypi.org/products/sense-hat/) has an 8×8 RGB LED matrix that provides its own driver for the Linux framebuffer.
5//!
6//! This library provides a thread-safe, strong-typed, high-level API for the LED matrix, treating
7//! it as you would any other screen on a Linux box.
8//!
9//! For examples, please check the
10//! [examples/](https://github.com/saibatizoku/sensehat-screen-rs/tree/master/examples) folder in the source code.
11//!
12//! Basics
13//! ------
14//! * [`Screen`](./screen/struct.Screen.html) offers a high-level API for the LED Matrix.
15//!
16//!   Internally, it stores a `PixelFrame` meant to be rendered on the LED Matrix.
17//!
18//!   With the `linux-framebuffer` feature, enabled by default, `Screen` will have two methods:
19//!
20//!     1. `Screen::open` which opens the framebuffer
21//!        file-descriptor given as the only argument.
22//!
23//!     1. `Screen::write_frame` which takes a
24//!        `&FrameLine` and writes the raw bytes onto the framebuffer, effectively displaying the
25//!        `PixelFrame` on the LED Matrix.
26//!
27//! * [`PixelFrame`](./frame/struct.PixelFrame.html) is a collection of 64 `PixelColor`, representing the 8-row by 8-column LED
28//! Matrix.
29//! * [`PixelColor`](./color/struct.PixelColor.html) is a 24-bit representation of an RGB color, encoded in three bytes.
30//!
31//! Low-level constructs
32//! --------------------
33//! * [`Rgb565`](./color/struct.Rgb565.html) is a 16-bit representation of an RGB color, encoded in two bytes. This is the
34//! format. `Rgb565` converts into/from `PixelColor`.
35//! supported by the LED Matrix's framebuffer device.
36//! * [`FrameLine`](./frame/struct.FrameLine.html) is the raw-byte rendering of the `PixelFrame`,
37//! properly encoded and ready to be written into the framebuffer device.
38//!
39//! Frame operations
40//! ----------------
41//! * [`Rotate`](./frame/rotate/enum.Rotate.html)
42//!
43//!   Requires `feature = "rotate"`, which is enabled by default.
44//!
45//!   Rotate the PixelFrame by `Rotate::None`, `Rotate::Ccw90`, `Rotate::Ccw180`, or
46//!   `Rotate::Ccw270`, that correspond to a counter-clockwise angle of `0°`, `90°`, `180°`, and `270°`,
47//!   respectively.
48//!
49//! * [`Offset`](./frame/offset/enum.Offset.html)
50//!
51//!   Requires `feature = "offset"`, which is enabled by default.
52//!
53//!   Offset the PixelFrame by `Offset::left(n)`, `Offset::right(n)`,
54//!   `Offset::bottom(n)`, or `Offset::top(n)`, where `n` is an integer between in the `0..=8` range.
55//!
56//!   `Offset` with a value of `n = 0`, return a clone of the `PixelFrame`.
57//!
58//!   `Offset` with a value of `n = 8`, return a `PixelFrame` offset out of view, represented with black pixels (LEDs are off).
59//!
60//! * [`Clip`](./frame/clip/struct.Clip.html)
61//!
62//!   Requires `feature = "clip"`, which is enabled by default.
63//!
64//!   Creates a clip of two `PixelFrame`s, by defining an
65//!   `Offset`. See the [clip documentation](./frame/clip/struct.Clip.html) for more details.
66#[cfg(feature = "fonts")]
67extern crate font8x8;
68#[macro_use]
69extern crate lazy_static;
70#[cfg(feature = "linux-framebuffer")]
71pub extern crate framebuffer;
72#[cfg(feature = "serde-support")]
73extern crate serde;
74#[cfg(feature = "serde-support")]
75#[macro_use]
76extern crate serde_derive;
77
78// RGB color with RGB565 support
79pub mod color;
80// Screen frames
81pub mod frame;
82// Screen errors
83pub mod error;
84// 8x8 fonts
85#[cfg(feature = "fonts")]
86pub mod fonts;
87#[cfg(feature = "linux-framebuffer")]
88#[path = "framebuffer.rs"]
89pub mod screen;
90// Scrolls for collections of PixelFrames
91#[cfg(feature = "scroll")]
92pub mod scroll;
93
94// Re-exports
95pub use self::color::{BackgroundColor, PixelColor, StrokeColor};
96
97#[cfg(feature = "fonts")]
98pub use self::fonts::{
99    font_to_frame, font_to_pixel_frame, FontCollection, FontString, FONT_COLLECTION, FONT_HASHMAP,
100};
101
102#[cfg(feature = "clip")]
103pub use self::frame::clip::Clip;
104
105#[cfg(any(feature = "offset", feature = "clip"))]
106pub use self::frame::Offset;
107
108#[cfg(feature = "rotate")]
109pub use self::frame::rotate::Rotate;
110
111pub use self::frame::{FrameLine, PixelFrame};
112
113#[cfg(feature = "linux-framebuffer")]
114pub use self::screen::Screen;
115
116#[cfg(feature = "scroll")]
117pub use self::scroll::Scroll;