chore(core/rust): Add backlight fading fn

pull/1961/head
Jan Pochyla 3 years ago committed by matejcik
parent a54ca9cb05
commit 12deedf3f6

@ -1,4 +1,4 @@
use crate::trezorhal::display; use crate::{micropython::time, time::Duration, trezorhal::display};
#[cfg(not(feature = "model_tt"))] #[cfg(not(feature = "model_tt"))]
use crate::ui::model_t1::constant; use crate::ui::model_t1::constant;
@ -23,8 +23,30 @@ pub fn screen() -> Rect {
Rect::from_top_left_and_size(Point::zero(), size()) Rect::from_top_left_and_size(Point::zero(), size())
} }
pub fn backlight(val: i32) -> i32 { pub fn backlight() -> i32 {
display::backlight(val) display::backlight(-1)
}
pub fn set_backlight(val: i32) {
display::backlight(val);
}
pub fn fade_backlight(target: i32) {
const BACKLIGHT_DELAY: Duration = Duration::from_millis(14);
const BACKLIGHT_STEP: usize = 15;
let current = backlight();
if current < target {
for val in (current..target).step_by(BACKLIGHT_STEP) {
set_backlight(val);
time::sleep(BACKLIGHT_DELAY);
}
} else {
for val in (target..current).rev().step_by(BACKLIGHT_STEP) {
set_backlight(val);
time::sleep(BACKLIGHT_DELAY);
}
}
} }
pub fn rect(r: Rect, fg_color: Color) { pub fn rect(r: Rect, fg_color: Color) {

@ -77,7 +77,7 @@ impl Swipe {
let start = self.backlight_start as f32; let start = self.backlight_start as f32;
let end = self.backlight_end as f32; let end = self.backlight_end as f32;
let value = start + ratio * (end - start); let value = start + ratio * (end - start);
display::backlight(value as i32); display::set_backlight(value as i32);
} }
} }

Loading…
Cancel
Save