mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 17:38:39 +00:00
TEST: pairing dialog
This commit is contained in:
parent
e765633a5d
commit
02ad6060c5
@ -22,7 +22,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{theme, Loader, LoaderMsg};
|
use super::{theme, Button, Loader, LoaderMsg};
|
||||||
use crate::{
|
use crate::{
|
||||||
trezorhal::{
|
trezorhal::{
|
||||||
ble,
|
ble,
|
||||||
@ -31,11 +31,13 @@ use crate::{
|
|||||||
uzlib::UZLIB_WINDOW_SIZE,
|
uzlib::UZLIB_WINDOW_SIZE,
|
||||||
},
|
},
|
||||||
ui::{
|
ui::{
|
||||||
|
component::Label,
|
||||||
constant::HEIGHT,
|
constant::HEIGHT,
|
||||||
display::tjpgd::BufferInput,
|
display::tjpgd::BufferInput,
|
||||||
event::{BLEEvent, ButtonEvent, PhysicalButton},
|
event::{BLEEvent, ButtonEvent, PhysicalButton},
|
||||||
model_tt::component::homescreen::render::{
|
model_tt::component::{
|
||||||
HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE,
|
bl_confirm::{Confirm, ConfirmMsg, ConfirmTitle},
|
||||||
|
homescreen::render::{HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -64,6 +66,8 @@ pub struct Homescreen {
|
|||||||
pad: Pad,
|
pad: Pad,
|
||||||
paint_notification_only: bool,
|
paint_notification_only: bool,
|
||||||
delay: Option<TimerToken>,
|
delay: Option<TimerToken>,
|
||||||
|
pairing: bool,
|
||||||
|
pairing_dialog: Option<Confirm<'static>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum HomescreenMsg {
|
pub enum HomescreenMsg {
|
||||||
@ -85,6 +89,8 @@ impl Homescreen {
|
|||||||
pad: Pad::with_background(theme::BG),
|
pad: Pad::with_background(theme::BG),
|
||||||
paint_notification_only: false,
|
paint_notification_only: false,
|
||||||
delay: None,
|
delay: None,
|
||||||
|
pairing: false,
|
||||||
|
pairing_dialog: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,13 +174,44 @@ impl Homescreen {
|
|||||||
ctx.request_paint();
|
ctx.request_paint();
|
||||||
}
|
}
|
||||||
Event::BLE(BLEEvent::PairingRequest(data)) => {
|
Event::BLE(BLEEvent::PairingRequest(data)) => {
|
||||||
ble::allow_pairing();
|
self.pairing = true;
|
||||||
}
|
|
||||||
|
|
||||||
|
let code = core::str::from_utf8(data).unwrap();
|
||||||
|
|
||||||
|
let mut pd = Confirm::new(
|
||||||
|
theme::BG,
|
||||||
|
Button::with_text("Cancel".into()),
|
||||||
|
Button::with_text("Confirm".into()),
|
||||||
|
ConfirmTitle::Text(Label::new(
|
||||||
|
"Pairing Request".into(),
|
||||||
|
Alignment::Start,
|
||||||
|
theme::TEXT_BOLD,
|
||||||
|
)),
|
||||||
|
Label::new(
|
||||||
|
"Pairing request received from another device. Confirm to pair.".into(),
|
||||||
|
Alignment::Center,
|
||||||
|
theme::TEXT_NORMAL,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.with_alert(Label::new(
|
||||||
|
code.into(),
|
||||||
|
Alignment::Center,
|
||||||
|
theme::TEXT_NORMAL,
|
||||||
|
));
|
||||||
|
|
||||||
|
pd.place(AREA);
|
||||||
|
|
||||||
|
self.pairing_dialog = Some(pd);
|
||||||
|
ctx.request_paint();
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pairing(&self) -> bool {
|
||||||
|
self.pairing
|
||||||
|
}
|
||||||
|
|
||||||
fn event_hold(&mut self, ctx: &mut EventCtx, event: Event) -> bool {
|
fn event_hold(&mut self, ctx: &mut EventCtx, event: Event) -> bool {
|
||||||
match event {
|
match event {
|
||||||
Event::Touch(TouchEvent::TouchStart(_)) => {
|
Event::Touch(TouchEvent::TouchStart(_)) => {
|
||||||
@ -226,6 +263,7 @@ impl Component for Homescreen {
|
|||||||
fn place(&mut self, bounds: Rect) -> Rect {
|
fn place(&mut self, bounds: Rect) -> Rect {
|
||||||
self.pad.place(AREA);
|
self.pad.place(AREA);
|
||||||
self.loader.place(AREA.translate(LOADER_OFFSET));
|
self.loader.place(AREA.translate(LOADER_OFFSET));
|
||||||
|
self.pairing_dialog.place(AREA);
|
||||||
bounds
|
bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,6 +276,23 @@ impl Component for Homescreen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.pairing() {
|
||||||
|
if let Some(msg) = self.pairing_dialog.event(ctx, event) {
|
||||||
|
match msg {
|
||||||
|
ConfirmMsg::Cancel => {
|
||||||
|
ble::reject_pairing();
|
||||||
|
self.pairing = false;
|
||||||
|
ctx.request_paint();
|
||||||
|
}
|
||||||
|
ConfirmMsg::Confirm => {
|
||||||
|
ble::allow_pairing();
|
||||||
|
self.pairing = false;
|
||||||
|
ctx.request_paint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Event::Button(ButtonEvent::ButtonPressed(PhysicalButton::Power)) = event {
|
if let Event::Button(ButtonEvent::ButtonPressed(PhysicalButton::Power)) = event {
|
||||||
pairing_mode();
|
pairing_mode();
|
||||||
None
|
None
|
||||||
@ -301,6 +356,8 @@ impl Component for Homescreen {
|
|||||||
self.pad.render(target);
|
self.pad.render(target);
|
||||||
if self.loader.is_animating() || self.loader.is_completely_grown(Instant::now()) {
|
if self.loader.is_animating() || self.loader.is_completely_grown(Instant::now()) {
|
||||||
self.render_loader(target);
|
self.render_loader(target);
|
||||||
|
} else if self.pairing() {
|
||||||
|
self.pairing_dialog.render(target);
|
||||||
} else {
|
} else {
|
||||||
match ImageInfo::parse(self.image) {
|
match ImageInfo::parse(self.image) {
|
||||||
ImageInfo::Jpeg(_) => {
|
ImageInfo::Jpeg(_) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user