|
|
|
|
@ -1,17 +1,16 @@
|
|
|
|
|
#![deny(warnings)] |
|
|
|
|
|
|
|
|
|
use embedded_graphics::{ |
|
|
|
|
fonts::{Font12x16, Font6x8, Text}, |
|
|
|
|
mono_font::MonoTextStyleBuilder, |
|
|
|
|
prelude::*, |
|
|
|
|
primitives::{Circle, Line}, |
|
|
|
|
style::PrimitiveStyle, |
|
|
|
|
text_style, |
|
|
|
|
primitives::{Circle, Line, PrimitiveStyleBuilder}, |
|
|
|
|
text::{Baseline, Text, TextStyleBuilder}, |
|
|
|
|
}; |
|
|
|
|
use embedded_hal::prelude::*; |
|
|
|
|
use epd_waveshare::{ |
|
|
|
|
color::*, |
|
|
|
|
epd4in2::{Display4in2, Epd4in2}, |
|
|
|
|
graphics::{Display, DisplayRotation}, |
|
|
|
|
graphics::DisplayRotation, |
|
|
|
|
prelude::*, |
|
|
|
|
}; |
|
|
|
|
use linux_embedded_hal::{ |
|
|
|
|
@ -65,7 +64,7 @@ fn main() -> Result<(), std::io::Error> {
|
|
|
|
|
let mut epd4in2 = |
|
|
|
|
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 display = Display4in2::default(); |
|
|
|
|
|
|
|
|
|
display.set_rotation(DisplayRotation::Rotate0); |
|
|
|
|
@ -86,36 +85,44 @@ fn main() -> Result<(), std::io::Error> {
|
|
|
|
|
.expect("display frame new graphics"); |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
// draw a analog clock
|
|
|
|
|
let _ = Circle::new(Point::new(64, 64), 64) |
|
|
|
|
.into_styled(PrimitiveStyle::with_stroke(Black, 1)) |
|
|
|
|
let style = PrimitiveStyleBuilder::new() |
|
|
|
|
.stroke_color(Black) |
|
|
|
|
.stroke_width(1) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
let _ = Circle::with_center(Point::new(64, 64), 80) |
|
|
|
|
.into_styled(style) |
|
|
|
|
.draw(&mut display); |
|
|
|
|
let _ = Line::new(Point::new(64, 64), Point::new(0, 64)) |
|
|
|
|
.into_styled(PrimitiveStyle::with_stroke(Black, 1)) |
|
|
|
|
.into_styled(style) |
|
|
|
|
.draw(&mut display); |
|
|
|
|
let _ = Line::new(Point::new(64, 64), Point::new(80, 80)) |
|
|
|
|
.into_styled(PrimitiveStyle::with_stroke(Black, 1)) |
|
|
|
|
.into_styled(style) |
|
|
|
|
.draw(&mut display); |
|
|
|
|
|
|
|
|
|
// draw white on black background
|
|
|
|
|
let _ = Text::new("It's working-WoB!", Point::new(175, 250)) |
|
|
|
|
.into_styled(text_style!( |
|
|
|
|
font = Font6x8, |
|
|
|
|
text_color = White, |
|
|
|
|
background_color = Black |
|
|
|
|
)) |
|
|
|
|
let style = MonoTextStyleBuilder::new() |
|
|
|
|
.font(&embedded_graphics::mono_font::ascii::FONT_6X10) |
|
|
|
|
.text_color(White) |
|
|
|
|
.background_color(Black) |
|
|
|
|
.build(); |
|
|
|
|
let text_style = TextStyleBuilder::new().baseline(Baseline::Top).build(); |
|
|
|
|
|
|
|
|
|
let _ = Text::with_text_style("It's working-WoB!", Point::new(175, 250), style, text_style) |
|
|
|
|
.draw(&mut display); |
|
|
|
|
|
|
|
|
|
// use bigger/different font
|
|
|
|
|
let _ = Text::new("It's working-WoB!", Point::new(50, 200)) |
|
|
|
|
.into_styled(text_style!( |
|
|
|
|
font = Font12x16, |
|
|
|
|
text_color = White, |
|
|
|
|
background_color = Black |
|
|
|
|
)) |
|
|
|
|
let style = MonoTextStyleBuilder::new() |
|
|
|
|
.font(&embedded_graphics::mono_font::ascii::FONT_10X20) |
|
|
|
|
.text_color(White) |
|
|
|
|
.background_color(Black) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
let _ = Text::with_text_style("It's working-WoB!", Point::new(50, 200), style, text_style) |
|
|
|
|
.draw(&mut display); |
|
|
|
|
|
|
|
|
|
// a moving `Hello World!`
|
|
|
|
|
@ -142,11 +149,13 @@ fn main() -> Result<(), std::io::Error> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn draw_text(display: &mut Display4in2, text: &str, x: i32, y: i32) { |
|
|
|
|
let _ = Text::new(text, Point::new(x, y)) |
|
|
|
|
.into_styled(text_style!( |
|
|
|
|
font = Font6x8, |
|
|
|
|
text_color = Black, |
|
|
|
|
background_color = White |
|
|
|
|
)) |
|
|
|
|
.draw(display); |
|
|
|
|
let style = MonoTextStyleBuilder::new() |
|
|
|
|
.font(&embedded_graphics::mono_font::ascii::FONT_6X10) |
|
|
|
|
.text_color(White) |
|
|
|
|
.background_color(Black) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
let text_style = TextStyleBuilder::new().baseline(Baseline::Top).build(); |
|
|
|
|
|
|
|
|
|
let _ = Text::with_text_style(text, Point::new(x, y), style, text_style).draw(display); |
|
|
|
|
} |
|
|
|
|
|