diff --git a/web/calibrate/Light9Calibrate.ts b/web/calibrate/Light9Calibrate.ts --- a/web/calibrate/Light9Calibrate.ts +++ b/web/calibrate/Light9Calibrate.ts @@ -4,15 +4,17 @@ import { customElement, query, state } f import { CollectorClient } from "../collector/CollectorClient"; import { getTopGraph } from "../RdfdbSyncedGraph"; import { SyncedGraph } from "../SyncedGraph"; +import { FindSafeExposure } from "./FindSafeExposure"; import { Light9Camera } from "./Light9Camera"; import { XyPlot } from "./XyPlot"; export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph"; export { Light9Camera } from "./Light9Camera"; export { XyPlot } from "./XyPlot"; + debug.enable("*"); const log = debug("calibrate"); -async function sleep(ms: number) { +export async function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } @@ -78,37 +80,8 @@ export class Light9Calibrate extends Lit async findSafeExposure(ev: MouseEvent) { await this.withButtonSpinner(ev, async () => { - - const gatherSample = async (expo: number) => { - await this.cam?.set("exposureTime", expo); - const settleUntil = Date.now() + 1000; - let miny = this.cam?.saturatedPixelCount!; - while (Date.now() < settleUntil) { - await sleep(50); - miny = Math.min(miny, this.cam?.saturatedPixelCount!); - } - this.plot!.insertPoint(expo, miny); - }; - - // todo: drive around without big skips, gradually slower, looking for the max workable expo - let fixedSteps = 8; - const expoMin = 1; - const expoMax = 200; - let expo = 0; - const data=this.plot!.data; - while (data.length < 20) { - if (data.length < fixedSteps + 1) { - expo = expoMin + ((expoMax - expoMin) / fixedSteps) * data.length; - } else { - let x2 = data.findIndex(([_, y]) => y > 2); - if (x2 < 1) x2 = 1; - const x1 = x2 - 1; - log(JSON.stringify([x1, data[x1], x2, data[x2]])); - expo = (data[x1][0] + data[x2][0]) / 2; - log(data); - } - await gatherSample(expo); - } + const algo = new FindSafeExposure(this.cam!, this.plot!); + await algo.run(); }); } async setToZero(ev: MouseEvent) {