1
+ use crate :: display_types:: { Display , PCSENIOR8_STYLE , FONT_6X12 , FONT_5X8 , PROFONT12 } ;
1
2
use linux_embedded_hal:: I2cdev ;
2
- use ssd1306:: { prelude:: * , I2CDisplayInterface , Ssd1306 , mode :: BufferedGraphicsMode } ;
3
+ use ssd1306:: { prelude:: * , I2CDisplayInterface , Ssd1306 } ;
3
4
use display_interface:: DisplayError ;
4
5
use embedded_graphics:: {
5
- mono_font:: { ascii, MonoTextStyleBuilder , MonoTextStyle } ,
6
6
pixelcolor:: BinaryColor ,
7
7
prelude:: * ,
8
8
text:: Text
9
9
} ;
10
- use profont:: PROFONT_12_POINT ;
11
10
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 > > ;
28
11
29
12
pub struct PoeDisplay {
30
13
display : Display
@@ -47,44 +30,45 @@ impl PoeDisplay {
47
30
) -> Result < ( ) , DisplayError > {
48
31
let disp = & mut self . display ;
49
32
50
- let y_offset = 8 ;
33
+ let y_offset = 7 ;
51
34
let display_width = 128 ;
52
35
let char_width: i32 = 8 ;
53
36
let x_margin = Point :: new ( 2 , 0 ) . x_axis ( ) ;
37
+ let y_margin = Point :: new ( 0 , 1 ) . y_axis ( ) ;
54
38
55
39
disp. clear ( BinaryColor :: Off ) ?;
56
40
57
41
// top center: ip address
58
42
let ip_width = ip_address. len ( ) as i32 * char_width;
59
43
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) ?;
61
45
62
46
// middle left: cpu usage
63
47
let cpu_width = cpu_usage. len ( ) as i32 * char_width;
64
48
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) ?;
67
51
Text :: new ( "CPU" , next + x_margin, FONT_5X8 ) . draw ( disp) ?;
68
52
69
53
// bottom left: ram usage
70
54
let ram_width = ram_usage. len ( ) as i32 * char_width;
71
55
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) ?;
74
58
Text :: new ( "RAM" , next + x_margin, FONT_5X8 ) . draw ( disp) ?;
75
59
76
60
// middle right: temp
77
61
let temp_width = temp. len ( ) as i32 * char_width;
78
62
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) ?;
82
66
83
67
// bottom right: disk usage
84
68
let disk_width = disk_usage. len ( ) as i32 * char_width;
85
69
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) ?;
88
72
Text :: new ( "DISK" , next + x_margin, FONT_5X8 ) . draw ( disp) ?;
89
73
90
74
disp. flush ( ) ?;
0 commit comments