Add rotation calibration and millimetre rulers on the calibration sheet
A new rotation setting turns the whole print about the sheet centre, in steps of 0.01 degree, on card sheets and the calibration sheet. The calibration sheet now has millimetre rulers at every card edge; the four lettered ones (A to D) are typed into Settings, which converts them into corrected offsets and rotation. A simulation test checks the conversion against modelled printer errors. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
5dfb50f1a8
commit
e23b6ee6c4
13 files changed
+410
-54
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useState } from 'preact/hooks';
|
||||
import { api } from '../api.ts';
|
||||
import { applyReadings } from '../../shared/calibration.ts';
|
||||
import { chooseCamera, useCamera } from '../camera.ts';
|
||||
import { showError, showToast } from '../toast-store.ts';
|
||||
import { Panel } from './Panel.tsx';
|
||||
@@ -8,12 +9,18 @@ export function Settings({ onClose }: { onClose: () => void }) {
|
||||
const cam = useCamera();
|
||||
const [x, setX] = useState('0');
|
||||
const [y, setY] = useState('0');
|
||||
const [rot, setRot] = useState('0');
|
||||
const [reads, setReads] = useState({ a: '', b: '', c: '', d: '' });
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
function show(s: { offsetXmm: number; offsetYmm: number; rotationDeg: number }) {
|
||||
setX(String(s.offsetXmm)); setY(String(s.offsetYmm)); setRot(String(s.rotationDeg));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
api.getSettings()
|
||||
.then(s => { setX(String(s.offsetXmm)); setY(String(s.offsetYmm)); setLoaded(true); })
|
||||
.then(s => { show(s); setLoaded(true); })
|
||||
.catch(e => showError(`Could not load the printer settings: ${(e as Error).message}`));
|
||||
}, []);
|
||||
|
||||
@@ -21,13 +28,31 @@ export function Settings({ onClose }: { onClose: () => void }) {
|
||||
ev.preventDefault();
|
||||
setBusy(true);
|
||||
try {
|
||||
const s = await api.putSettings({ offsetXmm: Number(x) || 0, offsetYmm: Number(y) || 0 });
|
||||
setX(String(s.offsetXmm)); setY(String(s.offsetYmm));
|
||||
show(await api.putSettings({ offsetXmm: Number(x) || 0, offsetYmm: Number(y) || 0, rotationDeg: Number(rot) || 0 }));
|
||||
showToast('Printer alignment saved');
|
||||
} catch (e) { showError(`Could not save the alignment: ${(e as Error).message}`); }
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
async function applyRuler() {
|
||||
setBusy(true);
|
||||
try {
|
||||
const n = (v: string) => Number(v) || 0;
|
||||
const current = await api.getSettings();
|
||||
const next = applyReadings(current, { a: n(reads.a), b: n(reads.b), c: n(reads.c), d: n(reads.d) });
|
||||
show(await api.putSettings(next));
|
||||
setReads({ a: '', b: '', c: '', d: '' });
|
||||
showToast('Readings applied; print the calibration page again to check');
|
||||
} catch (e) { showError(`Could not apply the readings: ${(e as Error).message}`); }
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
const reading = (k: 'a' | 'b' | 'c' | 'd') => (
|
||||
<label class="field">{k.toUpperCase()}
|
||||
<input type="number" step="0.25" value={reads[k]} onInput={e => setReads({ ...reads, [k]: e.currentTarget.value })} />
|
||||
</label>
|
||||
);
|
||||
|
||||
return (
|
||||
<Panel title="Settings" onClose={onClose}>
|
||||
<section class="settings-block" aria-labelledby="set-camera">
|
||||
@@ -52,12 +77,23 @@ export function Settings({ onClose }: { onClose: () => void }) {
|
||||
<label class="field">Offset Y (mm)
|
||||
<input type="number" step="0.25" min="-10" max="10" value={y} onInput={e => setY(e.currentTarget.value)} />
|
||||
</label>
|
||||
<label class="field">Rotation (degrees)
|
||||
<input type="number" step="0.01" min="-3" max="3" value={rot} onInput={e => setRot(e.currentTarget.value)} />
|
||||
</label>
|
||||
</div>
|
||||
<fieldset class="settings-block">
|
||||
<legend>Readings from the calibration sheet</legend>
|
||||
<div class="field-pair">{reading('a')}{reading('b')}</div>
|
||||
<div class="field-pair">{reading('c')}{reading('d')}</div>
|
||||
<div class="actions">
|
||||
<button type="button" class="btn" disabled={busy || !loaded} onClick={applyRuler}>Apply readings</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="actions">
|
||||
<button type="submit" class="btn" disabled={busy || !loaded}>Save</button>
|
||||
<a class="btn" href="/api/calibration.pdf" target="_blank" rel="noopener">Print calibration page</a>
|
||||
</div>
|
||||
<p class="help">Print the calibration page on plain paper, hold it over a real sheet up to a light, and enter how far the lines are off, up to 10 mm. Always print at 100% scale ("Actual size"), not "Fit to page"; the calibration page has a 6 inch line to check it. A positive Offset X moves everything toward the bottom of the cards (a negative one toward the top, where the call number is). A positive Offset Y moves everything toward the left of the cards, a negative one toward the right. The small marks around the cards on every printed sheet should point exactly at the perforations.</p>
|
||||
<p class="help">Print the calibration page and hold it over a real sheet up to a light. Read the numbers A to D off its rulers where the perforations cross them, enter them above and press Apply readings, then print it again to check. Positive rotation turns the print clockwise. Always print at 100% scale ("Actual size"), not "Fit to page"; the calibration page has a 6 inch line to check it. A positive Offset X moves everything toward the bottom of the cards (a negative one toward the top, where the call number is). A positive Offset Y moves everything toward the left of the cards, a negative one toward the right.</p>
|
||||
</form>
|
||||
</Panel>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user