Skip to content
Snippets Groups Projects
Commit 79af48df authored by schneider's avatar schneider
Browse files

imu: make available via standard input state

parent 04deefff
No related branches found
No related tags found
No related merge requests found
Pipeline #6049 failed
......@@ -5,6 +5,11 @@ def acc_read() -> Tuple[float, float, float]:
Returns current x, y, z accelerations in m/s**2.
"""
...
def gyro_read() -> Tuple[float, float, float]:
"""
Returns current pressure in Pa and temperature in degree C.
"""
...
def pressure_read() -> Tuple[float, float]:
"""
......
......@@ -3,6 +3,7 @@ from st3m.ui.ctx import Ctx
import hardware
import captouch
import imu
import math
......@@ -327,6 +328,19 @@ class TriSwitchState:
self.middle._ignore_pressed()
self.right._ignore_pressed()
class IMUState:
__slots__ = ("acc", "gyro", "pressure", "temperature")
def __init__(self) -> None:
self.acc = (0., 0., 0.)
self.gyro = (0., 0., 0.)
self.pressure = 0.
self.temperature = 0.
def _update(self, ts: int, hr: InputState) -> None:
self.acc = imu.acc_read()
self.gyro = imu.gyro_read()
self.pressure, self.temperature = imu.pressure_read()
class InputController:
"""
......@@ -344,6 +358,7 @@ class InputController:
"captouch",
"left_shoulder",
"right_shoulder",
"imu",
"_ts",
)
......@@ -351,6 +366,7 @@ class InputController:
self.captouch = CaptouchState()
self.left_shoulder = TriSwitchState(TriSwitchHandedness.left)
self.right_shoulder = TriSwitchState(TriSwitchHandedness.right)
self.imu = IMUState()
self._ts = 0
def think(self, hr: InputState, delta_ms: int) -> None:
......@@ -358,6 +374,7 @@ class InputController:
self.captouch._update(self._ts, hr)
self.left_shoulder._update(self._ts, hr)
self.right_shoulder._update(self._ts, hr)
self.imu._update(self._ts, hr)
def _ignore_pressed(self) -> None:
"""
......
import importlib
import importlib.abc
import importlib.machinery
from importlib.machinery import PathFinder, BuiltinImporter
import importlib.util
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment