simulate-lcd

A simple library to simulate monochrome dot-matrix displays, such as monochrome LCD screens.

Example

``` use std::{thread::sleep, time::Duration};

use rand::{threadrng, Rng}; use sdl2::event::Event; use simulatelcd::{Bitmap, LcdScreen, LCDDARKGREEN, LCDLIGHTGREEN};

const NANOSPERSEC: u64 = 1000000_000;

fn main() { let sdlcontext = sdl2::init().unwrap(); let mut screen = LcdScreen::<64, 96>::new( &sdlcontext, "LCD Demo: Random", LCDDARKGREEN, LCDLIGHTGREEN, 10, 10, ) .unwrap();

let mut event_pump = sdl_context.event_pump().unwrap();
'running: loop {
    for event in event_pump.poll_iter() {
        match event {
            Event::Quit { .. } => break 'running,
            _ => {}
        }
    }

    let mut rng = thread_rng();
    let random_bits: Vec<[bool; 96]> = (0..64).map(|_| rng.gen()).collect();
    screen.draw_bitmap(&random_bits.try_into().unwrap()).unwrap();

    sleep(Duration::new(0, NANOS_PER_SEC / 60));
}

} ```

More examples can be found in the examples folder.

Usage

LcdScreen is the main type provided by this crate. To create new simulated screen window with R rows and C columns of dots, use the function LcdScreen::<R, C>::new, with the following parameters:

The screen will disappear as soon as the LcdScreen object is dropped, including at the end of the scope it was created. Use a loop, or some other device, to stop the screen object from being dropped.

New images can be drawn to the screen using the draw_bitmap method. draw_bitmap takes any object which can be converted into a [[bool;C]; R] array. Each true in this row-major array represents a dot that is 'on'. simulate-lcd offers Bitmap<C, R> as a convenient alias for [[bool;C]; R].

The 'on' and 'off' colors of the screen are sdl2::pixels::Color objects. They can be created from RGB values with the sdl2::pixels::Color::RGB function. simulate-lcd offers the LCD_DARK_GREEN and LCD_LIGHT_GREEN constants from simulating green backlight LCD screens.

Setup

simulate-lcd is built around the sdl2 crate. A new LcdScreen requires an Sdl context object created by the sdl2::init() function. Note that sdl2 may require further setup than just adding the crate. See the sdl2 README for details.

License

Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).