# Extrusion firmware

Host-side scripts for driving the UFP stepper boards (syringe + CoreXY stage). Run them from this directory.

## Motor IDs

`mapping.json` maps each board's `MOTOR_ID` to its function and what it does. Every script reads it and prints
what the connected motors do on startup. Edit it if you rewire or reflash boards.

| ID | Function  | Action                |
|----|-----------|-----------------------|
| 1  | ID_A      | CoreXY stage motor A  |
| 2  | ID_B      | CoreXY stage motor B  |
| 3  | SYRINGE_1 | Syringe plunger 1     |
| 4  | SYRINGE_2 | Syringe plunger 2     |
| 5  | SYRINGE_3 | Syringe plunger 3     |

`xy_extrude_interactive.py` looks up its motors by function name (`ID_A`, `ID_B`, and the `SYRINGE_FUNCTION`
constant at the top of the file), so changing an ID here is all it takes to re-point it.

## Single device: `extrude.py`

Connects to one board by serial port and asks for a volume (cc) to deposit.

```
ls /dev/cu*                          # find the port, e.g. /dev/cu.usbmodem1101
python extrude.py /dev/cu.usbmodem1101
```

Without an argument it uses the `PORT` constant at the top of the file.

## Multiple devices, manual: `multi-device-manual.py`

Auto-discovers every connected board (by ID) and lets you turn any of them by hand.

```
python multi-device-manual.py
> 4, 2        # motor 4, 2 turns
> 2, -0.5     # motor 2, half a turn backwards
> q           # quit
```

The comma is optional (`4 2` works too), and spaces around it are fine. Invalid input (bad format, non-numeric values, motor not connected)
prints an error and asks again.

In all interactive scripts, pressing Enter on an empty prompt repeats the last valid command.

## Other scripts

- `xy_extrude_interactive.py` — type `x y cc` to move the stage and extrude at the same time.
- `multi-device.py` — demo that spins each connected motor forward and back in a loop.
- `utils.py` — `ExtrusionStepper`, `find_devices`, and the `mapping.json` helpers.
