Mercurial > code > home > repos > light9
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 |
rev | line source |
---|---|
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"; | |
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 | 12 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph"; |
13 export { Light9Camera } from "./Light9Camera"; | |
14 export { XyPlot } from "./XyPlot"; | |
2419 | 15 |
2417 | 16 debug.enable("*"); |
17 const log = debug("calibrate"); | |
18 | |
2419 | 19 export async function sleep(ms: number) { |
2417 | 20 return new Promise((resolve) => setTimeout(resolve, ms)); |
21 } | |
22 | |
23 @customElement("light9-calibrate") | |
24 export class Light9Calibrate extends LitElement { | |
25 graph!: SyncedGraph; | |
26 static styles = [ | |
27 css` | |
28 button { | |
29 min-height: 3em; | |
30 min-width: 10em; | |
31 } | |
32 `, | |
33 ]; | |
34 collector: CollectorClient = new CollectorClient("calibrate"); | |
35 @query("light9-camera", true) cam?: Light9Camera; | |
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 | 39 constructor() { |
40 super(); | |
41 getTopGraph().then((g) => { | |
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 | 47 }); |
48 } | |
49 | |
50 render() { | |
51 return html`<rdfdb-synced-graph></rdfdb-synced-graph> | |
52 <h1>Calibrate</h1> | |
53 <light9-camera></light9-camera> | |
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 | 57 |
58 <ol> | |
59 <li><button @click=${this.setToFull}>Set to full</button></li> | |
60 <li><button @click=${this.findSafeExposure}>Find safe exposure</button></li> | |
61 <li><button @click=${this.setToZero}>Set to 0</button></li> | |
62 <li><button @click=${this.markTare}>Mark tare</button></li> | |
63 <li><button @click=${this.calibrateLoop}>Calibrate loop</button></li> | |
64 </ol> | |
65 <xy-plot label="zebra pixels vs exposure"></xy-plot> | |
66 r/g/b/r*g*b lines ,x=send y=seen `; | |
67 } | |
68 | |
69 async withButtonSpinner(ev: MouseEvent, fn: () => Promise<void>) { | |
70 const btn = ev.target as HTMLButtonElement; | |
71 try { | |
72 btn.disabled = true; | |
73 await fn(); | |
74 } finally { | |
75 btn.disabled = false; | |
76 } | |
77 } | |
2422
62dc1b3644a0
collector client uses rdf types, not strings
drewp@bigasterisk.com
parents:
2420
diff
changeset
|
78 |
2417 | 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 | 81 await this.withButtonSpinner(ev, async () => { |
82 this.collector.updateSettings([ | |
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 | 86 ]); |
87 }); | |
88 } | |
89 | |
90 async findSafeExposure(ev: MouseEvent) { | |
91 await this.withButtonSpinner(ev, async () => { | |
2419 | 92 const algo = new FindSafeExposure(this.cam!, this.plot!); |
2420 | 93 const expo = await algo.run(); |
2417 | 94 }); |
95 } | |
2422
62dc1b3644a0
collector client uses rdf types, not strings
drewp@bigasterisk.com
parents:
2420
diff
changeset
|
96 |
2417 | 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 | 99 await this.withButtonSpinner(ev, async () => { |
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 | 103 ]); |
104 }); | |
105 } | |
2422
62dc1b3644a0
collector client uses rdf types, not strings
drewp@bigasterisk.com
parents:
2420
diff
changeset
|
106 |
2417 | 107 async markTare(ev: MouseEvent) { |
108 await this.withButtonSpinner(ev, async () => {}); | |
109 } | |
2422
62dc1b3644a0
collector client uses rdf types, not strings
drewp@bigasterisk.com
parents:
2420
diff
changeset
|
110 |
2417 | 111 async calibrateLoop(ev: MouseEvent) { |
112 await this.withButtonSpinner(ev, async () => {}); | |
113 } | |
114 } |