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() 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 (with dependency deep-dive)

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.enable_speaker(*arg, **kwargs)[source]
fusion_hat.device.disable_speaker(*arg, **kwargs)[source]
fusion_hat.device.get_speaker_state(*arg, **kwargs)[source]
fusion_hat.device.get_usr_btn(*arg, **kwargs)[source]
fusion_hat.device.set_led(*arg, **kwargs)[source]
fusion_hat.device.get_firmware_version(*arg, **kwargs)[source]
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_capture_device() tuple[source]

Check Fusion HAT mic via ALSA.

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._find_driver_src() str[source]

Find the Fusion Hat driver source directory.

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._remove_dtoverlay() bool[source]

Remove dtoverlay=sunfounder-fusionhat from config.txt.

Uses sudo sed since the file requires root.

Returns:

True if the line was removed or not present

Return type:

bool