mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-04 05:42:34 +00:00
fixup! feat(core/rust): cleaner backlight functions
This commit is contained in:
parent
c8871aac1a
commit
59197d364a
@ -35,30 +35,30 @@ pub use icon::{Icon, IconAndName};
|
|||||||
#[cfg(any(feature = "model_tt", feature = "model_tr"))]
|
#[cfg(any(feature = "model_tt", feature = "model_tr"))]
|
||||||
pub use loader::{loader, loader_indeterminate, LOADER_MAX, LOADER_MIN};
|
pub use loader::{loader, loader_indeterminate, LOADER_MAX, LOADER_MIN};
|
||||||
|
|
||||||
pub fn backlight() -> i32 {
|
pub fn backlight() -> u16 {
|
||||||
display::backlight(-1)
|
display::backlight(-1) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_backlight(val: i32) {
|
pub fn set_backlight(val: u16) {
|
||||||
display::backlight(val);
|
display::backlight(val as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fade_backlight(target: i32) {
|
pub fn fade_backlight(target: u16) {
|
||||||
const BACKLIGHT_DELAY: Duration = Duration::from_millis(14);
|
const FADE_DURATION_MS: u32 = 50;
|
||||||
const BACKLIGHT_STEP: usize = 15;
|
fade_backlight_duration(target, FADE_DURATION_MS);
|
||||||
|
}
|
||||||
|
|
||||||
let current = backlight();
|
pub fn fade_backlight_duration(target: u16, duration_ms: u32) {
|
||||||
if current < target {
|
let target = target as i32;
|
||||||
for val in (current..target).step_by(BACKLIGHT_STEP) {
|
let duration_ms = duration_ms as i32;
|
||||||
set_backlight(val);
|
let current = backlight() as i32;
|
||||||
time::sleep(BACKLIGHT_DELAY);
|
|
||||||
}
|
for i in 0..duration_ms {
|
||||||
} else {
|
set_backlight((current + (i * (target - current)) / duration_ms) as u16);
|
||||||
for val in (target..current).rev().step_by(BACKLIGHT_STEP) {
|
time::sleep(Duration::from_millis(1));
|
||||||
set_backlight(val);
|
|
||||||
time::sleep(BACKLIGHT_DELAY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// account for imprecise rounding
|
||||||
|
set_backlight(target as u16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fill a whole rectangle with a specific color.
|
/// Fill a whole rectangle with a specific color.
|
||||||
|
Loading…
Reference in New Issue
Block a user