diff --git a/python_payload/mypystubs/network.pyi b/python_payload/mypystubs/network.pyi index 13d68ef5c702ccdca562169e8fc7f08d173bf71e..9a8723877138755ec96982ecf62cf49d8810f373 100644 --- a/python_payload/mypystubs/network.pyi +++ b/python_payload/mypystubs/network.pyi @@ -3,11 +3,8 @@ from st3m.goose import Optional STA_IF: int class WLAN: - def __init__(self, mode: int) -> None: - pass - def active(self, active: bool) -> bool: - return False - def connect(self, ssid: bytes, key: Optional[bytes] = None) -> None: - pass - def isconnected(self) -> bool: - return False + def __init__(self, mode: int) -> None: ... + def active(self, active: bool) -> bool: ... + def connect(self, ssid: bytes, key: Optional[bytes] = None) -> None: ... + def isconnected(self) -> bool: ... + def status(self, s: str) -> float: ... diff --git a/python_payload/st3m/ui/elements/overlays.py b/python_payload/st3m/ui/elements/overlays.py index 41c30dbd9a26d978195d09db08a00eb0cd72a0a6..3cb1701d0582533300169fc087cef49f5a5a8bd8 100644 --- a/python_payload/st3m/ui/elements/overlays.py +++ b/python_payload/st3m/ui/elements/overlays.py @@ -12,10 +12,12 @@ from st3m.utils import tau from st3m.ui.view import ViewManager from st3m.input import power from ctx import Context +import st3m.wifi import math import audio import sys_kernel +import network class OverlayKind(Enum): @@ -375,6 +377,33 @@ class USBIcon(Icon): pass +class WifiIcon(Icon): + def __init__(self) -> None: + super().__init__() + self._rssi: float = -120 + + def visible(self) -> bool: + return st3m.wifi.enabled() + + def draw(self, ctx: Context) -> None: + ctx.gray(1.0) + ctx.line_width = 10.0 + w = 1.5 + a = -w / 2 - 3.14 / 2 + b = w / 2 - 3.14 / 2 + + r = self._rssi + ctx.gray(1.0 if r > -775 else 0.2) + ctx.arc(0, 60, 100, a, b, 0).stroke() + ctx.gray(1.0 if r > -85 else 0.2) + ctx.arc(0, 60, 70, a, b, 0).stroke() + ctx.gray(1.0 if r > -95 else 0.2) + ctx.arc(0, 60, 40, a, b, 0).stroke() + + def think(self, ins: InputState, delta_ms: int) -> None: + self._rssi = st3m.wifi.rssi() + + class IconTray(Overlay): """ An overlay which renders Icons. @@ -385,6 +414,7 @@ class IconTray(Overlay): def __init__(self) -> None: self.icons = [ USBIcon(), + WifiIcon(), ] self.visible: List[Icon] = [] @@ -395,7 +425,7 @@ class IconTray(Overlay): def draw(self, ctx: Context) -> None: nicons = len(self.visible) - dist = 20 + dist = 25 width = (nicons - 1) * dist x0 = width / -2 for i, v in enumerate(self.visible): diff --git a/python_payload/st3m/wifi.py b/python_payload/st3m/wifi.py index cca57e4a500ae566bf2cba2aaadee1cadebf5784..d9daa67d779dcb9ea38c168f76e8c386d3bdc7c2 100644 --- a/python_payload/st3m/wifi.py +++ b/python_payload/st3m/wifi.py @@ -18,8 +18,14 @@ def setup_camp_wifi() -> None: def disable() -> None: + global iface if iface is not None: iface.active(False) + iface = None + + +def enabled() -> bool: + return iface is not None def is_connected() -> bool: @@ -34,3 +40,12 @@ def _onoff_camp_wifi_update() -> None: setup_camp_wifi() else: disable() + + +def rssi() -> float: + if iface is None: + return -120 + try: + return iface.status("rssi") + except OSError: + return -120