mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
refactor(core): move set_brightness to UiFeatures
- this is a first commit where a trait function is not implemented for particular model, namely `set_brightness` for `model_r`
This commit is contained in:
parent
f202ea2703
commit
e82988665c
@ -12,9 +12,10 @@ use crate::{
|
|||||||
trezorhal::model,
|
trezorhal::model,
|
||||||
ui::{
|
ui::{
|
||||||
backlight::BACKLIGHT_LEVELS_OBJ,
|
backlight::BACKLIGHT_LEVELS_OBJ,
|
||||||
|
component::Empty,
|
||||||
layout::{
|
layout::{
|
||||||
base::LAYOUT_STATE,
|
base::LAYOUT_STATE,
|
||||||
obj::{LayoutObj, ATTACH_TYPE_OBJ},
|
obj::{ComponentMsgObj, LayoutObj, ATTACH_TYPE_OBJ},
|
||||||
result::{CANCELLED, CONFIRMED, INFO},
|
result::{CANCELLED, CONFIRMED, INFO},
|
||||||
util::{upy_disable_animation, RecoveryType},
|
util::{upy_disable_animation, RecoveryType},
|
||||||
},
|
},
|
||||||
@ -23,6 +24,14 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Dummy implementation so that we can use `Empty` in a return type of unimplemented trait
|
||||||
|
/// function
|
||||||
|
impl ComponentMsgObj for Empty {
|
||||||
|
fn msg_try_into_obj(&self, _msg: Self::Msg) -> Result<Obj, crate::error::Error> {
|
||||||
|
Ok(Obj::const_none())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// free-standing functions exported to MicroPython mirror `trait
|
// free-standing functions exported to MicroPython mirror `trait
|
||||||
// UIFeaturesFirmware`
|
// UIFeaturesFirmware`
|
||||||
// NOTE: `disable_animation` not a part of trait UiFeaturesFirmware
|
// NOTE: `disable_animation` not a part of trait UiFeaturesFirmware
|
||||||
@ -172,6 +181,16 @@ extern "C" fn new_select_word_count(n_args: usize, args: *const Obj, kwargs: *mu
|
|||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||||
|
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||||
|
let current: Option<u8> = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?;
|
||||||
|
|
||||||
|
let layout = ModelUI::set_brightness(current)?;
|
||||||
|
Ok(LayoutObj::new_root(layout)?.into())
|
||||||
|
};
|
||||||
|
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" fn new_show_homescreen(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
extern "C" fn new_show_homescreen(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||||
let label: TString<'static> = kwargs
|
let label: TString<'static> = kwargs
|
||||||
@ -429,6 +448,13 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
|||||||
/// For unlocking a repeated backup, select from 20 or 33."""
|
/// For unlocking a repeated backup, select from 20 or 33."""
|
||||||
Qstr::MP_QSTR_select_word_count => obj_fn_kw!(0, new_select_word_count).as_obj(),
|
Qstr::MP_QSTR_select_word_count => obj_fn_kw!(0, new_select_word_count).as_obj(),
|
||||||
|
|
||||||
|
/// def set_brightness(
|
||||||
|
/// *,
|
||||||
|
/// current: int | None = None
|
||||||
|
/// ) -> LayoutObj[UiResult]:
|
||||||
|
/// """Show the brightness configuration dialog."""
|
||||||
|
Qstr::MP_QSTR_set_brightness => obj_fn_kw!(0, new_set_brightness).as_obj(),
|
||||||
|
|
||||||
/// def show_homescreen(
|
/// def show_homescreen(
|
||||||
/// *,
|
/// *,
|
||||||
/// label: str | None,
|
/// label: str | None,
|
||||||
|
@ -572,15 +572,6 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
|
|||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
|
||||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
|
||||||
let current: u8 = kwargs.get(Qstr::MP_QSTR_current)?.try_into()?;
|
|
||||||
let flow = flow::set_brightness::new_set_brightness(current)?;
|
|
||||||
Ok(LayoutObj::new_root(flow)?.into())
|
|
||||||
};
|
|
||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn new_show_info_with_cancel(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
extern "C" fn new_show_info_with_cancel(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||||
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
|
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
|
||||||
@ -1501,13 +1492,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
|||||||
/// info."""
|
/// info."""
|
||||||
Qstr::MP_QSTR_flow_request_number => obj_fn_kw!(0, new_request_number).as_obj(),
|
Qstr::MP_QSTR_flow_request_number => obj_fn_kw!(0, new_request_number).as_obj(),
|
||||||
|
|
||||||
/// def set_brightness(
|
|
||||||
/// *,
|
|
||||||
/// current: int | None = None
|
|
||||||
/// ) -> LayoutObj[UiResult]:
|
|
||||||
/// """Show the brightness configuration dialog."""
|
|
||||||
Qstr::MP_QSTR_set_brightness => obj_fn_kw!(0, new_set_brightness).as_obj(),
|
|
||||||
|
|
||||||
/// def show_checklist(
|
/// def show_checklist(
|
||||||
/// *,
|
/// *,
|
||||||
/// title: str,
|
/// title: str,
|
||||||
|
@ -179,6 +179,13 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
|||||||
Ok(layout)
|
Ok(layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_brightness(current_brightness: Option<u8>) -> Result<impl LayoutMaybeTrace, Error> {
|
||||||
|
let flow = flow::set_brightness::new_set_brightness(
|
||||||
|
current_brightness.unwrap_or(theme::backlight::get_backlight_normal()),
|
||||||
|
)?;
|
||||||
|
Ok(flow)
|
||||||
|
}
|
||||||
|
|
||||||
fn show_homescreen(
|
fn show_homescreen(
|
||||||
label: TString<'static>,
|
label: TString<'static>,
|
||||||
hold: bool,
|
hold: bool,
|
||||||
|
@ -197,6 +197,12 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
|||||||
Ok(layout)
|
Ok(layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_brightness(current_brightness: Option<u8>) -> Result<impl LayoutMaybeTrace, Error> {
|
||||||
|
Err::<RootComponent<Empty, ModelTRFeatures>, Error>(Error::ValueError(
|
||||||
|
c"setting brightness not supported",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
fn show_homescreen(
|
fn show_homescreen(
|
||||||
label: TString<'static>,
|
label: TString<'static>,
|
||||||
hold: bool,
|
hold: bool,
|
||||||
|
@ -17,8 +17,7 @@ use super::{
|
|||||||
pub struct SetBrightnessDialog(NumberInputSliderDialog);
|
pub struct SetBrightnessDialog(NumberInputSliderDialog);
|
||||||
|
|
||||||
impl SetBrightnessDialog {
|
impl SetBrightnessDialog {
|
||||||
pub fn new(current: Option<u8>) -> Self {
|
pub fn new(current: u8) -> Self {
|
||||||
let current = current.unwrap_or(theme::backlight::get_backlight_normal());
|
|
||||||
Self(NumberInputSliderDialog::new(
|
Self(NumberInputSliderDialog::new(
|
||||||
theme::backlight::get_backlight_min() as u16,
|
theme::backlight::get_backlight_min() as u16,
|
||||||
theme::backlight::get_backlight_max() as u16,
|
theme::backlight::get_backlight_max() as u16,
|
||||||
|
@ -1172,19 +1172,6 @@ extern "C" fn new_request_number(n_args: usize, args: *const Obj, kwargs: *mut M
|
|||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
|
||||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
|
||||||
let current: Option<u8> = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?;
|
|
||||||
let obj = LayoutObj::new(Frame::centered(
|
|
||||||
theme::label_title(),
|
|
||||||
TR::brightness__title.into(),
|
|
||||||
SetBrightnessDialog::new(current),
|
|
||||||
))?;
|
|
||||||
Ok(obj.into())
|
|
||||||
};
|
|
||||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn new_show_checklist(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
extern "C" fn new_show_checklist(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||||
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
|
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
|
||||||
@ -1618,13 +1605,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
|||||||
/// """Number input with + and - buttons, description, and info button."""
|
/// """Number input with + and - buttons, description, and info button."""
|
||||||
Qstr::MP_QSTR_request_number => obj_fn_kw!(0, new_request_number).as_obj(),
|
Qstr::MP_QSTR_request_number => obj_fn_kw!(0, new_request_number).as_obj(),
|
||||||
|
|
||||||
/// def set_brightness(
|
|
||||||
/// *,
|
|
||||||
/// current: int | None = None
|
|
||||||
/// ) -> LayoutObj[UiResult]:
|
|
||||||
/// """Show the brightness configuration dialog."""
|
|
||||||
Qstr::MP_QSTR_set_brightness => obj_fn_kw!(0, new_set_brightness).as_obj(),
|
|
||||||
|
|
||||||
/// def show_checklist(
|
/// def show_checklist(
|
||||||
/// *,
|
/// *,
|
||||||
/// title: str,
|
/// title: str,
|
||||||
|
@ -22,7 +22,7 @@ use super::{
|
|||||||
component::{
|
component::{
|
||||||
check_homescreen_format, Bip39Input, Button, ButtonMsg, ButtonPage, ButtonStyleSheet,
|
check_homescreen_format, Bip39Input, Button, ButtonMsg, ButtonPage, ButtonStyleSheet,
|
||||||
CancelConfirmMsg, Dialog, Frame, Homescreen, IconDialog, Lockscreen, MnemonicKeyboard,
|
CancelConfirmMsg, Dialog, Frame, Homescreen, IconDialog, Lockscreen, MnemonicKeyboard,
|
||||||
PassphraseKeyboard, PinKeyboard, SelectWordCount, Slip39Input,
|
PassphraseKeyboard, PinKeyboard, SelectWordCount, SetBrightnessDialog, Slip39Input,
|
||||||
},
|
},
|
||||||
theme, ModelTTFeatures,
|
theme, ModelTTFeatures,
|
||||||
};
|
};
|
||||||
@ -209,6 +209,18 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
|||||||
Ok(layout)
|
Ok(layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_brightness(current_brightness: Option<u8>) -> Result<impl LayoutMaybeTrace, Error> {
|
||||||
|
let layout = RootComponent::new(Frame::centered(
|
||||||
|
theme::label_title(),
|
||||||
|
TR::brightness__title.into(),
|
||||||
|
SetBrightnessDialog::new(
|
||||||
|
current_brightness.unwrap_or(theme::backlight::get_backlight_normal()),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
Ok(layout)
|
||||||
|
}
|
||||||
|
|
||||||
fn show_homescreen(
|
fn show_homescreen(
|
||||||
label: TString<'static>,
|
label: TString<'static>,
|
||||||
hold: bool,
|
hold: bool,
|
||||||
|
@ -64,6 +64,8 @@ pub trait UIFeaturesFirmware {
|
|||||||
|
|
||||||
fn select_word_count(recovery_type: RecoveryType) -> Result<impl LayoutMaybeTrace, Error>;
|
fn select_word_count(recovery_type: RecoveryType) -> Result<impl LayoutMaybeTrace, Error>;
|
||||||
|
|
||||||
|
fn set_brightness(current_brightness: Option<u8>) -> Result<impl LayoutMaybeTrace, Error>;
|
||||||
|
|
||||||
fn show_homescreen(
|
fn show_homescreen(
|
||||||
label: TString<'static>,
|
label: TString<'static>,
|
||||||
hold: bool,
|
hold: bool,
|
||||||
|
@ -268,14 +268,6 @@ def flow_request_number(
|
|||||||
info."""
|
info."""
|
||||||
|
|
||||||
|
|
||||||
# rust/src/ui/model_mercury/layout.rs
|
|
||||||
def set_brightness(
|
|
||||||
*,
|
|
||||||
current: int | None = None
|
|
||||||
) -> LayoutObj[UiResult]:
|
|
||||||
"""Show the brightness configuration dialog."""
|
|
||||||
|
|
||||||
|
|
||||||
# rust/src/ui/model_mercury/layout.rs
|
# rust/src/ui/model_mercury/layout.rs
|
||||||
def show_checklist(
|
def show_checklist(
|
||||||
*,
|
*,
|
||||||
@ -1003,14 +995,6 @@ def request_number(
|
|||||||
"""Number input with + and - buttons, description, and info button."""
|
"""Number input with + and - buttons, description, and info button."""
|
||||||
|
|
||||||
|
|
||||||
# rust/src/ui/model_tt/layout.rs
|
|
||||||
def set_brightness(
|
|
||||||
*,
|
|
||||||
current: int | None = None
|
|
||||||
) -> LayoutObj[UiResult]:
|
|
||||||
"""Show the brightness configuration dialog."""
|
|
||||||
|
|
||||||
|
|
||||||
# rust/src/ui/model_tt/layout.rs
|
# rust/src/ui/model_tt/layout.rs
|
||||||
def show_checklist(
|
def show_checklist(
|
||||||
*,
|
*,
|
||||||
|
@ -174,6 +174,14 @@ def select_word_count(
|
|||||||
For unlocking a repeated backup, select from 20 or 33."""
|
For unlocking a repeated backup, select from 20 or 33."""
|
||||||
|
|
||||||
|
|
||||||
|
# rust/src/ui/api/firmware_upy.rs
|
||||||
|
def set_brightness(
|
||||||
|
*,
|
||||||
|
current: int | None = None
|
||||||
|
) -> LayoutObj[UiResult]:
|
||||||
|
"""Show the brightness configuration dialog."""
|
||||||
|
|
||||||
|
|
||||||
# rust/src/ui/api/firmware_upy.rs
|
# rust/src/ui/api/firmware_upy.rs
|
||||||
def show_homescreen(
|
def show_homescreen(
|
||||||
*,
|
*,
|
||||||
|
@ -1193,7 +1193,7 @@ def confirm_firmware_update(description: str, fingerprint: str) -> Awaitable[Non
|
|||||||
|
|
||||||
def set_brightness(current: int | None = None) -> Awaitable[None]:
|
def set_brightness(current: int | None = None) -> Awaitable[None]:
|
||||||
return raise_if_not_confirmed(
|
return raise_if_not_confirmed(
|
||||||
trezorui2.set_brightness(current=current),
|
trezorui_api.set_brightness(current=current),
|
||||||
"set_brightness",
|
"set_brightness",
|
||||||
BR_CODE_OTHER,
|
BR_CODE_OTHER,
|
||||||
)
|
)
|
||||||
|
@ -1262,7 +1262,7 @@ def confirm_firmware_update(description: str, fingerprint: str) -> Awaitable[Non
|
|||||||
|
|
||||||
async def set_brightness(current: int | None = None) -> None:
|
async def set_brightness(current: int | None = None) -> None:
|
||||||
await interact(
|
await interact(
|
||||||
trezorui2.set_brightness(current=current),
|
trezorui_api.set_brightness(current=current),
|
||||||
"set_brightness",
|
"set_brightness",
|
||||||
BR_CODE_OTHER,
|
BR_CODE_OTHER,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user