Files
scan-color-samples/measure.sh
2026-07-13 14:15:18 +03:30

76 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Measure reflective print samples with i1Pro 2 via ArgyllCMS spotread.
# Usage: ./measure.sh [M-condition]
# M-condition: D50 (default), M0, M1, or M2
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
MODE="${1:-D50}"
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
OUTPUT="scan_${MODE}_${TIMESTAMP}.tsv"
if ! command -v spotread >/dev/null 2>&1; then
echo "Error: spotread not found. Add ArgyllCMS bin to PATH." >&2
exit 1
fi
echo "Checking for i1Pro..."
# spotread -? exits 1 (usage), so capture output rather than piping under pipefail.
PORTS="$(spotread -? 2>&1 || true)"
if grep -q '\*\* No ports found \*\*' <<<"$PORTS"; then
echo "Error: No USB instrument detected." >&2
echo " 1. Connect the i1Pro 2 via USB" >&2
echo " 2. Run: sudo ./setup-udev.sh" >&2
echo " 3. Unplug and replug the device" >&2
exit 1
fi
SPOTREAD_ARGS=(-s "$OUTPUT")
case "$MODE" in
D50)
SPOTREAD_ARGS=(-i D50 "${SPOTREAD_ARGS[@]}")
;;
M0|M1|M2)
SPOTREAD_ARGS=(-I "$MODE" "${SPOTREAD_ARGS[@]}")
;;
*)
echo "Unknown mode: $MODE (use D50, M0, M1, or M2)" >&2
exit 1
;;
esac
SAMPLE_COUNT=0
if [[ -f samples.txt ]]; then
SAMPLE_COUNT="$(grep -cv '^#\|^$' samples.txt || true)"
fi
echo ""
echo "Output file: $OUTPUT"
echo "Mode: $MODE"
if [[ "$SAMPLE_COUNT" -gt 0 ]]; then
echo "Samples: $SAMPLE_COUNT expected (from samples.txt)"
fi
echo ""
echo "Workflow:"
echo " 1. Calibrate on the white tile when prompted"
echo " 2. Place i1Pro on each sample and press the button"
if [[ "$SAMPLE_COUNT" -gt 0 ]]; then
echo " 3. Take exactly $SAMPLE_COUNT readings, in samples.txt order"
echo " 4. Press Q to quit when all readings are done"
else
echo " 3. Press Q to quit when done"
fi
echo ""
echo "Starting spotread..."
echo ""
spotread "${SPOTREAD_ARGS[@]}"
echo ""
echo "Done. Convert to CSV with:"
echo " ./tsv-to-csv.py $OUTPUT"