Modul fusion_hat.device
Gerätebezogene Funktionen des Fusion Hat
Beispiel
Gerätemodul importieren
>>> from fusion_hat import device
Lautsprecher aktivieren
>>> device.enable_speaker()
>>> device.get_speaker_state()
True
Lautsprecher deaktivieren
>>> device.disable_speaker()
>>> device.get_speaker_state()
False
Status der Benutzertaste abrufen
>>> device.get_usr_btn()
False
Status der Herunterfahranforderung abrufen
>>> device.get_shutdown_request()
0
Benutzer-LED umschalten
>>> device.set_user_led(True)
>>> device.set_user_led(False)
>>> device.set_user_led(1)
>>> device.set_user_led(0)
Firmware-Version abrufen
>>> device.get_firmware_version()
'1.1.4'
Lautstärke einstellen
>>> device.set_volume(50)
Batteriespannung abrufen
>>> device.get_battery_voltage()
8.4
- fusion_hat.device.NAME = 'Fusion Hat'
Name der Platine
- fusion_hat.device.ID = 'fusion_hat'
ID der Platine
- fusion_hat.device.UUID = '9daeea78-0000-0774-000a-582369ac3e02'
UUID der Platine
- fusion_hat.device.PRODUCT_ID = 1908
Produkt-ID der Platine
- fusion_hat.device.PRODUCT_VER = 10
Produktversion der Platine
- fusion_hat.device.VENDOR = 'SunFounder'
Hersteller der Platine
- fusion_hat.device.is_detected() bool[Quellcode]
Check if the driver sysfs interface exists (driver loaded).
- Rückgabe:
True if /sys/class/fusion_hat/ exists
- Rückgabetyp:
bool
- fusion_hat.device.is_driver_loaded() bool[Quellcode]
Check if Fusion Hat driver is loaded
This function checks if the Fusion Hat driver module is loaded by verifying the existence of /sys/class/fusion_hat/ directory.
- Rückgabe:
True if driver is loaded, False otherwise
- Rückgabetyp:
bool
- fusion_hat.device.doctor(fix_mode: bool = False) dict[Quellcode]
Live hardware health check — prints results as each check runs.
- Sections:
Driver — sysfs, module, I2C MCU, dtoverlay, module file Audio — sound card, capture device, I2S clock health
- Parameter:
fix_mode – If True, summary messages adapt for
--fixmode (don’t suggest running--fixagain).- Rückgabe:
overall, driver_ok, audio_ok, results (per-check dict)
- Rückgabetyp:
dict with keys
- fusion_hat.device.is_installed() bool[Quellcode]
Prüfen, ob eine Fusion-Hat-Platine installiert ist
Veraltet ab Version Use:
is_detected()instead. This function will be removed in a future version.- Rückgabe:
True, wenn installiert, sonst False
- Rückgabetyp:
bool
- fusion_hat.device.is_connected()[Quellcode]
Check if Fusion HAT is connected
Veraltet ab Version Use:
is_driver_loaded()instead. This function will be removed in a future version.- Rückgabe:
True if connected
- Rückgabetyp:
bool
- fusion_hat.device.enable_speaker(*arg, **kwargs)[Quellcode]
- fusion_hat.device.disable_speaker(*arg, **kwargs)[Quellcode]
- fusion_hat.device.get_speaker_state(*arg, **kwargs)[Quellcode]
- fusion_hat.device.get_usr_btn(*arg, **kwargs)[Quellcode]
- fusion_hat.device.set_led(*arg, **kwargs)[Quellcode]
- fusion_hat.device.get_firmware_version(*arg, **kwargs)[Quellcode]
- fusion_hat.device.set_volume(value: int) None[Quellcode]
Lautstärke einstellen
- Parameter:
value (int) – Lautstärke (0~100)
- fusion_hat.device._add_dtoverlay() bool[Quellcode]
Ensure dtoverlay=sunfounder-fusionhat is active in config.txt.
Already active → no-op
Commented out → uncomment
Not present → append
- Rückgabe:
True if the line is active after the call
- Rückgabetyp:
bool
- fusion_hat.device._check_alsa_volume() tuple[Quellcode]
Check that ALSA speaker volume is not zero or muted.
- fusion_hat.device._check_asound_conf() tuple[Quellcode]
Check that /etc/asound.conf routes to the Fusion Hat card.
- fusion_hat.device._check_capture_device() tuple[Quellcode]
Check Fusion HAT mic via ALSA.
- fusion_hat.device._check_i2s_clock() tuple[Quellcode]
Check if the I2S PCM clock actually starts during playback.
Plays a brief silent tone via ALSA and verifies that the PCM clock’s enable count increases. A stuck count (especially 0 both before and during playback) means the I2S peripheral is not responding.
- Rückgabe:
- True if the clock started, False with a diagnostic
message otherwise.
- Rückgabetyp:
(bool, str)
- fusion_hat.device._check_pa_default_sink() tuple[Quellcode]
Check that PulseAudio default sink is the Fusion Hat card.
- fusion_hat.device._check_sound_card() tuple[Quellcode]
Check Fusion HAT sound card (speaker) via ALSA.
- fusion_hat.device._find_config_txt() str[Quellcode]
Locate the active Raspberry Pi config.txt file.
- Rückgabe:
path to config.txt (may not exist)
- Rückgabetyp:
str
- fusion_hat.device._find_driver_src() str[Quellcode]
Find the Fusion Hat driver source directory.
- fusion_hat.device._fix_i2s_stuck() bool[Quellcode]
Attempt to fix a stuck I2S peripheral.
Two-step fix for the „BCLK + LRCLK stuck HIGH / speaker hot“ issue:
PulseAudio routing — Ensure the default sink is the Fusion Hat card, not the built-in headphone jack. When Pipewire/PulseAudio routes audio to the wrong card, the I2S clock never starts.
Trigger hw_params — Play a brief tone via
play(sox) to force the ALSAhw_paramscall which configures the I2S registers correctly.
- Rückgabe:
True if PCM clock enable count increased after the fix.
- Rückgabetyp:
bool
- fusion_hat.device._get_fusion_hat_pa_sink() str[Quellcode]
Find the PulseAudio sink name for the Fusion Hat sound card.
- Rückgabe:
- sink name like
alsa_output.platform-soc_sound.stereo-fallback, or empty string if not found.
- sink name like
- Rückgabetyp:
str
- fusion_hat.device._has_dtoverlay() bool[Quellcode]
Check if dtoverlay=sunfounder-fusionhat is already in config.txt.
- Rückgabe:
True if the uncommented dtoverlay line exists
- Rückgabetyp:
bool
- fusion_hat.device._print_check(name: str, ok: bool, detail: str = '', indent: int = 2)[Quellcode]
Print a single check result inline, clearing previous spinner.
- fusion_hat.device._print_fix_hint(fix_mode: bool = False)[Quellcode]
Print a hint to run
--fix, or skip if already in fix mode.
- fusion_hat.device._read_pcm_enable_count() int[Quellcode]
Read the current PCM clock enable count from debugfs.
- Rückgabe:
- enable count (first numeric column for ‚pcm‘ row),
or -1 if the clock summary is not accessible.
- Rückgabetyp:
int
- fusion_hat.device._remove_dtoverlay() bool[Quellcode]
Remove dtoverlay=sunfounder-fusionhat from config.txt.
Uses sudo sed since the file requires root.
- Rückgabe:
True if the line was removed or not present
- Rückgabetyp:
bool
- fusion_hat.device._set_pa_default_sink(sink_name: str) bool[Quellcode]
Set the PulseAudio default sink.
Runs as the first non-root user (typically ‚pi‘) via sudo.