fusion_hat.device module
Fusion Hat device related functions
Example
Import device module
>>> from fusion_hat import device
Enable speaker
>>> device.enable_speaker()
>>> device.get_speaker_state()
True
Disable speaker
>>> device.disable_speaker()
>>> device.get_speaker_state()
False
Get user button state
>>> device.get_usr_btn()
False
Get shutdown request state
>>> device.get_shutdown_request()
0
Toggle user LED
>>> device.set_user_led(True)
>>> device.set_user_led(False)
>>> device.set_user_led(1)
>>> device.set_user_led(0)
Get firmware version
>>> device.get_firmware_version()
'1.1.4'
Set volume
>>> device.set_volume(50)
Get battery voltage
>>> device.get_battery_voltage()
8.4
- fusion_hat.device.NAME = 'Fusion Hat'
Name of the board
- fusion_hat.device.ID = 'fusion_hat'
ID of the board
- fusion_hat.device.UUID = '9daeea78-0000-0774-000a-582369ac3e02'
UUID of the board
- fusion_hat.device.PRODUCT_ID = 1908
Product ID of the board
- fusion_hat.device.PRODUCT_VER = 10
Product version of the board
- fusion_hat.device.VENDOR = 'SunFounder'
Vendor of the board
- fusion_hat.device.is_detected() bool[source]
Check if the driver sysfs interface exists (driver loaded).
- Returns:
True if /sys/class/fusion_hat/ exists
- Return type:
bool
- fusion_hat.device.is_driver_loaded() bool[source]
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.
- Returns:
True if driver is loaded, False otherwise
- Return type:
bool
- fusion_hat.device.doctor(fix_mode: bool = False) dict[source]
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
- Parameters:
fix_mode – If True, summary messages adapt for
--fixmode (don’t suggest running--fixagain).- Returns:
overall, driver_ok, audio_ok, results (per-check dict)
- Return type:
dict with keys
- fusion_hat.device.is_installed() bool[source]
Check if a Fusion Hat board is installed
Deprecated since version Use:
is_detected()instead. This function will be removed in a future version.- Returns:
True if installed, False otherwise
- Return type:
bool
- fusion_hat.device.is_connected()[source]
Check if Fusion HAT is connected
Deprecated since version Use:
is_driver_loaded()instead. This function will be removed in a future version.- Returns:
True if connected
- Return type:
bool
- fusion_hat.device.set_volume(value: int) None[source]
Set volume
- Parameters:
value (int) – volume(0~100)
- fusion_hat.device._add_dtoverlay() bool[source]
Ensure dtoverlay=sunfounder-fusionhat is active in config.txt.
Already active → no-op
Commented out → uncomment
Not present → append
- Returns:
True if the line is active after the call
- Return type:
bool
- fusion_hat.device._check_alsa_volume() tuple[source]
Check that ALSA speaker volume is not zero or muted.
- fusion_hat.device._check_asound_conf() tuple[source]
Check that /etc/asound.conf routes to the Fusion Hat card.
- fusion_hat.device._check_i2s_clock() tuple[source]
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.
- Returns:
- True if the clock started, False with a diagnostic
message otherwise.
- Return type:
(bool, str)
- fusion_hat.device._check_pa_default_sink() tuple[source]
Check that PulseAudio default sink is the Fusion Hat card.
- fusion_hat.device._check_sound_card() tuple[source]
Check Fusion HAT sound card (speaker) via ALSA.
- fusion_hat.device._find_config_txt() str[source]
Locate the active Raspberry Pi config.txt file.
- Returns:
path to config.txt (may not exist)
- Return type:
str
- fusion_hat.device._fix_i2s_stuck() bool[source]
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.
- Returns:
True if PCM clock enable count increased after the fix.
- Return type:
bool
- fusion_hat.device._get_fusion_hat_pa_sink() str[source]
Find the PulseAudio sink name for the Fusion Hat sound card.
- Returns:
- sink name like
alsa_output.platform-soc_sound.stereo-fallback, or empty string if not found.
- sink name like
- Return type:
str
- fusion_hat.device._has_dtoverlay() bool[source]
Check if dtoverlay=sunfounder-fusionhat is already in config.txt.
- Returns:
True if the uncommented dtoverlay line exists
- Return type:
bool
- fusion_hat.device._print_check(name: str, ok: bool, detail: str = '', indent: int = 2)[source]
Print a single check result inline, clearing previous spinner.
- fusion_hat.device._print_fix_hint(fix_mode: bool = False)[source]
Print a hint to run
--fix, or skip if already in fix mode.
- fusion_hat.device._read_pcm_enable_count() int[source]
Read the current PCM clock enable count from debugfs.
- Returns:
- enable count (first numeric column for ‘pcm’ row),
or -1 if the clock summary is not accessible.
- Return type:
int