run cargo fmt over 4in2 example
parent
bd79ffdbc6
commit
973b1d8982
|
|
@ -1,17 +1,14 @@
|
||||||
// the library for the embedded linux device
|
// the library for the embedded linux device
|
||||||
extern crate linux_embedded_hal as lin_hal;
|
extern crate linux_embedded_hal as lin_hal;
|
||||||
use lin_hal::spidev::{self, SpidevOptions};
|
use lin_hal::spidev::{self, SpidevOptions};
|
||||||
use lin_hal::{Pin, Spidev};
|
|
||||||
use lin_hal::sysfs_gpio::Direction;
|
use lin_hal::sysfs_gpio::Direction;
|
||||||
use lin_hal::Delay;
|
use lin_hal::Delay;
|
||||||
|
use lin_hal::{Pin, Spidev};
|
||||||
|
|
||||||
// the eink library
|
// the eink library
|
||||||
extern crate epd_waveshare;
|
extern crate epd_waveshare;
|
||||||
use epd_waveshare::{
|
use epd_waveshare::{
|
||||||
epd4in2::{
|
epd4in2::{Buffer4in2, EPD4in2},
|
||||||
EPD4in2,
|
|
||||||
Buffer4in2,
|
|
||||||
},
|
|
||||||
graphics::{Display, DisplayRotation},
|
graphics::{Display, DisplayRotation},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
@ -19,7 +16,7 @@ use epd_waveshare::{
|
||||||
// Graphics
|
// Graphics
|
||||||
extern crate embedded_graphics;
|
extern crate embedded_graphics;
|
||||||
use embedded_graphics::coord::Coord;
|
use embedded_graphics::coord::Coord;
|
||||||
use embedded_graphics::fonts::{Font6x8, Font12x16};
|
use embedded_graphics::fonts::{Font12x16, Font6x8};
|
||||||
use embedded_graphics::prelude::*;
|
use embedded_graphics::prelude::*;
|
||||||
use embedded_graphics::primitives::{Circle, Line};
|
use embedded_graphics::primitives::{Circle, Line};
|
||||||
use embedded_graphics::Drawing;
|
use embedded_graphics::Drawing;
|
||||||
|
|
@ -37,7 +34,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run() -> Result<(), std::io::Error> {
|
fn run() -> Result<(), std::io::Error> {
|
||||||
|
|
||||||
// Configure SPI
|
// Configure SPI
|
||||||
// Settings are taken from
|
// Settings are taken from
|
||||||
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");
|
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");
|
||||||
|
|
@ -49,13 +45,13 @@ fn run() -> Result<(), std::io::Error> {
|
||||||
spi.configure(&options).expect("spi configuration");
|
spi.configure(&options).expect("spi configuration");
|
||||||
|
|
||||||
// Configure Digital I/O Pin to be used as Chip Select for SPI
|
// Configure Digital I/O Pin to be used as Chip Select for SPI
|
||||||
let cs = Pin::new(26);//BCM7 CE0
|
let cs = Pin::new(26); //BCM7 CE0
|
||||||
cs.export().expect("cs export");
|
cs.export().expect("cs export");
|
||||||
while !cs.is_exported() {}
|
while !cs.is_exported() {}
|
||||||
cs.set_direction(Direction::Out).expect("CS Direction");
|
cs.set_direction(Direction::Out).expect("CS Direction");
|
||||||
cs.set_value(1).expect("CS Value set to 1");
|
cs.set_value(1).expect("CS Value set to 1");
|
||||||
|
|
||||||
let busy = Pin::new(5);//pin 29
|
let busy = Pin::new(5); //pin 29
|
||||||
busy.export().expect("busy export");
|
busy.export().expect("busy export");
|
||||||
while !busy.is_exported() {}
|
while !busy.is_exported() {}
|
||||||
busy.set_direction(Direction::In).expect("busy Direction");
|
busy.set_direction(Direction::In).expect("busy Direction");
|
||||||
|
|
@ -75,54 +71,54 @@ fn run() -> Result<(), std::io::Error> {
|
||||||
|
|
||||||
let mut delay = Delay {};
|
let mut delay = Delay {};
|
||||||
|
|
||||||
|
let mut epd4in2 =
|
||||||
let mut epd4in2 = EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initalize error");
|
EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initalize error");
|
||||||
|
|
||||||
println!("Test all the rotations");
|
println!("Test all the rotations");
|
||||||
let mut buffer = Buffer4in2::default();
|
let mut buffer = Buffer4in2::default();
|
||||||
let mut display = Display::new(epd4in2.width(), epd4in2.height(), &mut buffer.buffer);
|
let mut display = Display::new(epd4in2.width(), epd4in2.height(), &mut buffer.buffer);
|
||||||
display.set_rotation(DisplayRotation::Rotate0);
|
display.set_rotation(DisplayRotation::Rotate0);
|
||||||
display.draw(
|
display.draw(
|
||||||
Font6x8::render_str("Rotate 0!")
|
Font6x8::render_str("Rotate 0!")
|
||||||
.with_stroke(Some(Color::Black))
|
.with_stroke(Some(Color::Black))
|
||||||
.with_fill(Some(Color::White))
|
.with_fill(Some(Color::White))
|
||||||
.translate(Coord::new(5, 50))
|
.translate(Coord::new(5, 50))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|
||||||
display.set_rotation(DisplayRotation::Rotate90);
|
display.set_rotation(DisplayRotation::Rotate90);
|
||||||
display.draw(
|
display.draw(
|
||||||
Font6x8::render_str("Rotate 90!")
|
Font6x8::render_str("Rotate 90!")
|
||||||
.with_stroke(Some(Color::Black))
|
.with_stroke(Some(Color::Black))
|
||||||
.with_fill(Some(Color::White))
|
.with_fill(Some(Color::White))
|
||||||
.translate(Coord::new(5, 50))
|
.translate(Coord::new(5, 50))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|
||||||
display.set_rotation(DisplayRotation::Rotate180);
|
display.set_rotation(DisplayRotation::Rotate180);
|
||||||
display.draw(
|
display.draw(
|
||||||
Font6x8::render_str("Rotate 180!")
|
Font6x8::render_str("Rotate 180!")
|
||||||
.with_stroke(Some(Color::Black))
|
.with_stroke(Some(Color::Black))
|
||||||
.with_fill(Some(Color::White))
|
.with_fill(Some(Color::White))
|
||||||
.translate(Coord::new(5, 50))
|
.translate(Coord::new(5, 50))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|
||||||
display.set_rotation(DisplayRotation::Rotate270);
|
display.set_rotation(DisplayRotation::Rotate270);
|
||||||
display.draw(
|
display.draw(
|
||||||
Font6x8::render_str("Rotate 270!")
|
Font6x8::render_str("Rotate 270!")
|
||||||
.with_stroke(Some(Color::Black))
|
.with_stroke(Some(Color::Black))
|
||||||
.with_fill(Some(Color::White))
|
.with_fill(Some(Color::White))
|
||||||
.translate(Coord::new(5, 50))
|
.translate(Coord::new(5, 50))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
|
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||||
epd4in2.display_frame(&mut spi).expect("display frame new graphics");
|
epd4in2
|
||||||
|
.display_frame(&mut spi)
|
||||||
|
.expect("display frame new graphics");
|
||||||
delay.delay_ms(5000u16);
|
delay.delay_ms(5000u16);
|
||||||
|
|
||||||
|
|
||||||
println!("Now test new graphics with default rotation and some special stuff:");
|
println!("Now test new graphics with default rotation and some special stuff:");
|
||||||
display.clear_buffer(Color::White);
|
display.clear_buffer(Color::White);
|
||||||
|
|
||||||
|
|
@ -169,11 +165,10 @@ fn run() -> Result<(), std::io::Error> {
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// a moving `Hello World!`
|
// a moving `Hello World!`
|
||||||
let limit = 10;
|
let limit = 10;
|
||||||
for i in 0..limit {
|
for i in 0..limit {
|
||||||
println!("Moving Hello World. Loop {} from {}", (i+1), limit);
|
println!("Moving Hello World. Loop {} from {}", (i + 1), limit);
|
||||||
|
|
||||||
display.draw(
|
display.draw(
|
||||||
Font6x8::render_str(" Hello World! ")
|
Font6x8::render_str(" Hello World! ")
|
||||||
|
|
@ -182,17 +177,18 @@ fn run() -> Result<(), std::io::Error> {
|
||||||
stroke_color: Some(Color::Black),
|
stroke_color: Some(Color::Black),
|
||||||
stroke_width: 0u8, // Has no effect on fonts
|
stroke_width: 0u8, // Has no effect on fonts
|
||||||
})
|
})
|
||||||
.translate(Coord::new(5 + i*12, 50))
|
.translate(Coord::new(5 + i * 12, 50))
|
||||||
.into_iter(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|
||||||
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
|
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||||
epd4in2.display_frame(&mut spi).expect("display frame new graphics");
|
epd4in2
|
||||||
|
.display_frame(&mut spi)
|
||||||
|
.expect("display frame new graphics");
|
||||||
|
|
||||||
delay.delay_ms(1_000u16);
|
delay.delay_ms(1_000u16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
println!("Finished tests - going to sleep");
|
println!("Finished tests - going to sleep");
|
||||||
epd4in2.sleep(&mut spi)
|
epd4in2.sleep(&mut spi)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue