|
|
|
@ -31,30 +31,31 @@ pub use crate::ui::display::toif::Icon;
|
|
|
|
|
#[cfg(any(feature = "model_tt", feature = "model_tr"))]
|
|
|
|
|
pub use loader::{loader, loader_indeterminate, LOADER_MAX, LOADER_MIN};
|
|
|
|
|
|
|
|
|
|
pub fn backlight() -> i32 {
|
|
|
|
|
display::backlight(-1)
|
|
|
|
|
pub fn backlight() -> u16 {
|
|
|
|
|
display::backlight(-1) as u16
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_backlight(val: i32) {
|
|
|
|
|
display::backlight(val);
|
|
|
|
|
pub fn set_backlight(val: u16) {
|
|
|
|
|
display::backlight(val as i32);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn fade_backlight(target: i32) {
|
|
|
|
|
const BACKLIGHT_DELAY: Duration = Duration::from_millis(14);
|
|
|
|
|
const BACKLIGHT_STEP: usize = 15;
|
|
|
|
|
pub fn fade_backlight(target: u16) {
|
|
|
|
|
const FADE_DURATION_MS: u32 = 50;
|
|
|
|
|
fade_backlight_duration(target, FADE_DURATION_MS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 fade_backlight_duration(target: u16, duration_ms: u32) {
|
|
|
|
|
let target = target as i32;
|
|
|
|
|
let duration_ms = duration_ms as i32;
|
|
|
|
|
let current = backlight() as i32;
|
|
|
|
|
|
|
|
|
|
for i in 0..duration_ms {
|
|
|
|
|
let val = i32::lerp(current, target, i as f32 / duration_ms as f32);
|
|
|
|
|
set_backlight(val as u16);
|
|
|
|
|
time::sleep(Duration::from_millis(1));
|
|
|
|
|
}
|
|
|
|
|
//account for imprecise rounding
|
|
|
|
|
set_backlight(target as u16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn rect_fill(r: Rect, fg_color: Color) {
|
|
|
|
@ -1094,6 +1095,10 @@ impl Color {
|
|
|
|
|
Self(r | g | b)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn alpha(bg: Color, alpha: u16) -> Self {
|
|
|
|
|
Self::rgba(bg, 0xFF, 0xFF, 0xFF, alpha)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn r(self) -> u8 {
|
|
|
|
|
(self.0 >> 8) as u8 & 0xF8
|
|
|
|
|
}
|
|
|
|
|