Rework radar system

This commit is contained in:
Ayzen
2026-10-06 12:32:26 +03:00
parent 552cdc688a
commit 5bb86b7165
299 changed files with 13537 additions and 27763 deletions
@@ -1,13 +1,11 @@
"""Switch driver implementations for native GPIO and mock operation."""
from python_app.hardware_full.switch_drivers.h7992_driver import H7992Driver
from python_app.hardware_full.switch_drivers.hmc349a_driver import HMC349ADriver
from python_app.hardware_full.switch_drivers.interface import SwitchDriverProtocol
from python_app.hardware_full.switch_drivers.mock_driver import MockSwitchDriver
__all__ = [
"H7992Driver",
"HMC349ADriver",
"MockSwitchDriver",
"SwitchDriverProtocol",
]
@@ -1,84 +0,0 @@
"""Native GPIO driver for HMC349A switch."""
from __future__ import annotations
from dataclasses import dataclass, field
from contextlib import suppress
from python_app.hardware_full.switch_drivers.gpio_uapi import GpioOutputLines
@dataclass(slots=True)
class HMC349ADriver:
"""Drive HMC349A using one control GPIO line."""
name: str
positions: int = 2
default_position: int = 0
gpio_chip: str = "/dev/gpiochip0"
pin_a: int = 17
invert_logic: bool = False
_lines: GpioOutputLines | None = field(init=False, default=None, repr=False)
_is_open: bool = field(init=False, default=False, repr=False)
_current_position: int = field(init=False, default=0, repr=False)
def open(self) -> None:
"""Open GPIO lines and switch to default position."""
if self._is_open:
return
self._validate()
offsets = [self.pin_a]
self._lines = GpioOutputLines(
chip=self.gpio_chip,
offsets=offsets,
consumer=f"radar_{self.name}",
)
try:
self._lines.open()
self._is_open = True
self.switch_to(self.default_position)
except Exception:
with suppress(Exception):
self.close()
raise
def close(self) -> None:
"""Close GPIO lines."""
lines, self._lines = self._lines, None
self._is_open = False
if lines is not None:
lines.close()
def position_count(self) -> int:
"""Return number of supported positions."""
return self.positions
def switch_to(self, position: int) -> None:
"""Switch hardware to selected position."""
if not self._is_open or self._lines is None:
raise RuntimeError(f"Switch driver is not open for {self.name}")
if position < 0 or position >= self.positions:
raise ValueError(f"Position out of range for {self.name}: {position}")
control = int(position & 0x01)
if self.invert_logic:
control ^= 0x01
self._lines.set_values([control])
self._current_position = int(position)
@property
def current_position(self) -> int:
"""Return current position."""
return self._current_position
def _validate(self) -> None:
"""Validate HMC349A driver parameters."""
if self.positions <= 0 or self.positions > 2:
raise ValueError(f"HMC349A positions must be in range [1,2] for {self.name}")
if self.default_position < 0 or self.default_position >= self.positions:
raise ValueError(f"default_position out of range for {self.name}")
if self.pin_a < 0:
raise ValueError(f"pin_a is invalid for {self.name}")
@@ -16,6 +16,7 @@ class SwitchDriverProtocol(Protocol):
def position_count(self) -> int:
"""Return total number of supported positions."""
...
def switch_to(self, position: int) -> None:
"""Switch to requested zero-based position."""
@@ -23,3 +24,4 @@ class SwitchDriverProtocol(Protocol):
@property
def current_position(self) -> int:
"""Return currently active position."""
...