"""Makes the firmware folder importable (xy_stage_wrapper, single_stepper_wrapper, xy_geometry, ...).

The firmware folder is the single source of truth for everything that talks to the boards.
Default location: ../../firmware relative to this file; set PANCAKE_FIRMWARE_DIR to use another.
Importing this module is enough:  `import firmware_link  # noqa: F401`

Note: xy_geometry has no dependencies. The wrappers and simulators need the `ufp` library.
"""
import os
import sys
from pathlib import Path


def firmware_dir() -> Path:
    env = os.environ.get("PANCAKE_FIRMWARE_DIR")
    return Path(env) if env else Path(__file__).resolve().parents[2] / "firmware"


_dir = firmware_dir()
if not (_dir / "xy_stage_wrapper.py").is_file():
    raise ImportError(f"firmware folder not found at {_dir} (set PANCAKE_FIRMWARE_DIR)")
if str(_dir) not in sys.path:
    sys.path.append(str(_dir))
