fusion_hat.device モジュール

Fusion Hat デバイス関連の関数

サンプル

device モジュールをインポートします

>>> from fusion_hat import device

スピーカーを有効にします

>>> device.enable_speaker()
>>> device.get_speaker_state()
True

スピーカーを無効にします

>>> device.disable_speaker()
>>> device.get_speaker_state()
False

ユーザーボタンの状態を取得します

>>> device.get_usr_btn()
False

シャットダウン要求の状態を取得します

>>> device.get_shutdown_request()
0

ユーザー LED を切り替えます

>>> device.set_user_led(True)
>>> device.set_user_led(False)
>>> device.set_user_led(1)
>>> device.set_user_led(0)

ファームウェアのバージョンを取得します

>>> device.get_firmware_version()
'1.1.4'

音量を設定します

>>> device.set_volume(50)

バッテリー電圧を取得します

>>> device.get_battery_voltage()
8.4
fusion_hat.device.NAME = 'Fusion Hat'

ボード名

fusion_hat.device.ID = 'fusion_hat'

ボード ID

fusion_hat.device.UUID = '9daeea78-0000-0774-000a-582369ac3e02'

ボードの UUID

fusion_hat.device.PRODUCT_ID = 1908

ボードの製品 ID

fusion_hat.device.PRODUCT_VER = 10

ボードの製品バージョン

fusion_hat.device.VENDOR = 'SunFounder'

ボードのベンダー

fusion_hat.device.is_detected() bool[ソース]

Check if the driver sysfs interface exists (driver loaded).

戻り値:

True if /sys/class/fusion_hat/ exists

戻り値の型:

bool

fusion_hat.device.is_driver_loaded() bool[ソース]

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.

戻り値:

True if driver is loaded, False otherwise

戻り値の型:

bool

fusion_hat.device.doctor(fix_mode: bool = False) dict[ソース]

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

パラメータ:

fix_mode -- If True, summary messages adapt for --fix mode (don't suggest running --fix again).

戻り値:

overall, driver_ok, audio_ok, results (per-check dict)

戻り値の型:

dict with keys

fusion_hat.device.is_installed() bool[ソース]

Fusion Hat ボードがインストールされているかを確認します

バージョン Use で非推奨: is_detected() instead. This function will be removed in a future version.

戻り値:

インストールされている場合は True、そうでない場合は False

戻り値の型:

bool

fusion_hat.device.is_connected()[ソース]

Check if Fusion HAT is connected

バージョン Use で非推奨: is_driver_loaded() instead. This function will be removed in a future version.

戻り値:

True if connected

戻り値の型:

bool

fusion_hat.device.enable_speaker(*arg, **kwargs)[ソース]
fusion_hat.device.disable_speaker(*arg, **kwargs)[ソース]
fusion_hat.device.get_speaker_state(*arg, **kwargs)[ソース]
fusion_hat.device.get_usr_btn(*arg, **kwargs)[ソース]
fusion_hat.device.set_led(*arg, **kwargs)[ソース]
fusion_hat.device.get_firmware_version(*arg, **kwargs)[ソース]
fusion_hat.device.set_volume(value: int) None[ソース]

音量を設定します

パラメータ:

value (int) -- 音量(0~100)

fusion_hat.device._add_dtoverlay() bool[ソース]

Ensure dtoverlay=sunfounder-fusionhat is active in config.txt.

  • Already active → no-op

  • Commented out → uncomment

  • Not present → append

戻り値:

True if the line is active after the call

戻り値の型:

bool

fusion_hat.device._check_alsa_volume() tuple[ソース]

Check that ALSA speaker volume is not zero or muted.

fusion_hat.device._check_asound_conf() tuple[ソース]

Check that /etc/asound.conf routes to the Fusion Hat card.

fusion_hat.device._check_capture_device() tuple[ソース]

Check Fusion HAT mic via ALSA.

fusion_hat.device._check_i2s_clock() tuple[ソース]

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.

戻り値:

True if the clock started, False with a diagnostic

message otherwise.

戻り値の型:

(bool, str)

fusion_hat.device._check_pa_default_sink() tuple[ソース]

Check that PulseAudio default sink is the Fusion Hat card.

fusion_hat.device._check_sound_card() tuple[ソース]

Check Fusion HAT sound card (speaker) via ALSA.

fusion_hat.device._find_config_txt() str[ソース]

Locate the active Raspberry Pi config.txt file.

戻り値:

path to config.txt (may not exist)

戻り値の型:

str

fusion_hat.device._find_driver_src() str[ソース]

Find the Fusion Hat driver source directory.

fusion_hat.device._fix_i2s_stuck() bool[ソース]

Attempt to fix a stuck I2S peripheral.

Two-step fix for the "BCLK + LRCLK stuck HIGH / speaker hot" issue:

  1. 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.

  2. Trigger hw_params — Play a brief tone via play (sox) to force the ALSA hw_params call which configures the I2S registers correctly.

戻り値:

True if PCM clock enable count increased after the fix.

戻り値の型:

bool

fusion_hat.device._get_fusion_hat_pa_sink() str[ソース]

Find the PulseAudio sink name for the Fusion Hat sound card.

戻り値:

sink name like alsa_output.platform-soc_sound.stereo-fallback,

or empty string if not found.

戻り値の型:

str

fusion_hat.device._has_dtoverlay() bool[ソース]

Check if dtoverlay=sunfounder-fusionhat is already in config.txt.

戻り値:

True if the uncommented dtoverlay line exists

戻り値の型:

bool

fusion_hat.device._print_check(name: str, ok: bool, detail: str = '', indent: int = 2)[ソース]

Print a single check result inline, clearing previous spinner.

fusion_hat.device._print_fix_hint(fix_mode: bool = False)[ソース]

Print a hint to run --fix, or skip if already in fix mode.

fusion_hat.device._read_pcm_enable_count() int[ソース]

Read the current PCM clock enable count from debugfs.

戻り値:

enable count (first numeric column for 'pcm' row),

or -1 if the clock summary is not accessible.

戻り値の型:

int

fusion_hat.device._remove_dtoverlay() bool[ソース]

Remove dtoverlay=sunfounder-fusionhat from config.txt.

Uses sudo sed since the file requires root.

戻り値:

True if the line was removed or not present

戻り値の型:

bool

fusion_hat.device._set_pa_default_sink(sink_name: str) bool[ソース]

Set the PulseAudio default sink.

Runs as the first non-root user (typically 'pi') via sudo.