1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

chore(core/rust): Add backlight fading fn

This commit is contained in:
Jan Pochyla 2021-11-26 19:41:59 +01:00 committed by matejcik
parent a54ca9cb05
commit 12deedf3f6
2 changed files with 26 additions and 4 deletions

View File

@ -1,4 +1,4 @@
use crate::trezorhal::display;
use crate::{micropython::time, time::Duration, trezorhal::display};
#[cfg(not(feature = "model_tt"))]
use crate::ui::model_t1::constant;
@ -23,8 +23,30 @@ pub fn screen() -> Rect {
Rect::from_top_left_and_size(Point::zero(), size())
}
pub fn backlight(val: i32) -> i32 {
display::backlight(val)
pub fn backlight() -> i32 {
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) {

View File

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