mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-23 05:40:57 +00:00
TEST: homescreen
This commit is contained in:
parent
45fe153954
commit
e765633a5d
@ -24,11 +24,16 @@ use crate::{
|
|||||||
|
|
||||||
use super::{theme, Loader, LoaderMsg};
|
use super::{theme, Loader, LoaderMsg};
|
||||||
use crate::{
|
use crate::{
|
||||||
trezorhal::{ble::start_advertising, buffers::BufferJpegWork, uzlib::UZLIB_WINDOW_SIZE},
|
trezorhal::{
|
||||||
|
ble,
|
||||||
|
ble::{connected, pairing_mode},
|
||||||
|
buffers::BufferJpegWork,
|
||||||
|
uzlib::UZLIB_WINDOW_SIZE,
|
||||||
|
},
|
||||||
ui::{
|
ui::{
|
||||||
constant::HEIGHT,
|
constant::HEIGHT,
|
||||||
display::tjpgd::BufferInput,
|
display::tjpgd::BufferInput,
|
||||||
event::{ButtonEvent, PhysicalButton},
|
event::{BLEEvent, ButtonEvent, PhysicalButton},
|
||||||
model_tt::component::homescreen::render::{
|
model_tt::component::homescreen::render::{
|
||||||
HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE,
|
HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE,
|
||||||
},
|
},
|
||||||
@ -85,6 +90,7 @@ impl Homescreen {
|
|||||||
|
|
||||||
fn level_to_style(level: u8) -> (Color, Icon) {
|
fn level_to_style(level: u8) -> (Color, Icon) {
|
||||||
match level {
|
match level {
|
||||||
|
4 => (theme::BLUE, theme::ICON_MAGIC),
|
||||||
3 => (theme::YELLOW, theme::ICON_COINJOIN),
|
3 => (theme::YELLOW, theme::ICON_COINJOIN),
|
||||||
2 => (theme::VIOLET, theme::ICON_MAGIC),
|
2 => (theme::VIOLET, theme::ICON_MAGIC),
|
||||||
1 => (theme::YELLOW, theme::ICON_WARN),
|
1 => (theme::YELLOW, theme::ICON_WARN),
|
||||||
@ -93,6 +99,15 @@ impl Homescreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_notification(&self) -> Option<HomescreenNotification> {
|
fn get_notification(&self) -> Option<HomescreenNotification> {
|
||||||
|
if connected() {
|
||||||
|
let (color, icon) = Self::level_to_style(4);
|
||||||
|
return Some(HomescreenNotification {
|
||||||
|
text: "BLE connected".into(),
|
||||||
|
icon,
|
||||||
|
color,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if !usb_configured() {
|
if !usb_configured() {
|
||||||
let (color, icon) = Self::level_to_style(0);
|
let (color, icon) = Self::level_to_style(0);
|
||||||
Some(HomescreenNotification {
|
Some(HomescreenNotification {
|
||||||
@ -146,6 +161,20 @@ impl Homescreen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn event_ble(&mut self, ctx: &mut EventCtx, event: Event) {
|
||||||
|
match event {
|
||||||
|
Event::BLE(BLEEvent::Connected) | Event::BLE(BLEEvent::Disconnected) => {
|
||||||
|
self.paint_notification_only = true;
|
||||||
|
ctx.request_paint();
|
||||||
|
}
|
||||||
|
Event::BLE(BLEEvent::PairingRequest(data)) => {
|
||||||
|
ble::allow_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(_)) => {
|
||||||
@ -202,6 +231,7 @@ impl Component for Homescreen {
|
|||||||
|
|
||||||
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
|
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
|
||||||
Self::event_usb(self, ctx, event);
|
Self::event_usb(self, ctx, event);
|
||||||
|
Self::event_ble(self, ctx, event);
|
||||||
if self.hold_to_lock {
|
if self.hold_to_lock {
|
||||||
if Self::event_hold(self, ctx, event) {
|
if Self::event_hold(self, ctx, event) {
|
||||||
return Some(HomescreenMsg::Dismissed);
|
return Some(HomescreenMsg::Dismissed);
|
||||||
@ -209,7 +239,7 @@ impl Component for Homescreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Event::Button(ButtonEvent::ButtonPressed(PhysicalButton::Power)) = event {
|
if let Event::Button(ButtonEvent::ButtonPressed(PhysicalButton::Power)) = event {
|
||||||
start_advertising(false);
|
pairing_mode();
|
||||||
None
|
None
|
||||||
//Some(HomescreenMsg::Dismissed)
|
//Some(HomescreenMsg::Dismissed)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user