annotate web/calibrate/Light9Calibrate.ts @ 2450:a4052905ca7d default tip

notes about how rdfdb syncs, or should sync
author drewp@bigasterisk.com
date Mon, 03 Jun 2024 23:01:54 -0700
parents 62dc1b3644a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
1 import debug from "debug";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
2 import { css, html, LitElement } from "lit";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
3 import { customElement, query, state } from "lit/decorators.js";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
4 import { CollectorClient } from "../collector/CollectorClient";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
5 import { getTopGraph } from "../RdfdbSyncedGraph";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
6 import { SyncedGraph } from "../SyncedGraph";
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
7 import { FindSafeExposure } from "./FindSafeExposure";
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
8 import { Light9Camera } from "./Light9Camera";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
9 import { XyPlot } from "./XyPlot";
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
10 import { NamedNode } from "n3";
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
11 import { showRoot } from "../show_specific";
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
12 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
13 export { Light9Camera } from "./Light9Camera";
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
14 export { XyPlot } from "./XyPlot";
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
15
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
16 debug.enable("*");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
17 const log = debug("calibrate");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
18
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
19 export async function sleep(ms: number) {
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
20 return new Promise((resolve) => setTimeout(resolve, ms));
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
21 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
22
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
23 @customElement("light9-calibrate")
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
24 export class Light9Calibrate extends LitElement {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
25 graph!: SyncedGraph;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
26 static styles = [
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
27 css`
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
28 button {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
29 min-height: 3em;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
30 min-width: 10em;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
31 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
32 `,
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
33 ];
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
34 collector: CollectorClient = new CollectorClient("calibrate");
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
35 @query("light9-camera", true) cam?: Light9Camera;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
36 @query("xy-plot", true) plot?: XyPlot;
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
37 @state() device?: NamedNode;
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
38 @state() calibrationSession?: NamedNode;
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
39 constructor() {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
40 super();
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
41 getTopGraph().then((g) => {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
42 this.graph = g;
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
43 const U = this.graph.U();
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
44 this.calibrationSession = U(showRoot + "/calibration/session1");
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
45 this.device = U("dev:parR3");
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
46 this.graph.patchObject(this.calibrationSession, U("rdf:type"), U(":CalibrationSession"), this.calibrationSession);
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
47 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
48 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
49
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
50 render() {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
51 return html`<rdfdb-synced-graph></rdfdb-synced-graph>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
52 <h1>Calibrate</h1>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
53 <light9-camera></light9-camera>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
54
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
55 <p>Calibration session; [ ${this.calibrationSession?.value} ]</p>
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
56 <p>Device to calibrate: [ ${this.device?.value} ]</p>
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
57
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
58 <ol>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
59 <li><button @click=${this.setToFull}>Set to full</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
60 <li><button @click=${this.findSafeExposure}>Find safe exposure</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
61 <li><button @click=${this.setToZero}>Set to 0</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
62 <li><button @click=${this.markTare}>Mark tare</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
63 <li><button @click=${this.calibrateLoop}>Calibrate loop</button></li>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
64 </ol>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
65 <xy-plot label="zebra pixels vs exposure"></xy-plot>
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
66 r/g/b/r*g*b lines ,x=send y=seen `;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
67 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
68
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
69 async withButtonSpinner(ev: MouseEvent, fn: () => Promise<void>) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
70 const btn = ev.target as HTMLButtonElement;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
71 try {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
72 btn.disabled = true;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
73 await fn();
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
74 } finally {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
75 btn.disabled = false;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
76 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
77 }
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
78
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
79 async setToFull(ev: MouseEvent) {
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
80 const U = this.graph.U();
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
81 await this.withButtonSpinner(ev, async () => {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
82 this.collector.updateSettings([
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
83 /// device,attr,value
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
84 [this.device!, U(":color"), this.graph.Literal("#ffffff")],
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
85 [this.device!, U(":white"), this.graph.LiteralRoundedFloat(1)],
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
86 ]);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
87 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
88 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
89
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
90 async findSafeExposure(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
91 await this.withButtonSpinner(ev, async () => {
2419
e3af0ac507c8 new exposure-finder algorithm
drewp@bigasterisk.com
parents: 2417
diff changeset
92 const algo = new FindSafeExposure(this.cam!, this.plot!);
2420
d5750b2aaa9e minor cam edits
drewp@bigasterisk.com
parents: 2419
diff changeset
93 const expo = await algo.run();
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
94 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
95 }
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
96
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
97 async setToZero(ev: MouseEvent) {
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
98 const U = this.graph.U();
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
99 await this.withButtonSpinner(ev, async () => {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
100 this.collector.updateSettings([
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
101 [this.device!, U(":color"), this.graph.Literal("#000000")],
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
102 [this.device!, U(":white"), this.graph.LiteralRoundedFloat(0)],
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
103 ]);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
104 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
105 }
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
106
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
107 async markTare(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
108 await this.withButtonSpinner(ev, async () => {});
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
109 }
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2420
diff changeset
110
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
111 async calibrateLoop(ev: MouseEvent) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
112 await this.withButtonSpinner(ev, async () => {});
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
113 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
114 }