diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/fuel_gauge.rs b/core/embed/rust/src/ui/layout_eckhart/component/fuel_gauge.rs similarity index 72% rename from core/embed/rust/src/ui/layout_eckhart/firmware/fuel_gauge.rs rename to core/embed/rust/src/ui/layout_eckhart/component/fuel_gauge.rs index 1309c36342..0895dad381 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/fuel_gauge.rs +++ b/core/embed/rust/src/ui/layout_eckhart/component/fuel_gauge.rs @@ -1,22 +1,27 @@ use crate::{ trezorhal::power_manager::{self, ChargingState}, ui::{ - component::{Component, Event, EventCtx, Never, Timer}, + component::{Component, Event, EventCtx, Never}, display::{Color, Font, Icon}, geometry::{Alignment, Alignment2D, Offset, Point, Rect}, shape::{self, Renderer}, - util::animation_disabled, }, }; +#[cfg(feature = "micropython")] +use crate::ui::{component::Timer, util::animation_disabled}; + use super::super::{ fonts, theme::{ - firmware::FUEL_GAUGE_DURATION, GREY_LIGHT, ICON_BATTERY_EMPTY, ICON_BATTERY_FULL, - ICON_BATTERY_LOW, ICON_BATTERY_MID, ICON_BATTERY_ZAP, RED, YELLOW, + GREY_LIGHT, ICON_BATTERY_EMPTY, ICON_BATTERY_FULL, ICON_BATTERY_LOW, ICON_BATTERY_MID, + ICON_BATTERY_ZAP, RED, YELLOW, }, }; +#[cfg(feature = "micropython")] +use super::super::theme::firmware::FUEL_GAUGE_DURATION; + /// Component for showing a small fuel gauge (battery status) consisting of: /// - icon indicating charging or discharging state /// - percentage @@ -32,20 +37,20 @@ pub struct FuelGauge { charging_state: ChargingState, /// State of charge (0-100) [%] soc: Option, - /// Timer to track temporary battery status showcase - timer: Timer, /// Font used for the soc percentage font: Font, } -#[derive(Clone, PartialEq)] +#[derive(Clone)] pub enum FuelGaugeMode { /// Always show the fuel gauge Always, /// Show the fuel gauge only when charging state changes - OnChargingChange, + #[cfg(feature = "micropython")] + OnChargingChange(Timer), /// Show the fuel gauge when charging state changes or when attached - OnChargingChangeOrAttach, + #[cfg(feature = "micropython")] + OnChargingChangeOrAttach(Timer), } impl FuelGauge { @@ -53,12 +58,14 @@ impl FuelGauge { Self::new(FuelGaugeMode::Always) } + #[cfg(feature = "micropython")] pub const fn on_charging_change() -> Self { - Self::new(FuelGaugeMode::OnChargingChange) + Self::new(FuelGaugeMode::OnChargingChange(Timer::new())) } + #[cfg(feature = "micropython")] pub const fn on_charging_change_or_attach() -> Self { - Self::new(FuelGaugeMode::OnChargingChangeOrAttach) + Self::new(FuelGaugeMode::OnChargingChangeOrAttach(Timer::new())) } pub const fn with_alignment(mut self, alignment: Alignment) -> Self { @@ -77,23 +84,26 @@ impl FuelGauge { } pub fn should_be_shown(&self) -> bool { - match self.mode { + match &self.mode { FuelGaugeMode::Always => true, - FuelGaugeMode::OnChargingChange | FuelGaugeMode::OnChargingChangeOrAttach => { - self.timer.is_running() - } + #[cfg(feature = "micropython")] + FuelGaugeMode::OnChargingChange(timer) + | FuelGaugeMode::OnChargingChangeOrAttach(timer) => timer.is_running(), } } const fn new(mode: FuelGaugeMode) -> Self { + #[cfg(feature = "micropython")] + let font = fonts::FONT_SATOSHI_REGULAR_22; + #[cfg(not(feature = "micropython"))] + let font = fonts::FONT_SATOSHI_MEDIUM_26; Self { area: Rect::zero(), alignment: Alignment::Start, mode, charging_state: ChargingState::Idle, soc: None, - timer: Timer::new(), - font: fonts::FONT_SATOSHI_REGULAR_22, + font, } } @@ -134,30 +144,40 @@ impl Component for FuelGauge { if self.soc.is_none() { self.update_pm_state(); } - if !animation_disabled() && self.mode == FuelGaugeMode::OnChargingChangeOrAttach { - self.timer.start(ctx, FUEL_GAUGE_DURATION.into()); + #[cfg(feature = "micropython")] + if let FuelGaugeMode::OnChargingChangeOrAttach(timer) = &mut self.mode { + if !animation_disabled() { + timer.start(ctx, FUEL_GAUGE_DURATION.into()); + } } ctx.request_paint(); } - Event::PM(e) => { + Event::PM(_e) => { self.update_pm_state(); - match self.mode { + match &mut self.mode { FuelGaugeMode::Always => { ctx.request_paint(); } - FuelGaugeMode::OnChargingChange | FuelGaugeMode::OnChargingChangeOrAttach => { - if e.charging_status_changed { - self.timer.start(ctx, FUEL_GAUGE_DURATION.into()); + #[cfg(feature = "micropython")] + FuelGaugeMode::OnChargingChange(timer) + | FuelGaugeMode::OnChargingChangeOrAttach(timer) => { + if _e.charging_status_changed { + timer.start(ctx, FUEL_GAUGE_DURATION.into()); ctx.request_paint(); } } } } - Event::Timer(_) => { - if self.timer.expire(event) { - ctx.request_paint(); + #[cfg(feature = "micropython")] + Event::Timer(_) => match &mut self.mode { + FuelGaugeMode::OnChargingChange(timer) + | FuelGaugeMode::OnChargingChangeOrAttach(timer) => { + if timer.expire(event) { + ctx.request_paint(); + } } - } + _ => {} + }, _ => {} } @@ -170,7 +190,7 @@ impl Component for FuelGauge { let soc = self.soc.unwrap_or(0); let (icon, color_icon, color_text) = self.battery_indication(self.charging_state, soc); let soc_percent_fmt = if self.soc.is_none() { - uformat!("--") + uformat!("?") } else { uformat!("{} %", soc) }; diff --git a/core/embed/rust/src/ui/layout_eckhart/component/mod.rs b/core/embed/rust/src/ui/layout_eckhart/component/mod.rs index 4b6376e320..d5cda4b98d 100644 --- a/core/embed/rust/src/ui/layout_eckhart/component/mod.rs +++ b/core/embed/rust/src/ui/layout_eckhart/component/mod.rs @@ -1,9 +1,11 @@ mod button; mod error; +mod fuel_gauge; mod update_screen; mod welcome_screen; pub use button::{Button, ButtonContent, ButtonMsg, ButtonStyle, ButtonStyleSheet, IconText}; pub use error::ErrorScreen; +pub use fuel_gauge::FuelGauge; pub use update_screen::UpdateScreen; pub use welcome_screen::WelcomeScreen; diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/device_menu_screen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/device_menu_screen.rs index 714b44f9ab..7aac8aa5ac 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/device_menu_screen.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/device_menu_screen.rs @@ -20,11 +20,11 @@ use crate::{ use super::{ super::{ - component::{Button, ButtonStyleSheet}, + component::{Button, ButtonStyleSheet, FuelGauge}, constant::SCREEN, firmware::{ - FuelGauge, Header, HeaderMsg, TextScreen, TextScreenMsg, VerticalMenu, - VerticalMenuScreen, VerticalMenuScreenMsg, SHORT_MENU_ITEMS, + Header, HeaderMsg, TextScreen, TextScreenMsg, VerticalMenu, VerticalMenuScreen, + VerticalMenuScreenMsg, SHORT_MENU_ITEMS, }, }, theme, ShortMenuVec, diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs index 7f7ac1c37e..3fdba00ca0 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/header.rs @@ -9,10 +9,7 @@ use crate::{ }; use super::{ - super::{ - component::{Button, ButtonContent, ButtonMsg}, - firmware::FuelGauge, - }, + super::component::{Button, ButtonContent, ButtonMsg, FuelGauge}, constant, theme, }; diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs index 4ea3ef4e6f..2c70b9f1df 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/homescreen.rs @@ -20,12 +20,12 @@ use crate::{ use super::{ super::{ - component::{Button, ButtonContent, ButtonMsg}, + component::{Button, ButtonContent, ButtonMsg, FuelGauge}, fonts, }, constant::{HEIGHT, SCREEN, WIDTH}, theme::{self, firmware::button_homebar_style, TILES_GRID}, - ActionBar, ActionBarMsg, FuelGauge, Hint, + ActionBar, ActionBarMsg, Hint, }; const LOCK_HOLD_DURATION: ShortDuration = ShortDuration::from_millis(3000); diff --git a/core/embed/rust/src/ui/layout_eckhart/firmware/mod.rs b/core/embed/rust/src/ui/layout_eckhart/firmware/mod.rs index 31db4a57a8..ccb5825230 100644 --- a/core/embed/rust/src/ui/layout_eckhart/firmware/mod.rs +++ b/core/embed/rust/src/ui/layout_eckhart/firmware/mod.rs @@ -5,7 +5,6 @@ mod device_menu_screen; mod fido; #[rustfmt::skip] mod fido_icons; -mod fuel_gauge; mod header; mod hint; mod hold_to_confirm; @@ -26,7 +25,6 @@ pub use brightness_screen::SetBrightnessScreen; pub use confirm_homescreen::{ConfirmHomescreen, ConfirmHomescreenMsg}; pub use device_menu_screen::{DeviceMenuMsg, DeviceMenuScreen}; pub use fido::{FidoAccountName, FidoCredential}; -pub use fuel_gauge::FuelGauge; pub use header::{Header, HeaderMsg}; pub use hint::Hint; pub use hold_to_confirm::HoldToConfirmAnim;