mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-03 22:06:43 +00:00
Various improvements (#25)
- Added is_busy to Waveshare_Interface - Added IS_BUSY_LOW const for all supported epds - Added is_busy to DisplayInterface - moved width, height and default_background_color directly to epd4in2 module - Added VarDisplay (a variable buffersize display/graphic driver) - Removed all Buffers (Buffer1in54,...) and instead made specialised Displays (Display1in54,...) with included Buffers - Updated and added more examples - Cargo fmt/clippy - Improved Docs/Readmes
This commit is contained in:
+13
-5
@@ -1,12 +1,20 @@
|
||||
# Examples:
|
||||
|
||||
### embedded_linux_epd4in2
|
||||
All of these examples are projects of their own.
|
||||
|
||||
Basic example of using a Raspberry Pi with the 4in2 Waveshare E-Ink Display.
|
||||
A few notes:
|
||||
- If not stated otherwise the example is for a Raspberry Pi running Linux.
|
||||
- epdXinYY_full showcase most of what can be done with this crate. This means that they are using graphics feature and use the DisplayXinYY with its buffer.
|
||||
|
||||
It showcases most of what can be done with the crate.
|
||||
Special Examples:
|
||||
|
||||
### epd4in2_var_display_buffer
|
||||
|
||||
This examples used the graphics feature with VarDisplay and therefore a variable buffer(size).
|
||||
|
||||
### epd1in54_no_graphics (Fastest Example)
|
||||
|
||||
This example doesn't use the graphics feature and handles all the "drawing" by itself. It also has a speeddemonstration included.
|
||||
|
||||
### embedded_linux_epd1in54
|
||||
|
||||
This example doesn't use the graphics feature of the crate and shows the fast update rate of the 1in54 EPD.
|
||||
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
name = "embedded_linux_eink_example"
|
||||
version = "0.1.0"
|
||||
authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
epd-waveshare = { path = "../../", default-features = false, features = ["epd1in54", "graphics"]}
|
||||
|
||||
linux-embedded-hal = "0.2.1"
|
||||
|
||||
embedded-graphics = "0.4.3"
|
||||
|
||||
embedded-hal = { version = "0.2.1", features = ["unproven"] }
|
||||
linux-embedded-hal = "0.2.2"
|
||||
embedded-graphics = "0.4.5"
|
||||
embedded-hal = { version = "0.2.2", features = ["unproven"] }
|
||||
@@ -1,36 +1,26 @@
|
||||
// the library for the embedded linux device
|
||||
extern crate linux_embedded_hal as lin_hal;
|
||||
use lin_hal::spidev::{self, SpidevOptions};
|
||||
use lin_hal::sysfs_gpio::Direction;
|
||||
use lin_hal::Delay;
|
||||
use lin_hal::{Pin, Spidev};
|
||||
#![deny(warnings)]
|
||||
|
||||
// the eink library
|
||||
extern crate epd_waveshare;
|
||||
use embedded_graphics::{coord::Coord, fonts::Font6x8, prelude::*, Drawing};
|
||||
use embedded_hal::prelude::*;
|
||||
use epd_waveshare::{
|
||||
epd1in54::{Buffer1in54, EPD1in54},
|
||||
epd1in54::{Display1in54, EPD1in54},
|
||||
graphics::{Display, DisplayRotation},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
// Graphics
|
||||
extern crate embedded_graphics;
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::fonts::Font6x8;
|
||||
use embedded_graphics::prelude::*;
|
||||
//use embedded_graphics::primitives::{Circle, Line};
|
||||
use embedded_graphics::Drawing;
|
||||
|
||||
// HAL (Traits)
|
||||
extern crate embedded_hal;
|
||||
use embedded_hal::prelude::*;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
sysfs_gpio::Direction,
|
||||
Delay, Pin, Spidev,
|
||||
};
|
||||
|
||||
// activate spi, gpio in raspi-config
|
||||
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
|
||||
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
|
||||
|
||||
fn main() {
|
||||
run().unwrap();
|
||||
if let Err(e) = run() {
|
||||
eprintln!("Program exited early with error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), std::io::Error> {
|
||||
@@ -86,8 +76,7 @@ fn run() -> Result<(), std::io::Error> {
|
||||
epd.display_frame(&mut spi).expect("disp 1");
|
||||
|
||||
println!("Test all the rotations");
|
||||
let mut buffer = Buffer1in54::default();
|
||||
let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer);
|
||||
let mut display = Display1in54::default();
|
||||
display.set_rotation(DisplayRotation::Rotate0);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 0!")
|
||||
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "embedded_linux_eink_example"
|
||||
version = "0.1.0"
|
||||
authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
epd-waveshare = { path = "../../", default-features = false, features = ["epd1in54"]}
|
||||
|
||||
linux-embedded-hal = "0.2.2"
|
||||
embedded-hal = { version = "0.2.2", features = ["unproven"] }
|
||||
@@ -0,0 +1,105 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
use embedded_hal::prelude::*;
|
||||
use epd_waveshare::{epd1in54::EPD1in54, prelude::*};
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
sysfs_gpio::Direction,
|
||||
Delay, Pin, Spidev,
|
||||
};
|
||||
|
||||
// activate spi, gpio in raspi-config
|
||||
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
|
||||
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
|
||||
|
||||
fn main() {
|
||||
if let Err(e) = run() {
|
||||
eprintln!("Program exited early with error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), std::io::Error> {
|
||||
// Configure SPI
|
||||
// SPI settings are from eink-waveshare-rs documenation
|
||||
let mut spi = Spidev::open("/dev/spidev0.0")?;
|
||||
let options = SpidevOptions::new()
|
||||
.bits_per_word(8)
|
||||
.max_speed_hz(4_000_000)
|
||||
.mode(spidev::SPI_MODE_0)
|
||||
.build();
|
||||
spi.configure(&options).expect("spi configuration");
|
||||
|
||||
// Configure Digital I/O Pin to be used as Chip Select for SPI
|
||||
let cs_pin = Pin::new(26); //BCM7 CE0
|
||||
cs_pin.export().expect("cs_pin export");
|
||||
while !cs_pin.is_exported() {}
|
||||
cs_pin
|
||||
.set_direction(Direction::Out)
|
||||
.expect("cs_pin Direction");
|
||||
cs_pin.set_value(1).expect("cs_pin Value set to 1");
|
||||
|
||||
// Configure Busy Input Pin
|
||||
let busy = Pin::new(5); //pin 29
|
||||
busy.export().expect("busy export");
|
||||
while !busy.is_exported() {}
|
||||
busy.set_direction(Direction::In).expect("busy Direction");
|
||||
//busy.set_value(1).expect("busy Value set to 1");
|
||||
|
||||
// Configure Data/Command OutputPin
|
||||
let dc = Pin::new(6); //pin 31 //bcm6
|
||||
dc.export().expect("dc export");
|
||||
while !dc.is_exported() {}
|
||||
dc.set_direction(Direction::Out).expect("dc Direction");
|
||||
dc.set_value(1).expect("dc Value set to 1");
|
||||
|
||||
// Configure Reset OutputPin
|
||||
let rst = Pin::new(16); //pin 36 //bcm16
|
||||
rst.export().expect("rst export");
|
||||
while !rst.is_exported() {}
|
||||
rst.set_direction(Direction::Out).expect("rst Direction");
|
||||
rst.set_value(1).expect("rst Value set to 1");
|
||||
|
||||
// Configure Delay
|
||||
let mut delay = Delay {};
|
||||
|
||||
// Setup of the needed pins is finished here
|
||||
// Now the "real" usage of the eink-waveshare-rs crate begins
|
||||
let mut epd = EPD1in54::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?;
|
||||
|
||||
// Clear the full screen
|
||||
epd.clear_frame(&mut spi)?;
|
||||
epd.display_frame(&mut spi)?;
|
||||
|
||||
// Speeddemo
|
||||
epd.set_lut(&mut spi, Some(RefreshLUT::QUICK))?;
|
||||
let small_buffer = [Color::Black.get_byte_value(); 32]; //16x16
|
||||
let number_of_runs = 1;
|
||||
for i in 0..number_of_runs {
|
||||
let offset = i * 8 % 150;
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 25 + offset, 25 + offset, 16, 16)?;
|
||||
epd.display_frame(&mut spi)?;
|
||||
}
|
||||
|
||||
// Clear the full screen
|
||||
epd.clear_frame(&mut spi)?;
|
||||
epd.display_frame(&mut spi)?;
|
||||
|
||||
// Draw some squares
|
||||
let small_buffer = [Color::Black.get_byte_value(); 3200]; //160x160
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 20, 20, 160, 160)?;
|
||||
|
||||
let small_buffer = [Color::White.get_byte_value(); 800]; //80x80
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 60, 60, 80, 80)?;
|
||||
|
||||
let small_buffer = [Color::Black.get_byte_value(); 8]; //8x8
|
||||
epd.update_partial_frame(&mut spi, &small_buffer, 96, 96, 8, 8)?;
|
||||
|
||||
// Display updated frame
|
||||
epd.display_frame(&mut spi)?;
|
||||
delay.delay_ms(5000u16);
|
||||
|
||||
// Set the EPD to sleep
|
||||
epd.sleep(&mut spi)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -2,13 +2,12 @@
|
||||
name = "embedded_linux_eink_example"
|
||||
version = "0.1.0"
|
||||
authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
epd-waveshare = { path = "../../", default-features = false, features = ["epd2in9", "graphics"]}
|
||||
|
||||
linux-embedded-hal = "0.2.1"
|
||||
|
||||
embedded-graphics = "0.4.3"
|
||||
|
||||
embedded-hal = { version = "0.2.1", features = ["unproven"] }
|
||||
linux-embedded-hal = "0.2.2"
|
||||
embedded-graphics = "0.4.5"
|
||||
embedded-hal = { version = "0.2.2", features = ["unproven"] }
|
||||
@@ -1,29 +1,17 @@
|
||||
// the library for the embedded linux device
|
||||
extern crate linux_embedded_hal as lin_hal;
|
||||
use lin_hal::spidev::{self, SpidevOptions};
|
||||
use lin_hal::sysfs_gpio::Direction;
|
||||
use lin_hal::Delay;
|
||||
use lin_hal::{Pin, Spidev};
|
||||
#![deny(warnings)]
|
||||
|
||||
// the eink library
|
||||
extern crate epd_waveshare;
|
||||
use embedded_graphics::{coord::Coord, fonts::Font6x8, prelude::*, Drawing};
|
||||
use embedded_hal::prelude::*;
|
||||
use epd_waveshare::{
|
||||
epd2in9::{Buffer2in9, EPD2in9},
|
||||
epd2in9::{Display2in9, EPD2in9},
|
||||
graphics::{Display, DisplayRotation},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
// Graphics
|
||||
extern crate embedded_graphics;
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::fonts::Font6x8;
|
||||
use embedded_graphics::prelude::*;
|
||||
//use embedded_graphics::primitives::{Circle, Line};
|
||||
use embedded_graphics::Drawing;
|
||||
|
||||
// HAL (Traits)
|
||||
extern crate embedded_hal;
|
||||
use embedded_hal::prelude::*;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
sysfs_gpio::Direction,
|
||||
Delay, Pin, Spidev,
|
||||
};
|
||||
|
||||
// activate spi, gpio in raspi-config
|
||||
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
|
||||
@@ -31,7 +19,9 @@ use embedded_hal::prelude::*;
|
||||
|
||||
//TODO: Test this implemenation with a new display
|
||||
fn main() {
|
||||
run().unwrap();
|
||||
if let Err(e) = run() {
|
||||
eprintln!("Program exited early with error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), std::io::Error> {
|
||||
@@ -87,8 +77,7 @@ fn run() -> Result<(), std::io::Error> {
|
||||
epd.display_frame(&mut spi).expect("disp 1");
|
||||
|
||||
println!("Test all the rotations");
|
||||
let mut buffer = Buffer2in9::default();
|
||||
let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer);
|
||||
let mut display = Display2in9::default();
|
||||
epd.update_frame(&mut spi, display.buffer()).unwrap();
|
||||
epd.display_frame(&mut spi).expect("display frame x03");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "embedded_linux_eink_example"
|
||||
version = "0.1.0"
|
||||
authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -9,8 +10,6 @@ authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
||||
#epd_waveshare = { path = "../../"}
|
||||
epd-waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]}
|
||||
|
||||
linux-embedded-hal = "0.2.1"
|
||||
|
||||
embedded-graphics = "0.4.3"
|
||||
|
||||
embedded-hal = { version = "0.2.1", features = ["unproven"] }
|
||||
linux-embedded-hal = "0.2.2"
|
||||
embedded-graphics = "0.4.5"
|
||||
embedded-hal = { version = "0.2.2", features = ["unproven"] }
|
||||
@@ -1,36 +1,32 @@
|
||||
// the library for the embedded linux device
|
||||
extern crate linux_embedded_hal as lin_hal;
|
||||
use lin_hal::spidev::{self, SpidevOptions};
|
||||
use lin_hal::sysfs_gpio::Direction;
|
||||
use lin_hal::Delay;
|
||||
use lin_hal::{Pin, Spidev};
|
||||
#![deny(warnings)]
|
||||
|
||||
// the eink library
|
||||
extern crate epd_waveshare;
|
||||
use embedded_graphics::{
|
||||
coord::Coord,
|
||||
fonts::{Font12x16, Font6x8},
|
||||
prelude::*,
|
||||
primitives::{Circle, Line},
|
||||
Drawing,
|
||||
};
|
||||
use embedded_hal::prelude::*;
|
||||
use epd_waveshare::{
|
||||
epd4in2::{Buffer4in2, EPD4in2},
|
||||
epd4in2::{Display4in2, EPD4in2},
|
||||
graphics::{Display, DisplayRotation},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
// Graphics
|
||||
extern crate embedded_graphics;
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::fonts::{Font12x16, Font6x8};
|
||||
use embedded_graphics::prelude::*;
|
||||
use embedded_graphics::primitives::{Circle, Line};
|
||||
use embedded_graphics::Drawing;
|
||||
|
||||
// HAL (Traits)
|
||||
extern crate embedded_hal;
|
||||
use embedded_hal::prelude::*;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
sysfs_gpio::Direction,
|
||||
Delay, Pin, Spidev,
|
||||
};
|
||||
|
||||
// activate spi, gpio in raspi-config
|
||||
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
|
||||
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
|
||||
|
||||
fn main() {
|
||||
run().map_err(|e| println!("{}", e.to_string())).unwrap();
|
||||
if let Err(e) = run() {
|
||||
eprintln!("Program exited early with error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), std::io::Error> {
|
||||
@@ -75,8 +71,7 @@ fn run() -> Result<(), std::io::Error> {
|
||||
EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initalize error");
|
||||
|
||||
println!("Test all the rotations");
|
||||
let mut buffer = Buffer4in2::default();
|
||||
let mut display = Display::new(epd4in2.width(), epd4in2.height(), &mut buffer.buffer);
|
||||
let mut display = Display4in2::default();
|
||||
display.set_rotation(DisplayRotation::Rotate0);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 0!")
|
||||
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "embedded_linux_eink_example"
|
||||
version = "0.1.0"
|
||||
authors = ["Christoph Groß <christoph-gross@mailbox.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
## The Only difference between this one and the one without default features sizewise seems to be a different .d-file Size (dependencies-file)
|
||||
#epd_waveshare = { path = "../../"}
|
||||
epd-waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]}
|
||||
|
||||
linux-embedded-hal = "0.2.2"
|
||||
embedded-graphics = "0.4.5"
|
||||
embedded-hal = { version = "0.2.2", features = ["unproven"] }
|
||||
@@ -0,0 +1,195 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
use embedded_graphics::{
|
||||
coord::Coord,
|
||||
fonts::{Font12x16, Font6x8},
|
||||
prelude::*,
|
||||
primitives::{Circle, Line},
|
||||
Drawing,
|
||||
};
|
||||
use embedded_hal::prelude::*;
|
||||
use epd_waveshare::{
|
||||
epd4in2::{self, EPD4in2},
|
||||
graphics::{Display, DisplayRotation, VarDisplay},
|
||||
prelude::*,
|
||||
};
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
sysfs_gpio::Direction,
|
||||
Delay, Pin, Spidev,
|
||||
};
|
||||
|
||||
// activate spi, gpio in raspi-config
|
||||
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
|
||||
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
|
||||
|
||||
fn main() {
|
||||
if let Err(e) = run() {
|
||||
eprintln!("Program exited early with error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), std::io::Error> {
|
||||
// Configure SPI
|
||||
// Settings are taken from
|
||||
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");
|
||||
let options = SpidevOptions::new()
|
||||
.bits_per_word(8)
|
||||
.max_speed_hz(4_000_000)
|
||||
.mode(spidev::SPI_MODE_0)
|
||||
.build();
|
||||
spi.configure(&options).expect("spi configuration");
|
||||
|
||||
// Configure Digital I/O Pin to be used as Chip Select for SPI
|
||||
let cs = Pin::new(26); //BCM7 CE0
|
||||
cs.export().expect("cs export");
|
||||
while !cs.is_exported() {}
|
||||
cs.set_direction(Direction::Out).expect("CS Direction");
|
||||
cs.set_value(1).expect("CS Value set to 1");
|
||||
|
||||
let busy = Pin::new(5); //pin 29
|
||||
busy.export().expect("busy export");
|
||||
while !busy.is_exported() {}
|
||||
busy.set_direction(Direction::In).expect("busy Direction");
|
||||
//busy.set_value(1).expect("busy Value set to 1");
|
||||
|
||||
let dc = Pin::new(6); //pin 31 //bcm6
|
||||
dc.export().expect("dc export");
|
||||
while !dc.is_exported() {}
|
||||
dc.set_direction(Direction::Out).expect("dc Direction");
|
||||
dc.set_value(1).expect("dc Value set to 1");
|
||||
|
||||
let rst = Pin::new(16); //pin 36 //bcm16
|
||||
rst.export().expect("rst export");
|
||||
while !rst.is_exported() {}
|
||||
rst.set_direction(Direction::Out).expect("rst Direction");
|
||||
rst.set_value(1).expect("rst Value set to 1");
|
||||
|
||||
let mut delay = Delay {};
|
||||
|
||||
let mut epd4in2 =
|
||||
EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initalize error");
|
||||
|
||||
println!("Test all the rotations");
|
||||
|
||||
let (x, y, width, height) = (50, 50, 250, 250);
|
||||
|
||||
let mut buffer = [epd4in2::DEFAULT_BACKGROUND_COLOR.get_byte_value(); 62500]; //250*250
|
||||
let mut display = VarDisplay::new(width, height, &mut buffer);
|
||||
display.set_rotation(DisplayRotation::Rotate0);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 0!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 90!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
display.set_rotation(DisplayRotation::Rotate180);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 180!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
display.set_rotation(DisplayRotation::Rotate270);
|
||||
display.draw(
|
||||
Font6x8::render_str("Rotate 270!")
|
||||
.with_stroke(Some(Color::Black))
|
||||
.with_fill(Some(Color::White))
|
||||
.translate(Coord::new(5, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
epd4in2
|
||||
.update_partial_frame(&mut spi, &display.buffer(), x, y, width, height)
|
||||
.unwrap();
|
||||
epd4in2
|
||||
.display_frame(&mut spi)
|
||||
.expect("display frame new graphics");
|
||||
delay.delay_ms(5000u16);
|
||||
|
||||
println!("Now test new graphics with default rotation and some special stuff:");
|
||||
display.clear_buffer(Color::White);
|
||||
|
||||
// draw a analog clock
|
||||
display.draw(
|
||||
Circle::new(Coord::new(64, 64), 64)
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
display.draw(
|
||||
Line::new(Coord::new(64, 64), Coord::new(0, 64))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
display.draw(
|
||||
Line::new(Coord::new(64, 64), Coord::new(80, 80))
|
||||
.with_stroke(Some(Color::Black))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// draw white on black background
|
||||
display.draw(
|
||||
Font6x8::render_str("It's working-WoB!")
|
||||
// Using Style here
|
||||
.with_style(Style {
|
||||
fill_color: Some(Color::Black),
|
||||
stroke_color: Some(Color::White),
|
||||
stroke_width: 0u8, // Has no effect on fonts
|
||||
})
|
||||
.translate(Coord::new(175, 250))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// use bigger/different font
|
||||
display.draw(
|
||||
Font12x16::render_str("It's working-BoW!")
|
||||
// Using Style here
|
||||
.with_style(Style {
|
||||
fill_color: Some(Color::White),
|
||||
stroke_color: Some(Color::Black),
|
||||
stroke_width: 0u8, // Has no effect on fonts
|
||||
})
|
||||
.translate(Coord::new(50, 200))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
// a moving `Hello World!`
|
||||
let limit = 10;
|
||||
for i in 0..limit {
|
||||
println!("Moving Hello World. Loop {} from {}", (i + 1), limit);
|
||||
|
||||
display.draw(
|
||||
Font6x8::render_str(" Hello World! ")
|
||||
.with_style(Style {
|
||||
fill_color: Some(Color::White),
|
||||
stroke_color: Some(Color::Black),
|
||||
stroke_width: 0u8, // Has no effect on fonts
|
||||
})
|
||||
.translate(Coord::new(5 + i * 12, 50))
|
||||
.into_iter(),
|
||||
);
|
||||
|
||||
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||
epd4in2
|
||||
.display_frame(&mut spi)
|
||||
.expect("display frame new graphics");
|
||||
|
||||
delay.delay_ms(1_000u16);
|
||||
}
|
||||
|
||||
println!("Finished tests - going to sleep");
|
||||
epd4in2.sleep(&mut spi)
|
||||
}
|
||||
Reference in New Issue
Block a user