improved logging

This commit is contained in:
Ayzen
2026-06-06 00:52:52 +03:00
parent af6005d68f
commit aea49f6128
65 changed files with 1206 additions and 240 deletions
+7
View File
@@ -3,8 +3,11 @@
from __future__ import annotations
from dataclasses import dataclass, field
import logging
from pathlib import Path
logger = logging.getLogger(__name__)
_PWM_CHANNEL_BY_PIN = {
12: 0,
@@ -53,12 +56,14 @@ class HardwarePwmGate:
self._pwm = HardwarePWM(pwm_channel=channel, hz=self.frequency_hz, chip=0)
except Exception as exc:
config_hint = _boot_config_hint()
logger.exception("Failed to initialize hardware PWM on GPIO%d (channel %d)", self.pin, channel)
raise RuntimeError(
"Failed to initialize Raspberry Pi hardware PWM. "
f"Enable the PWM overlay in {config_hint} by adding "
"'dtoverlay=pwm-2chan', then reboot the Raspberry Pi."
) from exc
self._running = False
logger.info("Hardware PWM opened on GPIO%d at %d Hz", self.pin, self.frequency_hz)
def enable(self) -> None:
"""Start PWM output when not already running."""
@@ -81,6 +86,8 @@ class HardwarePwmGate:
def close(self) -> None:
"""Stop PWM and release runtime state."""
self.disable()
if self._pwm is not None:
logger.info("Hardware PWM closed on GPIO%d", self.pin)
self._pwm = None