diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index a4e9b63fb0..427d6ad647 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -6,14 +6,20 @@ static void _librust_qstrs(void) { MP_QSTR_; + MP_QSTR_BacklightLevels; MP_QSTR_CANCELLED; MP_QSTR_CONFIRMED; + MP_QSTR_DIM; MP_QSTR_INFO; + MP_QSTR_LOW; MP_QSTR_LayoutObj; + MP_QSTR_MAX; MP_QSTR_MESSAGE_NAME; MP_QSTR_MESSAGE_WIRE_TYPE; MP_QSTR_Msg; MP_QSTR_MsgDef; + MP_QSTR_NONE; + MP_QSTR_NORMAL; MP_QSTR_TR; MP_QSTR_TranslationsHeader; MP_QSTR___dict__; diff --git a/core/embed/rust/src/ui/backlight.rs b/core/embed/rust/src/ui/backlight.rs new file mode 100644 index 0000000000..ca2ce55ff6 --- /dev/null +++ b/core/embed/rust/src/ui/backlight.rs @@ -0,0 +1,43 @@ +use crate::{ + error::Error, + micropython::{ffi, obj::Obj, qstr::Qstr, simple_type::SimpleTypeObj, typ::Type, util}, + ui::{ui_features::ModelUI, UIFeaturesCommon}, +}; + +/* + * This whole module should be removed, in favor of fully + * moving backlight control into Rust. Relatively easy to do, but not + * necessary right now. Filed as https://github.com/trezor/trezor-firmware/issues/3849 + * + * Consider this module temporary. (yeah yeah everyone knows "temporary" + * things stay forever. Written in May 2024.) + */ + +static BACKLIGHT_LEVELS_TYPE: Type = obj_type! { + name: Qstr::MP_QSTR_BacklightLevels, + attr_fn: backlight_levels_attr, +}; + +unsafe extern "C" fn backlight_levels_attr(_self_in: Obj, attr: ffi::qstr, dest: *mut Obj) { + let block = || { + let arg = unsafe { dest.read() }; + if !arg.is_null() { + // Null destination would mean a `setattr`. + return Err(Error::TypeError); + } + let attr = Qstr::from_u16(attr as _); + let value = match attr { + Qstr::MP_QSTR_NONE => ModelUI::get_backlight_none(), + Qstr::MP_QSTR_NORMAL => ModelUI::get_backlight_normal(), + Qstr::MP_QSTR_LOW => ModelUI::get_backlight_low(), + Qstr::MP_QSTR_DIM => ModelUI::get_backlight_dim(), + Qstr::MP_QSTR_MAX => ModelUI::get_backlight_max(), + _ => return Err(Error::AttributeError(attr)), + }; + unsafe { dest.write(value.into()) }; + Ok(()) + }; + unsafe { util::try_or_raise(block) } +} + +pub static BACKLIGHT_LEVELS_OBJ: SimpleTypeObj = SimpleTypeObj::new(&BACKLIGHT_LEVELS_TYPE); diff --git a/core/embed/rust/src/ui/mod.rs b/core/embed/rust/src/ui/mod.rs index f68d521fc2..f1fed31e8f 100644 --- a/core/embed/rust/src/ui/mod.rs +++ b/core/embed/rust/src/ui/mod.rs @@ -2,6 +2,8 @@ pub mod macros; pub mod animation; +#[cfg(feature = "micropython")] +pub mod backlight; pub mod button_request; pub mod component; pub mod constant; diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index 9c459351bb..f51e4d7268 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -44,8 +44,8 @@ use super::{ FidoMsg, Frame, FrameMsg, Homescreen, HomescreenMsg, IconDialog, Lockscreen, MnemonicInput, MnemonicKeyboard, MnemonicKeyboardMsg, PassphraseKeyboard, PassphraseKeyboardMsg, PinKeyboard, PinKeyboardMsg, Progress, PromptScreen, SelectWordCount, SelectWordCountMsg, - SetBrightnessDialog, SimplePage, Slip39Input, StatusScreen, SwipeUpScreen, SwipeUpScreenMsg, - VerticalMenu, VerticalMenuChoiceMsg, + SetBrightnessDialog, SimplePage, Slip39Input, StatusScreen, SwipeUpScreen, + SwipeUpScreenMsg, VerticalMenu, VerticalMenuChoiceMsg, }, flow, theme, }; @@ -2033,6 +2033,17 @@ pub static mp_module_trezorui2: Module = obj_module! { /// ) -> LayoutObj[UiResult]: /// """Total summary and hold to confirm.""" Qstr::MP_QSTR_flow_confirm_summary => obj_fn_kw!(0, flow::new_confirm_summary).as_obj(), + + /// class BacklightLevels: + /// """Backlight levels. Values dynamically update based on user settings.""" + /// MAX: ClassVar[int] + /// NORMAL: ClassVar[int] + /// LOW: ClassVar[int] + /// DIM: ClassVar[int] + /// NONE: ClassVar[int] + /// + /// mock:global + Qstr::MP_QSTR_BacklightLevels => BACKLIGHT_LEVELS_OBJ.as_obj(), }; #[cfg(test)] diff --git a/core/embed/rust/src/ui/model_mercury/mod.rs b/core/embed/rust/src/ui/model_mercury/mod.rs index abcf538772..c73ee96a77 100644 --- a/core/embed/rust/src/ui/model_mercury/mod.rs +++ b/core/embed/rust/src/ui/model_mercury/mod.rs @@ -1,4 +1,5 @@ use super::{geometry::Rect, UIFeaturesCommon}; +use crate::ui::model_mercury::theme::backlight; #[cfg(feature = "bootloader")] pub mod bootloader; @@ -16,19 +17,44 @@ pub mod shapes; pub struct ModelMercuryFeatures; impl UIFeaturesCommon for ModelMercuryFeatures { + #[cfg(feature = "backlight")] fn fadein() { - #[cfg(feature = "backlight")] - crate::ui::display::fade_backlight_duration(theme::backlight::get_backlight_normal(), 150); + crate::ui::display::fade_backlight_duration(backlight::get_backlight_normal(), 150); } + #[cfg(feature = "backlight")] fn fadeout() { - #[cfg(feature = "backlight")] - crate::ui::display::fade_backlight_duration(theme::backlight::get_backlight_dim(), 150); + crate::ui::display::fade_backlight_duration(backlight::get_backlight_dim(), 150); } + #[cfg(feature = "backlight")] fn backlight_on() { - #[cfg(feature = "backlight")] - crate::ui::display::set_backlight(theme::backlight::get_backlight_normal()); + crate::ui::display::set_backlight(backlight::get_backlight_normal()); + } + + #[cfg(feature = "backlight")] + fn get_backlight_none() -> u16 { + backlight::get_backlight_none() + } + + #[cfg(feature = "backlight")] + fn get_backlight_normal() -> u16 { + backlight::get_backlight_normal() + } + + #[cfg(feature = "backlight")] + fn get_backlight_low() -> u16 { + backlight::get_backlight_low() + } + + #[cfg(feature = "backlight")] + fn get_backlight_dim() -> u16 { + backlight::get_backlight_dim() + } + + #[cfg(feature = "backlight")] + fn get_backlight_max() -> u16 { + backlight::get_backlight_max() } const SCREEN: Rect = constant::SCREEN; diff --git a/core/embed/rust/src/ui/model_mercury/theme/backlight.rs b/core/embed/rust/src/ui/model_mercury/theme/backlight.rs index 37a788c1d9..7dca47cc39 100644 --- a/core/embed/rust/src/ui/model_mercury/theme/backlight.rs +++ b/core/embed/rust/src/ui/model_mercury/theme/backlight.rs @@ -5,7 +5,7 @@ use crate::storage; const BACKLIGHT_NORMAL: u8 = 150; const BACKLIGHT_LOW: u8 = 45; const BACKLIGHT_DIM: u8 = 5; -const BACKLIGHT_NONE: u8 = 2; +const BACKLIGHT_NONE: u8 = 0; const BACKLIGHT_MIN: u8 = 10; const BACKLIGHT_MAX: u8 = 255; diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index bc56bd6570..55ee4ab8fd 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -13,6 +13,7 @@ use crate::{ translations::TR, trezorhal::model, ui::{ + backlight::BACKLIGHT_LEVELS_OBJ, component::{ base::Component, connect::Connect, @@ -2037,4 +2038,15 @@ pub static mp_module_trezorui2: Module = obj_module! { /// def show_wait_text(message: str, /) -> None: /// """Show single-line text in the middle of the screen.""" Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(), + + /// class BacklightLevels: + /// """Backlight levels. Values dynamically update based on user settings.""" + /// MAX: ClassVar[int] + /// NORMAL: ClassVar[int] + /// LOW: ClassVar[int] + /// DIM: ClassVar[int] + /// NONE: ClassVar[int] + /// + /// mock:global + Qstr::MP_QSTR_BacklightLevels => BACKLIGHT_LEVELS_OBJ.as_obj(), }; diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index f6bdb79884..b0bcb05157 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -10,6 +10,7 @@ use crate::{ translations::TR, trezorhal::model, ui::{ + backlight::BACKLIGHT_LEVELS_OBJ, component::{ base::ComponentExt, connect::Connect, @@ -2117,6 +2118,17 @@ pub static mp_module_trezorui2: Module = obj_module! { /// def show_wait_text(message: str, /) -> LayoutObj[None]: /// """Show single-line text in the middle of the screen.""" Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(), + + /// class BacklightLevels: + /// """Backlight levels. Values dynamically update based on user settings.""" + /// MAX: ClassVar[int] + /// NORMAL: ClassVar[int] + /// LOW: ClassVar[int] + /// DIM: ClassVar[int] + /// NONE: ClassVar[int] + /// + /// mock:global + Qstr::MP_QSTR_BacklightLevels => BACKLIGHT_LEVELS_OBJ.as_obj(), }; #[cfg(test)] diff --git a/core/embed/rust/src/ui/model_tt/mod.rs b/core/embed/rust/src/ui/model_tt/mod.rs index 1789dd188a..4754ee74ec 100644 --- a/core/embed/rust/src/ui/model_tt/mod.rs +++ b/core/embed/rust/src/ui/model_tt/mod.rs @@ -20,21 +20,44 @@ use crate::ui::{ pub struct ModelTTFeatures; impl UIFeaturesCommon for ModelTTFeatures { + #[cfg(feature = "backlight")] fn fadein() { - #[cfg(feature = "backlight")] crate::ui::display::fade_backlight_duration(backlight::get_backlight_normal(), 150); } - + #[cfg(feature = "backlight")] fn fadeout() { - #[cfg(feature = "backlight")] crate::ui::display::fade_backlight_duration(backlight::get_backlight_normal(), 150); } - + #[cfg(feature = "backlight")] fn backlight_on() { - #[cfg(feature = "backlight")] crate::ui::display::set_backlight(backlight::get_backlight_normal()); } + #[cfg(feature = "backlight")] + fn get_backlight_none() -> u16 { + backlight::get_backlight_none() + } + + #[cfg(feature = "backlight")] + fn get_backlight_normal() -> u16 { + backlight::get_backlight_normal() + } + + #[cfg(feature = "backlight")] + fn get_backlight_low() -> u16 { + backlight::get_backlight_low() + } + + #[cfg(feature = "backlight")] + fn get_backlight_dim() -> u16 { + backlight::get_backlight_dim() + } + + #[cfg(feature = "backlight")] + fn get_backlight_max() -> u16 { + backlight::get_backlight_max() + } + const SCREEN: Rect = constant::SCREEN; fn screen_fatal_error(title: &str, msg: &str, footer: &str) { diff --git a/core/embed/rust/src/ui/model_tt/theme/backlight.rs b/core/embed/rust/src/ui/model_tt/theme/backlight.rs index 37a788c1d9..7dca47cc39 100644 --- a/core/embed/rust/src/ui/model_tt/theme/backlight.rs +++ b/core/embed/rust/src/ui/model_tt/theme/backlight.rs @@ -5,7 +5,7 @@ use crate::storage; const BACKLIGHT_NORMAL: u8 = 150; const BACKLIGHT_LOW: u8 = 45; const BACKLIGHT_DIM: u8 = 5; -const BACKLIGHT_NONE: u8 = 2; +const BACKLIGHT_NONE: u8 = 0; const BACKLIGHT_MIN: u8 = 10; const BACKLIGHT_MAX: u8 = 255; diff --git a/core/embed/rust/src/ui/ui_features.rs b/core/embed/rust/src/ui/ui_features.rs index 528981faab..d45e48cae6 100644 --- a/core/embed/rust/src/ui/ui_features.rs +++ b/core/embed/rust/src/ui/ui_features.rs @@ -11,6 +11,22 @@ pub trait UIFeaturesCommon { fn fadeout() {} fn backlight_on() {} + fn get_backlight_none() -> u16 { + 0 + } + fn get_backlight_normal() -> u16 { + 0 + } + fn get_backlight_low() -> u16 { + 0 + } + fn get_backlight_dim() -> u16 { + 0 + } + fn get_backlight_max() -> u16 { + 0 + } + const SCREEN: Rect; fn screen_fatal_error(title: &str, msg: &str, footer: &str); diff --git a/core/mocks/generated/trezorui2.pyi b/core/mocks/generated/trezorui2.pyi index ed25b725b2..52e099bd63 100644 --- a/core/mocks/generated/trezorui2.pyi +++ b/core/mocks/generated/trezorui2.pyi @@ -592,6 +592,16 @@ def flow_confirm_summary( br_type: str, ) -> LayoutObj[UiResult]: """Total summary and hold to confirm.""" + + +# rust/src/ui/model_mercury/layout.rs +class BacklightLevels: + """Backlight levels. Values dynamically update based on user settings.""" + MAX: ClassVar[int] + NORMAL: ClassVar[int] + LOW: ClassVar[int] + DIM: ClassVar[int] + NONE: ClassVar[int] CONFIRMED: UiResult CANCELLED: UiResult INFO: UiResult @@ -1586,3 +1596,13 @@ def confirm_firmware_update( # rust/src/ui/model_tt/layout.rs def show_wait_text(message: str, /) -> LayoutObj[None]: """Show single-line text in the middle of the screen.""" + + +# rust/src/ui/model_tt/layout.rs +class BacklightLevels: + """Backlight levels. Values dynamically update based on user settings.""" + MAX: ClassVar[int] + NORMAL: ClassVar[int] + LOW: ClassVar[int] + DIM: ClassVar[int] + NONE: ClassVar[int] diff --git a/core/src/all_modules.py b/core/src/all_modules.py index 5275e2dd5d..165a57d2e1 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -195,8 +195,6 @@ trezor.ui.layouts.tt.recovery import trezor.ui.layouts.tt.recovery trezor.ui.layouts.tt.reset import trezor.ui.layouts.tt.reset -trezor.ui.style -import trezor.ui.style trezor.utils import trezor.utils trezor.wire diff --git a/core/src/apps/base.py b/core/src/apps/base.py index 3e4317dfd8..e9d5fc7352 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -437,7 +437,7 @@ def reload_settings_from_storage() -> None: ) wire.EXPERIMENTAL_ENABLED = storage_device.get_experimental_features() if ui.display.orientation() != storage_device.get_rotation(): - ui.backlight_fade(ui.style.get_backlight_dim()) + ui.backlight_fade(ui.BacklightLevels.DIM) ui.display.orientation(storage_device.get_rotation()) diff --git a/core/src/boot.py b/core/src/boot.py index 134d27e0e4..cffc828b07 100644 --- a/core/src/boot.py +++ b/core/src/boot.py @@ -49,7 +49,7 @@ async def bootscreen() -> None: if can_lock_device(): enforce_welcome_screen_duration() - ui.backlight_fade(ui.style.get_backlight_dim()) + ui.backlight_fade(ui.BacklightLevels.NONE) ui.display.orientation(storage.device.get_rotation()) await lockscreen await verify_user_pin() @@ -64,7 +64,7 @@ async def bootscreen() -> None: if rotation != ui.display.orientation(): # there is a slight delay before next screen is shown, # so we don't fade unless there is a change of orientation - ui.backlight_fade(ui.style.get_backlight_dim()) + ui.backlight_fade(ui.BacklightLevels.DIM) ui.display.orientation(rotation) allow_all_loader_messages() return diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py index 785447b9cd..eaf19edf3d 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -4,6 +4,7 @@ from trezorui import Display from typing import TYPE_CHECKING, Any, Awaitable, Generator from trezor import loop, utils +from trezorui2 import BacklightLevels if TYPE_CHECKING: from typing import Generic, TypeVar @@ -53,21 +54,17 @@ if utils.EMULATOR or utils.INTERNAL_MODEL in ("T1B1", "T2B1"): loop.after_step_hook = refresh -# import style later to avoid circular dep -from trezor.ui import style # isort:skip - - async def _alert(count: int) -> None: short_sleep = loop.sleep(20) long_sleep = loop.sleep(80) for i in range(count * 2): if i % 2 == 0: - display.backlight(style.get_backlight_max()) + display.backlight(BacklightLevels.MAX) await short_sleep else: - display.backlight(style.get_backlight_dim()) + display.backlight(BacklightLevels.DIM) await long_sleep - display.backlight(style.get_backlight_normal()) + display.backlight(BacklightLevels.NORMAL) global _alert_in_progress _alert_in_progress = False diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index 586e6e6b91..98775be170 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -38,7 +38,7 @@ class RustLayout(ui.Layout): self.timer = loop.Timer() self.layout.attach_timer_fn(self.set_timer) self._send_button_request() - self.backlight_level = ui.style.get_backlight_normal() + self.backlight_level = ui.BacklightLevels.NORMAL def set_timer(self, token: int, deadline: int) -> None: self.timer.schedule(deadline, token) @@ -187,7 +187,7 @@ class RustLayout(ui.Layout): ) def _first_paint(self) -> None: - ui.backlight_fade(ui.style.get_backlight_none()) + ui.backlight_fade(ui.BacklightLevels.NONE) self._paint() if __debug__ and self.should_notify_layout_change: @@ -263,10 +263,10 @@ def draw_simple(layout: Any) -> None: raise RuntimeError layout.attach_timer_fn(dummy_set_timer) - ui.backlight_fade(ui.style.get_backlight_dim()) + ui.backlight_fade(ui.BacklightLevels.DIM) layout.paint() ui.refresh() - ui.backlight_fade(ui.style.get_backlight_normal()) + ui.backlight_fade(ui.BacklightLevels.NORMAL) async def raise_if_not_confirmed( diff --git a/core/src/trezor/ui/layouts/mercury/homescreen.py b/core/src/trezor/ui/layouts/mercury/homescreen.py index e6da99996b..bd608aefe0 100644 --- a/core/src/trezor/ui/layouts/mercury/homescreen.py +++ b/core/src/trezor/ui/layouts/mercury/homescreen.py @@ -93,9 +93,9 @@ class Lockscreen(HomescreenBase): coinjoin_authorized: bool = False, ) -> None: self.bootscreen = bootscreen - self.backlight_level = ui.style.get_backlight_low() + self.backlight_level = ui.BacklightLevels.LOW if bootscreen: - self.backlight_level = ui.style.get_backlight_normal() + self.backlight_level = ui.BacklightLevels.NORMAL skip = ( not bootscreen and storage_cache.homescreen_shown is self.RENDER_INDICATOR diff --git a/core/src/trezor/ui/layouts/progress.py b/core/src/trezor/ui/layouts/progress.py index 2b3f11a5f0..53b960a83d 100644 --- a/core/src/trezor/ui/layouts/progress.py +++ b/core/src/trezor/ui/layouts/progress.py @@ -34,11 +34,11 @@ class RustProgress: layout: Any, ): self.layout = layout - ui.backlight_fade(ui.style.get_backlight_dim()) + ui.backlight_fade(ui.BacklightLevels.DIM) self.layout.attach_timer_fn(self.set_timer) self.layout.paint() ui.refresh() - ui.backlight_fade(ui.style.get_backlight_normal()) + ui.backlight_fade(ui.BacklightLevels.NORMAL) def set_timer(self, token: int, deadline: int) -> None: raise RuntimeError # progress layouts should not set timers diff --git a/core/src/trezor/ui/layouts/tt/__init__.py b/core/src/trezor/ui/layouts/tt/__init__.py index 300a1089e7..4fe81b511f 100644 --- a/core/src/trezor/ui/layouts/tt/__init__.py +++ b/core/src/trezor/ui/layouts/tt/__init__.py @@ -44,7 +44,7 @@ class RustLayout(LayoutParentType[T]): self.timer = loop.Timer() self.layout.attach_timer_fn(self.set_timer) self._send_button_request() - self.backlight_level = ui.style.get_backlight_normal() + self.backlight_level = ui.BacklightLevels.NORMAL def set_timer(self, token: int, deadline: int) -> None: self.timer.schedule(deadline, token) @@ -193,7 +193,7 @@ class RustLayout(LayoutParentType[T]): ) def _first_paint(self) -> None: - ui.backlight_fade(ui.style.get_backlight_none()) + ui.backlight_fade(ui.BacklightLevels.NONE) self._paint() if __debug__ and self.should_notify_layout_change: @@ -269,10 +269,10 @@ def draw_simple(layout: trezorui2.LayoutObj[Any]) -> None: raise RuntimeError layout.attach_timer_fn(dummy_set_timer) - ui.backlight_fade(ui.style.get_backlight_dim()) + ui.backlight_fade(ui.BacklightLevels.DIM) layout.paint() ui.refresh() - ui.backlight_fade(ui.style.get_backlight_normal()) + ui.backlight_fade(ui.BacklightLevels.NORMAL) async def raise_if_not_confirmed( diff --git a/core/src/trezor/ui/layouts/tt/homescreen.py b/core/src/trezor/ui/layouts/tt/homescreen.py index e6da99996b..bd608aefe0 100644 --- a/core/src/trezor/ui/layouts/tt/homescreen.py +++ b/core/src/trezor/ui/layouts/tt/homescreen.py @@ -93,9 +93,9 @@ class Lockscreen(HomescreenBase): coinjoin_authorized: bool = False, ) -> None: self.bootscreen = bootscreen - self.backlight_level = ui.style.get_backlight_low() + self.backlight_level = ui.BacklightLevels.LOW if bootscreen: - self.backlight_level = ui.style.get_backlight_normal() + self.backlight_level = ui.BacklightLevels.NORMAL skip = ( not bootscreen and storage_cache.homescreen_shown is self.RENDER_INDICATOR diff --git a/core/src/trezor/ui/style.py b/core/src/trezor/ui/style.py deleted file mode 100644 index dd6affeaca..0000000000 --- a/core/src/trezor/ui/style.py +++ /dev/null @@ -1,41 +0,0 @@ -from micropython import const - -import storage.device - -# backlight brightness -_BACKLIGHT_NORMAL = const(150) -_BACKLIGHT_LOW = const(45) -_BACKLIGHT_DIM = const(5) -_BACKLIGHT_NONE = const(0) -_BACKLIGHT_MIN = const(10) -_BACKLIGHT_MAX = const(255) - - -def get_backlight_normal() -> int: - val = storage.device.get_brightness() - if val is None: - return _BACKLIGHT_NORMAL - return val - - -def get_backlight_low() -> int: - val = storage.device.get_brightness() - if val is None or val > _BACKLIGHT_LOW: - return _BACKLIGHT_LOW - return val - - -def get_backlight_dim() -> int: - return _BACKLIGHT_DIM - - -def get_backlight_none() -> int: - return _BACKLIGHT_NONE - - -def get_backlight_min() -> int: - return _BACKLIGHT_MIN - - -def get_backlight_max() -> int: - return _BACKLIGHT_MAX