-
-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix fading issues #4492
base: main
Are you sure you want to change the base?
fix fading issues #4492
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[T3T1] Fixed flashing old content when fading |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[T3T1] Fix slow fade in/non responsiveness in bootloader UI |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ use crate::{strutil::TString, trezorhal::display}; | |
#[cfg(feature = "backlight")] | ||
use crate::ui::lerp::Lerp; | ||
|
||
#[cfg(feature = "backlight")] | ||
use crate::{time::Instant, ui::util::animation_disabled}; | ||
|
||
// Reexports | ||
pub use crate::ui::display::toif::Icon; | ||
pub use color::Color; | ||
|
@@ -42,7 +45,19 @@ pub fn fade_backlight_duration(target: u8, duration_ms: u32) { | |
let duration_ms = duration_ms as i32; | ||
let current = backlight() as i32; | ||
|
||
for i in 0..duration_ms { | ||
if animation_disabled() { | ||
set_backlight(target as u8); | ||
return; | ||
} | ||
|
||
let start = Instant::now(); | ||
let end = unwrap!(start.checked_add(Duration::from_millis(duration_ms as _))); | ||
|
||
while Instant::now() < end { | ||
let i = Instant::now() | ||
.checked_duration_since(start) | ||
.unwrap() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
here's a slightly tidier version of this function though: #[cfg(feature = "backlight")]
pub fn fade_backlight_duration(target: u8, duration_ms: u32) {
let target = target as i32;
let current = backlight() as i32;
let duration = Duration::from_millis(duration_ms);
if animation_disabled() {
set_backlight(target as u8);
return;
}
let mut now = Instant::now();
let start = now;
let end = unwrap!(start.checked_add(duration));
while now < end {
let elapsed = unwrap!(now.checked_duration_since(start));
let val = i32::lerp(current, target, elapsed / duration);
set_backlight(val as u8);
time::sleep(Duration::from_millis(1));
now = Instant::now();
}
//account for imprecise rounding
set_backlight(target as u8);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see below |
||
.to_millis(); | ||
let val = i32::lerp(current, target, i as f32 / duration_ms as f32); | ||
set_backlight(val as u8); | ||
time::sleep(Duration::from_millis(1)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from trezor.ui.layouts import confirm_action | ||
from trezor.wire import context | ||
from trezor.wire.message_handler import filters, remove_filter | ||
from trezorui_api import backlight_fade | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(also we generally don't import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed 1c7bde1 |
||
|
||
from . import workflow_handlers | ||
|
||
|
@@ -454,7 +455,7 @@ def reload_settings_from_storage() -> None: | |
storage_device.get_experimental_features() | ||
) | ||
if ui.display.orientation() != storage_device.get_rotation(): | ||
ui.backlight_fade(ui.BacklightLevels.DIM) | ||
backlight_fade(ui.BacklightLevels.DIM) | ||
ui.display.orientation(storage_device.get_rotation()) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
show_pin_timeout, | ||
) | ||
from trezor.ui.layouts.homescreen import Lockscreen | ||
from trezorui_api import backlight_fade | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed 1c7bde1 |
||
|
||
from apps.common.request_pin import can_lock_device, verify_user_pin | ||
|
||
|
@@ -61,7 +62,7 @@ async def bootscreen() -> None: | |
if can_lock_device(): | ||
enforce_welcome_screen_duration() | ||
if utils.INTERNAL_MODEL == "T2T1": | ||
ui.backlight_fade(ui.BacklightLevels.NONE) | ||
backlight_fade(ui.BacklightLevels.NONE) | ||
ui.display.orientation(storage.device.get_rotation()) | ||
if utils.USE_HAPTIC: | ||
io.haptic.haptic_set_enabled(storage.device.get_haptic_feedback()) | ||
|
@@ -88,7 +89,7 @@ async def bootscreen() -> None: | |
# there is a slight delay before next screen is shown, | ||
# so we don't fade unless there is a change of orientation | ||
if utils.INTERNAL_MODEL == "T2T1": | ||
ui.backlight_fade(ui.BacklightLevels.NONE) | ||
backlight_fade(ui.BacklightLevels.NONE) | ||
ui.display.orientation(rotation) | ||
allow_all_loader_messages() | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from common import * # isort:skip | ||
|
||
from trezor.ui import display | ||
from trezorui_api import backlight_set | ||
|
||
|
||
class TestDisplay(unittest.TestCase): | ||
|
@@ -17,7 +18,7 @@ def test_orientation(self): | |
|
||
def test_backlight(self): | ||
for b in range(256): | ||
display.backlight(b) | ||
backlight_set(b) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wondering if there's any point in keeping this testcase around? it's just a smoke test for existence of the function, we're not verifying any result here 🤷♀️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not, we should either make something useful of it or remove it. I'd say its out of scope here though |
||
|
||
def test_raw(self): | ||
pass | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s a small chance that the app might crash when the timer wraps from its maximum value to 0. How about using StopWatch instead of the timer here? It could slightly simplify the code and resolve this minor issue:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I suspected there's an existing code that could help here.
(also note that
Duration
s support division and the result is a f32, see my suggested version of this function)while you're touching this, please also convert this
unwrap()
tounwrap!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to the combo of your suggestions: 1c7bde1
i replaced that unwrap(), but note that there are unwrap()s in bunch of other places in our rust codebase, so probably some larger cleanup should take place. (would there be a way to automatically check for this?)