From b5e4f3d4567b4305945da4ddbb80c86f37184df1 Mon Sep 17 00:00:00 2001 From: Serge Bazanski <q3k@q3k.org> Date: Sun, 13 Aug 2023 15:44:48 +0200 Subject: [PATCH] py: add battery voltage to debug overlay --- python_payload/st3m/run.py | 1 + python_payload/st3m/ui/elements/overlays.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/python_payload/st3m/run.py b/python_payload/st3m/run.py index ae95af878e..8f7dfec2d7 100644 --- a/python_payload/st3m/run.py +++ b/python_payload/st3m/run.py @@ -75,6 +75,7 @@ def _make_compositor(reactor: Reactor, vm: ViewManager) -> overlays.Compositor: # Configure debug overlay fragments. debug = overlays.OverlayDebug() debug.add_fragment(overlays.DebugReactorStats(reactor)) + debug.add_fragment(overlays.DebugBattery()) compositor.add_overlay(debug) debug_touch = overlays.OverlayCaptouch() diff --git a/python_payload/st3m/ui/elements/overlays.py b/python_payload/st3m/ui/elements/overlays.py index 83f9780b1c..41c30dbd9a 100644 --- a/python_payload/st3m/ui/elements/overlays.py +++ b/python_payload/st3m/ui/elements/overlays.py @@ -10,6 +10,7 @@ from st3m import Responder, InputState, Reactor from st3m.goose import Dict, Enum, List, ABCBase, abstractmethod, Optional from st3m.utils import tau from st3m.ui.view import ViewManager +from st3m.input import power from ctx import Context import math @@ -122,6 +123,17 @@ class DebugReactorStats(DebugFragment): return " ".join(res) +class DebugBattery(DebugFragment): + """ + DebugFragment which provides the OverlayDebug with information about the + battery voltage. + """ + + def text(self) -> str: + v = power.battery_voltage + return f"bat: {v:.2f}V" + + class OverlayDebug(Overlay): """ Overlay which renders a text bar at the bottom of the screen with random -- GitLab