dashboard/mode/
init_running.rs

1use embedded_graphics::prelude::WebColors;
2use embedded_graphics::primitives::PrimitiveStyle;
3use embedded_graphics::primitives::{
4    Circle, PrimitiveStyleBuilder, Rectangle, StrokeAlignment, StyledDrawable,
5};
6
7use embedded_graphics::mono_font::iso_8859_13::FONT_10X20;
8use embedded_graphics::{
9    Drawable,
10    pixelcolor::Rgb666,
11    prelude::{Point, RgbColor, Size},
12    text::{Alignment, Text},
13};
14
15use crate::display_mod::{CENTER_POINT, DISPLAY_HEIGHT, DISPLAY_WIDTH, DisplayDevice};
16use embedded_graphics::mono_font::MonoTextStyle;
17
18pub const SPEED_FONT_WIDTH: u32 = 27;
19pub const SPEED_FONT_HEIGHT: u32 = 63;
20
21pub const EFF_FONT_WIDTH: u32 = 15;
22pub const EFF_FONT_HEIGHT: u32 = 25;
23pub const EFF_POS: Point = Point::new(50, DISPLAY_HEIGHT as i32 - 50);
24
25pub const BATT_WIDTH: u32 = 16;
26pub const BATT_HEIGHT: u32 = 40;
27pub const BATT_POS: Point = Point::new(DISPLAY_WIDTH as i32 - 40, DISPLAY_HEIGHT as i32 - 60);
28
29fn init_render_speed_gui(display: &mut DisplayDevice) {
30    let speed_unit_style = MonoTextStyle::new(&FONT_10X20, Rgb666::RED);
31    let speed_circle_style = PrimitiveStyleBuilder::new()
32        .stroke_color(Rgb666::CSS_FIRE_BRICK)
33        .stroke_width(5)
34        .stroke_alignment(StrokeAlignment::Outside)
35        .build();
36
37    // Render Speed Circle
38    Circle::with_center(CENTER_POINT, 120)
39        .draw_styled(&speed_circle_style, display)
40        .unwrap();
41    // Render Speed Unit
42    Text::with_alignment(
43        "km/h",
44        CENTER_POINT + Point::new(0, SPEED_FONT_HEIGHT as i32 / 2 + 15),
45        speed_unit_style,
46        Alignment::Center,
47    )
48    .draw(display)
49    .unwrap();
50}
51
52fn init_render_efficiency_gui(display: &mut DisplayDevice) {
53    let eff_unit_style = MonoTextStyle::new(&FONT_10X20, Rgb666::GREEN);
54    let eff_circle_style = PrimitiveStyleBuilder::new()
55        .stroke_color(Rgb666::GREEN)
56        .stroke_width(4)
57        .stroke_alignment(StrokeAlignment::Outside)
58        .build();
59    // Render Efficiency Circle
60    Circle::with_center(EFF_POS, 70)
61        .draw_styled(&eff_circle_style, display)
62        .unwrap();
63    // Render Efficiency %
64    Text::with_alignment(
65        "%",
66        EFF_POS + Point::new(EFF_FONT_WIDTH as i32 + 2, EFF_FONT_HEIGHT as i32 / 2),
67        eff_unit_style,
68        Alignment::Left,
69    )
70    .draw(display)
71    .unwrap();
72}
73
74fn init_render_battery_gui(display: &mut DisplayDevice) {
75    let bat_tip_width = 12;
76    let bat_tip_height = 8;
77
78    let bat_tip = Rectangle::new(
79        BATT_POS + Point::new((BATT_WIDTH as i32 - bat_tip_width) / 2, -bat_tip_height),
80        Size::new(bat_tip_width as u32, bat_tip_height as u32),
81    );
82    let batt_outline = Rectangle::new(BATT_POS, Size::new(BATT_WIDTH, BATT_HEIGHT));
83
84    let outline_style = PrimitiveStyleBuilder::new()
85        .stroke_alignment(StrokeAlignment::Outside)
86        .stroke_color(Rgb666::WHITE)
87        .stroke_width(4)
88        .build();
89    let tip_style = PrimitiveStyle::with_fill(Rgb666::WHITE);
90    let batt_unit_style = MonoTextStyle::new(&FONT_10X20, Rgb666::WHITE);
91
92    // Render Battery Tip
93    bat_tip.draw_styled(&tip_style, display).unwrap();
94    // Render Battery Border
95    batt_outline.draw_styled(&outline_style, display).unwrap();
96    // Render Battey %
97    Text::with_alignment(
98        "%",
99        BATT_POS + Point::new(-8, 40),
100        batt_unit_style,
101        Alignment::Right,
102    )
103    .draw(display)
104    .unwrap();
105}
106pub fn init_render_running_gui(display: &mut DisplayDevice) {
107    init_render_speed_gui(display);
108    init_render_efficiency_gui(display);
109    init_render_battery_gui(display);
110}