diff --git a/src/apps/common/storage.py b/src/apps/common/storage.py index f477439f8a..ec5e551739 100644 --- a/src/apps/common/storage.py +++ b/src/apps/common/storage.py @@ -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: diff --git a/src/apps/homescreen/homescreen.py b/src/apps/homescreen/homescreen.py index 9929832f49..6bc6b4e109 100644 --- a/src/apps/homescreen/homescreen.py +++ b/src/apps/homescreen/homescreen.py @@ -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)) diff --git a/src/apps/management/apply_settings.py b/src/apps/management/apply_settings.py index 8b519a21c5..ea86aaefb2 100644 --- a/src/apps/management/apply_settings.py +++ b/src/apps/management/apply_settings.py @@ -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) diff --git a/src/boot.py b/src/boot.py index 292de1e1a0..1368da229d 100644 --- a/src/boot.py +++ b/src/boot.py @@ -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(): diff --git a/src/trezor/ui/swipe.py b/src/trezor/ui/swipe.py index 7f371753c4..02dd2ccbb1 100644 --- a/src/trezor/ui/swipe.py +++ b/src/trezor/ui/swipe.py @@ -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)