Skip to content

Commit 65d9905

Browse files
committed
Merge branch 'font' into main
2 parents f645704 + 7ad41b6 commit 65d9905

File tree

5 files changed

+63
-30
lines changed

5 files changed

+63
-30
lines changed

data/pcsenior.raw

960 Bytes
Binary file not shown.

docs/IMG_3890.webp

224 KB
Binary file not shown.

src/display.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
1+
use crate::display_types::{Display, PCSENIOR8_STYLE, FONT_6X12, FONT_5X8, PROFONT12};
12
use linux_embedded_hal::I2cdev;
2-
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306, mode::BufferedGraphicsMode};
3+
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
34
use display_interface::DisplayError;
45
use embedded_graphics::{
5-
mono_font::{ascii, MonoTextStyleBuilder, MonoTextStyle},
66
pixelcolor::BinaryColor,
77
prelude::*,
88
text::Text
99
};
10-
use profont::PROFONT_12_POINT;
1110

12-
const PROFONT12: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
13-
.font(&PROFONT_12_POINT)
14-
.text_color(BinaryColor::On)
15-
.build();
16-
17-
const FONT_6X12: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
18-
.font(&ascii::FONT_6X12)
19-
.text_color(BinaryColor::On)
20-
.build();
21-
22-
const FONT_5X8: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
23-
.font(&ascii::FONT_5X8)
24-
.text_color(BinaryColor::On)
25-
.build();
26-
27-
type Display = Ssd1306<I2CInterface<I2cdev>, DisplaySize128x32, BufferedGraphicsMode<DisplaySize128x32>>;
2811

