2417
|
1 import debug from "debug";
|
|
2 import { css, html, LitElement } from "lit";
|
|
3 import { customElement, query, state } from "lit/decorators.js";
|
|
4 import { CollectorClient } from "../collector/CollectorClient";
|
|
5 import { getTopGraph } from "../RdfdbSyncedGraph";
|
|
6 import { SyncedGraph } from "../SyncedGraph";
|
2419
|
7 import { FindSafeExposure } from "./FindSafeExposure";
|
2417
|
8 import { Light9Camera } from "./Light9Camera";
|
|
9 import { XyPlot } from "./XyPlot";
|
|
10 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph";
|
|
11 export { Light9Camera } from "./Light9Camera";
|
|
12 export { XyPlot } from "./XyPlot";
|
2419
|
13
|
2417
|
14 debug.enable("*");
|
|
15 const log = debug("calibrate");
|
|
16
|
2419
|
17 export async function sleep(ms: number) {
|
2417
|
18 return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19 }
|
|
20
|
|
21 @customElement("light9-calibrate")
|
|
22 export class Light9Calibrate extends LitElement {
|
|
23 graph!: SyncedGraph;
|
|
24 static styles = [
|
|
25 css`
|
|
26 button {
|
|
27 min-height: 3em;
|
|
28 min-width: 10em;
|
|
29 }
|
|
30 `,
|
|
31 ];
|
|
32 collector: CollectorClient = new CollectorClient("calibrate");
|
|
33 @query("light9-camera", true) cam?: Light9Camera;
|
|
34 @query("xy-plot", true) plot?: XyPlot;
|
|
35 @state() device: string;
|
|
36 constructor() {
|
|
37 super();
|
|
38 this.device = "http://light9.bigasterisk.com/theater/vet/device/parR3";
|
|
39 getTopGraph().then((g) => {
|
|
40 this.graph = g;
|
|
41 });
|
|
42 }
|
|
43
|
|
44 render() {
|
|
45 return html`<rdfdb-synced-graph></rdfdb-synced-graph>
|
|
46 <h1>Calibrate</h1>
|
|
47 <light9-camera></light9-camera>
|
|
48
|
|
49 <p>Device to calibrate: [ ${this.device} ]</p>
|
|
50
|
|
51 <ol>
|
|
52 <li><button @click=${this.setToFull}>Set to full</button></li>
|
|
53 <li><button @click=${this.findSafeExposure}>Find safe exposure</button></li>
|
|
54 <li><button @click=${this.setToZero}>Set to 0</button></li>
|
|
55 <li><button @click=${this.markTare}>Mark tare</button></li>
|
|
56 <li><button @click=${this.calibrateLoop}>Calibrate loop</button></li>
|
|
57 </ol>
|
|
58 <xy-plot label="zebra pixels vs exposure"></xy-plot>
|
|
59 r/g/b/r*g*b lines ,x=send y=seen `;
|
|
60 }
|
|
61
|
|
62 async withButtonSpinner(ev: MouseEvent, fn: () => Promise<void>) {
|
|
63 const btn = ev.target as HTMLButtonElement;
|
|
64 try {
|
|
65 btn.disabled = true;
|
|
66 await fn();
|
|
67 } finally {
|
|
68 btn.disabled = false;
|
|
69 }
|
|
70 }
|
|
71 async setToFull(ev: MouseEvent) {
|
|
72 await this.withButtonSpinner(ev, async () => {
|
|
73 this.collector.updateSettings([
|
|
74 /// device,attr,value
|
|
75 [this.device, "http://light9.bigasterisk.com/color", "#ffffff"],
|
|
76 [this.device, "http://light9.bigasterisk.com/white", 1],
|
|
77 ]);
|
|
78 });
|
|
79 }
|
|
80
|
|
81 async findSafeExposure(ev: MouseEvent) {
|
|
82 await this.withButtonSpinner(ev, async () => {
|
2419
|
83 const algo = new FindSafeExposure(this.cam!, this.plot!);
|
2420
|
84 const expo = await algo.run();
|
2417
|
85 });
|
|
86 }
|
|
87 async setToZero(ev: MouseEvent) {
|
|
88 await this.withButtonSpinner(ev, async () => {
|
|
89 this.collector.updateSettings([
|
|
90 [this.device, "http://light9.bigasterisk.com/color", "#000000"],
|
|
91 [this.device, "http://light9.bigasterisk.com/white", 0],
|
|
92 ]);
|
|
93 });
|
|
94 }
|
|
95 async markTare(ev: MouseEvent) {
|
|
96 await this.withButtonSpinner(ev, async () => {});
|
|
97 }
|
|
98 async calibrateLoop(ev: MouseEvent) {
|
|
99 await this.withButtonSpinner(ev, async () => {});
|
|
100 }
|
|
101 }
|