Crate sensehat_screen [] [src]

A Rust library for the Raspberry Pi Sense HAT LED Screen

The Raspberry Pi Sense HAT has an 8×8 RGB LED matrix that provides its own driver for the Linux framebuffer.

This library provides a thread-safe, strong-typed, high-level API for the LED matrix, treating it as you would any other screen on a Linux box.

Example

The following program shows how to:

  • Open the framebuffer file-descriptor for the LED matrix screen (screen)
  • Define a pixel color (red_pixel)
  • Define a vector of each pixel color that makes up the screen (all_64_pixels)
  • Turn that vector into a valid screen frame
  • Show the frame on the screen
extern crate sensehat_screen;

#[cfg(feature = "default")]
use sensehat_screen::{FrameLine, PixelColor, Screen};

#[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").expect("Could not open the framebuffer for the screen");

    let red_pixel = PixelColor::new(255, 0, 0); // rgb colors are in the range of 0 <= c < 256.

    let all_64_pixels = vec![red_pixel; 64];   // A single vector of 8 x 8 = 64 pixel colors (rows are grouped by chunks of 8)

    let all_red_screen = FrameLine::from_pixels(&all_64_pixels); // a screen frame

    screen.write_frame(&all_red_screen); // show the frame on the LED matrix
}

Features

default

By default, the linux-framebuffer, fonts, and serde-support features are included.

linux-framebuffer

Use the Linux framebuffer to write to the LED matrix.

fonts

A collection of legacy 8x8 fonts, renderable on the LED matrix.

rotate

In default. Support for rotating PixelFrames by 90-degree steps.

serde-support

Enables support for serialization/deserialization with serde.

big-endian

Uses big-endian format, suitable for non-AMD64/x86-64 processors. This is used when encoding/decoding 16-bit RGB565 to/from 24-bit RGB.

Re-exports

pub use self::color::PixelColor;
pub use self::fonts::FontCollection;
pub use self::fonts::FontString;
pub use self::frame::FrameLine;
pub use self::frame::PixelFrame;
pub use self::screen::Screen;

Modules

color

RGB color for LED pixels, with RGB565 rendering support.

fonts

8x8 font collection

frame

Frames for the LED Matrix screen

screen

Framebuffer support for the Sense HAT LED Matrix.

Structs

FramebufferError

Functions

font_to_frame

Render a font symbol with a PixelColor into a FrameLine.

font_to_pixel_frame

Render a font symbol with a PixelColor into a FrameLine.