2912
pub struct PoeDisplay {
3013
display: Display
@@ -47,44 +30,45 @@ impl PoeDisplay {
4730
) -> Result<(), DisplayError> {
4831
let disp = &mut self.display;
4932

50-
let y_offset = 8;
33+
let y_offset = 7;
5134
let display_width = 128;
5235
let char_width: i32 = 8;
5336
let x_margin = Point::new(2, 0).x_axis();
37+
let y_margin = Point::new(0, 1).y_axis();
5438

5539
disp.clear(BinaryColor::Off)?;
5640

5741
// top center: ip address
5842
let ip_width = ip_address.len() as i32 * char_width;
5943
let ip_x_position = (display_width - ip_width) / 2;
60-
Text::new(ip_address, Point::new(ip_x_position, y_offset), PROFONT12).draw(disp)?;
44+
Text::new(ip_address, Point::new(ip_x_position, y_offset), PCSENIOR8_STYLE).draw(disp)?;
6145

6246
// middle left: cpu usage
6347
let cpu_width = cpu_usage.len() as i32 * char_width;
6448
let cpu_point = Point::new(34 - cpu_width, 12 + y_offset);
65-
let next = Text::new(&cpu_usage, cpu_point, PROFONT12).draw(disp)?;
66-
let next = Text::new("%", next, FONT_6X12).draw(disp)?;
49+
let next = Text::new(&cpu_usage, cpu_point, PCSENIOR8_STYLE).draw(disp)?;
50+
let next = Text::new("%", next + y_margin, FONT_6X12).draw(disp)?;
6751
Text::new("CPU", next + x_margin, FONT_5X8).draw(disp)?;
6852

6953
// bottom left: ram usage
7054
let ram_width = ram_usage.len() as i32 * char_width;
7155
let ram_point = Point::new(34 - ram_width, 23 + y_offset);
72-
let next = Text::new(&ram_usage, ram_point, PROFONT12).draw(disp)?;
73-
let next = Text::new("%", next, FONT_6X12).draw(disp)?;
56+
let next = Text::new(&ram_usage, ram_point, PCSENIOR8_STYLE).draw(disp)?;
57+
let next = Text::new("%", next + y_margin, FONT_6X12).draw(disp)?;
7458
Text::new("RAM", next + x_margin, FONT_5X8).draw(disp)?;
7559

7660
// middle right: temp
7761
let temp_width = temp.len() as i32 * char_width;
7862
let temp_point = Point::new(99 - temp_width, 12 + y_offset);
79-
let next = Text::new(&temp, temp_point, PROFONT12).draw(disp)?;
80-
let next = Text::new("°", next, PROFONT12).draw(disp)?;
81-
Text::new("C", next, PROFONT12).draw(disp)?;
63+
let next = Text::new(&temp, temp_point, PCSENIOR8_STYLE).draw(disp)?;
64+
let next = Text::new("°", next + Point::new(0, 3), PROFONT12).draw(disp)?;
65+
Text::new("C", next - Point::new(0, 2), PCSENIOR8_STYLE).draw(disp)?;
8266

8367
// bottom right: disk usage
8468
let disk_width = disk_usage.len() as i32 * char_width;
8569
let disk_point = Point::new(99 - disk_width, 23 + y_offset);
86-
let next = Text::new(disk_usage, disk_point, PROFONT12).draw(disp)?;
87-
let next = Text::new("%", next, FONT_6X12).draw(disp)?;
70+
let next = Text::new(disk_usage, disk_point, PCSENIOR8_STYLE).draw(disp)?;
71+
let next = Text::new("%", next + y_margin, FONT_6X12).draw(disp)?;
8872
Text::new("DISK", next + x_margin, FONT_5X8).draw(disp)?;
8973

9074
disp.flush()?;

src/display_types.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use linux_embedded_hal::I2cdev;
2+
use ssd1306::{prelude::*, Ssd1306, mode::BufferedGraphicsMode};
3+
use embedded_graphics::{
4+
image::ImageRaw,
5+
mono_font::{ascii, MonoTextStyleBuilder, MonoFont, MonoTextStyle, DecorationDimensions, mapping::StrGlyphMapping},
6+
pixelcolor::BinaryColor,
7+
prelude::*
8+
};
9+
use profont::PROFONT_12_POINT;
10+
11+
12+
pub type Display = Ssd1306<I2CInterface<I2cdev>, DisplaySize128x32, BufferedGraphicsMode<DisplaySize128x32>>;
13+
14+
15+
pub const PROFONT12: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
16+
.font(&PROFONT_12_POINT)
17+
.text_color(BinaryColor::On)
18+
.build();
19+
20+
pub const FONT_6X12: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
21+
.font(&ascii::FONT_6X12)
22+
.text_color(BinaryColor::On)
23+
.build();
24+
25+
pub const FONT_5X8: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
26+
.font(&ascii::FONT_5X8)
27+
.text_color(BinaryColor::On)
28+
.build();
29+
30+
pub const GLYPH_MAPPING: StrGlyphMapping = StrGlyphMapping::new(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~°", '?' as usize - ' ' as usize);
31+
32+
pub const PCSENIOR8: MonoFont = MonoFont {
33+
image: ImageRaw::new(
34+
include_bytes!("../data/pcsenior.raw"),
35+
128,
36+
),
37+
character_size: Size::new(8, 10),
38+
character_spacing: 0,
39+
baseline: 7,
40+
underline: DecorationDimensions::new(9, 1),
41+
strikethrough: DecorationDimensions::new(10 / 2, 1),
42+
glyph_mapping: &GLYPH_MAPPING,
43+
};
44+
45+
pub const PCSENIOR8_STYLE: MonoTextStyle<'_, BinaryColor> = MonoTextStyleBuilder::new()
46+
.font(&PCSENIOR8)
47+
.text_color(BinaryColor::On)
48+
.build();

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use fan_controller::FanController;
1010
mod display;
1111
use display::PoeDisplay;
1212

13+
mod display_types;
1314

1415
fn main() -> Result<(), Box<dyn Error>> {
1516
let mut poe_disp = PoeDisplay::new()?;

0 commit comments

Comments
 (0)