feat: load i2c-dev kernel module on startup (#14)
Ensure i2c-dev kernel module is loaded before initializing I2C communication to guarantee /dev/i2c-* device access. Add error handling and logging for module loading process. Reviewed-on: https://gitea.pstruebi.xyz/auracaster/bumble-auracast/pulls/14
This commit was merged in pull request #14.
This commit is contained in:
@@ -146,6 +146,25 @@ _stream_lock = asyncio.Lock() # serialize initialize/stop_audio on API side
|
|||||||
|
|
||||||
|
|
||||||
async def _init_i2c_on_startup() -> None:
|
async def _init_i2c_on_startup() -> None:
|
||||||
|
# Ensure i2c-dev kernel module is loaded (required for /dev/i2c-* access)
|
||||||
|
try:
|
||||||
|
proc = await asyncio.create_subprocess_exec(
|
||||||
|
"sudo", "modprobe", "i2c-dev",
|
||||||
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
stderr=asyncio.subprocess.PIPE,
|
||||||
|
)
|
||||||
|
stdout, stderr = await proc.communicate()
|
||||||
|
if proc.returncode != 0:
|
||||||
|
log.warning(
|
||||||
|
"modprobe i2c-dev failed (rc=%s): %s",
|
||||||
|
proc.returncode,
|
||||||
|
(stderr or b"").decode(errors="ignore").strip(),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
log.info("i2c-dev module loaded successfully")
|
||||||
|
except Exception as e:
|
||||||
|
log.warning("Exception running modprobe i2c-dev: %s", e, exc_info=True)
|
||||||
|
|
||||||
# Table of (register, expected_value)
|
# Table of (register, expected_value)
|
||||||
dev_add = "0x4a"
|
dev_add = "0x4a"
|
||||||
reg_table = [
|
reg_table = [
|
||||||
|
|||||||
Reference in New Issue
Block a user