mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
parent
c2b7b8032a
commit
c462918e3e
@ -31,6 +31,7 @@ _UNFINISHED_BACKUP = const(0x0B) # bool (0x01 or empty)
|
||||
_AUTOLOCK_DELAY_MS = const(0x0C) # int
|
||||
_NO_BACKUP = const(0x0D) # bool (0x01 or empty)
|
||||
_MNEMONIC_TYPE = const(0x0E) # int
|
||||
_ROTATION = const(0x0F) # int
|
||||
# fmt: on
|
||||
|
||||
|
||||
@ -68,6 +69,13 @@ def get_device_id() -> str:
|
||||
return dev_id.decode()
|
||||
|
||||
|
||||
def get_rotation() -> int:
|
||||
rotation = config.get(_APP, _ROTATION, True) # public
|
||||
if not rotation:
|
||||
return 0
|
||||
return int.from_bytes(rotation, "big")
|
||||
|
||||
|
||||
def is_initialized() -> bool:
|
||||
return bool(config.get(_APP, _VERSION))
|
||||
|
||||
@ -144,6 +152,7 @@ def load_settings(
|
||||
use_passphrase: bool = None,
|
||||
homescreen: bytes = None,
|
||||
passphrase_source: int = None,
|
||||
display_rotation: int = None,
|
||||
) -> None:
|
||||
if label is not None:
|
||||
config.set(_APP, _LABEL, label.encode(), True) # public
|
||||
@ -156,8 +165,17 @@ def load_settings(
|
||||
else:
|
||||
config.set(_APP, _HOMESCREEN, b"", True) # public
|
||||
if passphrase_source is not None:
|
||||
if passphrase_source in [0, 1, 2]:
|
||||
if passphrase_source in (0, 1, 2):
|
||||
config.set(_APP, _PASSPHRASE_SOURCE, bytes([passphrase_source]))
|
||||
if display_rotation is not None:
|
||||
if display_rotation not in (0, 90, 180, 270):
|
||||
raise ValueError(
|
||||
"Unsupported display rotation degrees: %d" % display_rotation
|
||||
)
|
||||
else:
|
||||
config.set(
|
||||
_APP, _ROTATION, display_rotation.to_bytes(2, "big"), True
|
||||
) # public
|
||||
|
||||
|
||||
def get_flags() -> int:
|
||||
|
@ -1,15 +1,12 @@
|
||||
from trezor import config, res, ui
|
||||
from trezor.ui.swipe import Swipe, degrees
|
||||
|
||||
from apps.common import storage
|
||||
|
||||
|
||||
async def homescreen():
|
||||
while True:
|
||||
await ui.backlight_slide(ui.BACKLIGHT_DIM)
|
||||
display_homescreen()
|
||||
await ui.backlight_slide(ui.BACKLIGHT_NORMAL)
|
||||
await swipe_to_rotate()
|
||||
await ui.backlight_slide(ui.BACKLIGHT_DIM)
|
||||
display_homescreen()
|
||||
await ui.backlight_slide(ui.BACKLIGHT_NORMAL)
|
||||
|
||||
|
||||
def display_homescreen():
|
||||
@ -49,8 +46,3 @@ def display_homescreen():
|
||||
ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG)
|
||||
ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK)
|
||||
ui.display.text_center(ui.WIDTH // 2, 220, label, ui.BOLD, ui.FG, ui.BG)
|
||||
|
||||
|
||||
async def swipe_to_rotate():
|
||||
swipe = await Swipe(absolute=True)
|
||||
ui.display.orientation(degrees(swipe))
|
||||
|
@ -13,6 +13,7 @@ async def apply_settings(ctx, msg):
|
||||
and msg.label is None
|
||||
and msg.use_passphrase is None
|
||||
and msg.passphrase_source is None
|
||||
and msg.display_rotation is None
|
||||
):
|
||||
raise wire.ProcessError("No setting provided")
|
||||
|
||||
@ -30,13 +31,20 @@ async def apply_settings(ctx, msg):
|
||||
if msg.passphrase_source is not None:
|
||||
await require_confirm_change_passphrase_source(ctx, msg.passphrase_source)
|
||||
|
||||
if msg.display_rotation is not None:
|
||||
await require_confirm_change_display_rotation(ctx, msg.display_rotation)
|
||||
|
||||
storage.load_settings(
|
||||
label=msg.label,
|
||||
use_passphrase=msg.use_passphrase,
|
||||
homescreen=msg.homescreen,
|
||||
passphrase_source=msg.passphrase_source,
|
||||
display_rotation=msg.display_rotation,
|
||||
)
|
||||
|
||||
if msg.display_rotation is not None:
|
||||
ui.display.orientation(storage.get_rotation())
|
||||
|
||||
return Success(message="Settings applied")
|
||||
|
||||
|
||||
@ -72,3 +80,19 @@ async def require_confirm_change_passphrase_source(ctx, source):
|
||||
text.normal("Do you really want to", "change the passphrase", "source to")
|
||||
text.bold("ALWAYS %s?" % desc)
|
||||
await require_confirm(ctx, text, code=ButtonRequestType.ProtectCall)
|
||||
|
||||
|
||||
async def require_confirm_change_display_rotation(ctx, rotation):
|
||||
if rotation == 0:
|
||||
label = "north"
|
||||
elif rotation == 90:
|
||||
label = "east"
|
||||
elif rotation == 180:
|
||||
label = "south"
|
||||
elif rotation == 270:
|
||||
label = "west"
|
||||
text = Text("Change rotation", ui.ICON_CONFIG, new_lines=False)
|
||||
text.normal("Do you really want to", "change display rotation")
|
||||
text.normal("to")
|
||||
text.bold("%s?" % label)
|
||||
await require_confirm(ctx, text, code=ButtonRequestType.ProtectCall)
|
||||
|
@ -6,6 +6,7 @@ from apps.common.request_pin import request_pin
|
||||
|
||||
|
||||
async def bootscreen():
|
||||
ui.display.orientation(storage.get_rotation())
|
||||
while True:
|
||||
try:
|
||||
if not config.has_pin():
|
||||
|
@ -14,17 +14,6 @@ SWIPE_ALL = const(SWIPE_VERTICAL | SWIPE_HORIZONTAL)
|
||||
_SWIPE_DISTANCE = const(120)
|
||||
|
||||
|
||||
def degrees(swipe: int) -> int:
|
||||
if swipe == SWIPE_UP:
|
||||
return 180
|
||||
elif swipe == SWIPE_DOWN:
|
||||
return 0
|
||||
elif swipe == SWIPE_LEFT:
|
||||
return 90
|
||||
elif swipe == SWIPE_RIGHT:
|
||||
return 270
|
||||
|
||||
|
||||
class Swipe(ui.Widget):
|
||||
def __init__(self, area=None, absolute=False, directions=SWIPE_ALL, treshold=30):
|
||||
self.area = area or (0, 0, ui.WIDTH, ui.HEIGHT)
|
||||
|
Loading…
Reference in New Issue
Block a user