# Utilities

Utility scripts for rpi-power-hat operations.

## Scripts

### `port-map.sh`
Maps HAT physical ports to USB topology and block devices.

```bash
# Show all port mappings (auto-detects Pi model)
./port-map.sh

# Show specific port mapping  
./port-map.sh 5 B1

# Get actual block device for port
./port-map.sh -d auto B1

# Explicit Pi model
./port-map.sh -d 4 B1
```

**Supported Models:** Pi 4, Pi 5 (auto-detected)  
**Ports:** B1, B2 (bottom), T1, T2 (top)

### `clean-data.sh`
Removes all measurement data, logs, and images.

```bash
# Interactive cleanup
./clean-data.sh

# Force cleanup (non-interactive)
./clean-data.sh --force
```

**Cleans:** `/var/lib/rpi-power-hat/`, `/var/log/rpi-power-hat/`, local data directories

## Usage in Scripts

```bash
# Get device for port B1
DEVICE=$(./utils/port-map.sh -d auto B1)

# Check if device exists
if [[ -e "$DEVICE" ]]; then
    echo "Port B1 device: $DEVICE"
fi
```

## Cross-Pi Compatibility

`port-map.sh` automatically detects Pi model and applies correct USB topology mappings:
- **Pi 5:** Uses dual xHCI controllers (Bus 1,3)  
- **Pi 4:** Uses VL805 controller (Bus 1 hub)
