Skip to content
Snippets Groups Projects
Select Git revision
  • bb4ad00146ee5c0793440aec2bfd3f269ab6ce5b
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
36 results

bootstrap.sh

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    action_view.py 2.70 KiB
    from st3m.goose import Optional
    from st3m.input import InputController, InputState
    from st3m.ui.view import BaseView, ViewManager, ViewTransitionSwipeRight
    from ctx import Context
    
    from ..common import utils
    from ..common import theme
    
    from math import pi, sin, cos
    
    
    class Action:
        icon: str
        label: str
        enabled: bool
        progress: float
    
        def __init__(
            self, icon: str, label: str, enabled: bool = True, progress: float = 0.0
        ) -> None:
            self.icon = icon
            self.label = label
            self.enabled = enabled
            self.progress = progress
    
    
    class ActionView(BaseView):
        """
        A View with an action on each top petal.
    
        Each action is represented by a circular icon button and can either be
        enabled, disabled or not assigned.
        """
    
        actions: list[Optional[Action]] = [
            None,
            None,
            None,
            None,
            None,
        ]
    
        action_x: list[int] = [0] * 5
        action_y: list[int] = [0] * 5
    
        input: InputController
    
        def __init__(self) -> None:
            super().__init__()
    
            self.input = InputController()
    
            for i in range(0, 5):
                petal_angle = 2.0 * -pi / 5.0
                self.action_x[i] = int(cos(-petal_angle * float(i) - pi / 2.0) * 100.0)
                self.action_y[i] = int(sin(-petal_angle * float(i) - pi / 2.0) * 100.0)
    
        def on_enter(self, vm: ViewManager | None) -> None:
            super().on_enter(vm)
    
        def think(self, ins: InputState, delta_ms: int) -> None:
            self.input.think(ins, delta_ms)
    
        def draw(self, ctx: Context) -> None:
            for i in range(0, 5):
                action = self.actions[i]
    
                if action is None:
                    continue
    
                if action.enabled:
                    utils.draw_circle(
                        ctx,
                        theme.PRIMARY,
                        self.action_x[i],
                        self.action_y[i],
                        18,
                        action.progress,
                    )
                else:
                    utils.draw_circle(
                        ctx, theme.PRIMARY, self.action_x[i], self.action_y[i], 18
                    )
                    utils.draw_circle(
                        ctx, theme.BACKGROUND, self.action_x[i], self.action_y[i], 17
                    )
    
            ctx.save()
            ctx.text_align = ctx.CENTER
            ctx.text_baseline = ctx.HANGING
            ctx.font_size = 30
            ctx.font = "Material Icons"
            ctx.rgb(*theme.PRIMARY_TEXT)
    
            for i in range(0, 5):
                action = self.actions[i]
                if action is None:
                    continue
    
                if not action.enabled:
                    continue
    
                ctx.move_to(self.action_x[i], self.action_y[i] - 2)
                ctx.text(action.icon)
            ctx.restore()