Fix example

This commit is contained in:
Wesley Moore 2022-02-08 18:56:53 +10:00
parent 61b6ea9d59
commit b34424dde7
No known key found for this signature in database
GPG key ID: BF67766C0BC2D0EE

View file

@ -10,11 +10,13 @@ use ssd1675::{Builder, Color, Dimensions, Display, GraphicDisplay, Rotation};
// Graphics // Graphics
#[macro_use] #[macro_use]
extern crate embedded_graphics; extern crate embedded_graphics;
use embedded_graphics::mono_font::MonoTextStyle;
use embedded_graphics::prelude::*; use embedded_graphics::prelude::*;
use embedded_graphics::text::Text;
// Font // Font
extern crate profont; extern crate profont;
use profont::{ProFont12Point, ProFont14Point, ProFont24Point, ProFont9Point}; use profont::{PROFONT_12_POINT, PROFONT_14_POINT, PROFONT_24_POINT, PROFONT_9_POINT};
use std::process::Command; use std::process::Command;
use std::thread::sleep; use std::thread::sleep;
@ -116,66 +118,46 @@ fn main() -> Result<(), std::io::Error> {
display.clear(Color::White); display.clear(Color::White);
println!("Clear"); println!("Clear");
egtext!( Text::new(
text = "Raspberry Pi", "Raspberry Pi",
top_left = (1, -4), Point::new(1, -4),
style = text_style!( MonoTextStyle::new(&PROFONT_24_POINT, Color::Red),
font = ProFont24Point,
background_color = Color::White,
text_color = Color::Red,
)
) )
.draw(&mut display) .draw(&mut display)
.expect("error drawing text"); .expect("error drawing text");
if let Ok(cpu_temp) = read_cpu_temp() { if let Ok(cpu_temp) = read_cpu_temp() {
egtext!( Text::new(
text = "CPU Temp:", "CPU Temp:",
top_left = (1, 30), Point::new(1, 30),
style = text_style!( MonoTextStyle::new(&PROFONT_14_POINT, Color::Black),
font = ProFont14Point,
background_color = Color::White,
text_color = Color::Black,
)
) )
.draw(&mut display) .draw(&mut display)
.expect("error drawing text"); .expect("error drawing text");
egtext!( Text::new(
text = &format!("{:.1}°C", cpu_temp), &format!("{:.1}°C", cpu_temp),
top_left = (95, 34), Point::new(95, 34),
style = text_style!( MonoTextStyle::new(&PROFONT_12_POINT, Color::Black),
font = ProFont12Point,
background_color = Color::White,
text_color = Color::Black,
)
) )
.draw(&mut display) .draw(&mut display)
.expect("error drawing text"); .expect("error drawing text");
} }
if let Some(uptime) = read_uptime() { if let Some(uptime) = read_uptime() {
egtext!( Text::new(
text = uptime.trim(), uptime.trim(),
top_left = (1, 93), Point::new(1, 93),
style = text_style!( MonoTextStyle::new(&PROFONT_9_POINT, Color::Black),
font = ProFont9Point,
background_color = Color::White,
text_color = Color::Black,
)
) )
.draw(&mut display) .draw(&mut display)
.expect("error drawing text"); .expect("error drawing text");
} }
if let Some(uname) = read_uname() { if let Some(uname) = read_uname() {
egtext!( Text::new(
text = uname.trim(), uname.trim(),
top_left = (1, 84), Point::new(1, 84),
style = text_style!( MonoTextStyle::new(&PROFONT_9_POINT, Color::Black),
font = ProFont9Point,
background_color = Color::White,
text_color = Color::Black,
)
) )
.draw(&mut display) .draw(&mut display)
.expect("error drawing text"); .expect("error drawing text");