LED Color

An LED analyzer's reading of a board's eight LEDs on the CIE 1931 chromaticity diagram: each LED's point drops into its bin, the ANSI 5700 K quadrangle for the white one.

STATIONCLI/PROCEDURELED Color

LED color

PASS00:14.47LED color (1/1)Passed

Run It

Every instrument is mocked, so the example runs without hardware.

bash
git clone https://github.com/tofupilot/panelscd panelstofupilot run led-color

The procedure

procedure.yaml
name: LED Colorversion: 1.0.0plugs:  - key: led_analyzer    name: LED analyzer    python: plugs.led_analyzer:LedAnalyzermain:  - key: leds    name: LED color    python: phases.led_color:measure_leds    measurements:      - key: red_x        name: D1 chromaticity x        unit: ""        validators:          - operator: ">="            expected_value: 0.685          - operator: "<="            expected_value: 0.705      - key: white_y        name: D8 chromaticity y        unit: ""        validators:          - operator: ">="            expected_value: 0.3243          - operator: "<="            expected_value: 0.3616    ui:      panel: panels/color.html

The panel

panels/color.html
<div class="inst"><svg viewBox="0 0 320 210" role="img"><rect x="1" y="1" width="318" height="208" rx="10" fill="#0d1014" stroke="#20262c" stroke-width="1.5"/><path d="M97.6 191.0L96.6 190.9L94.1 189.7L91.2 188.3L86.6 185.9L79.3 180.0L74.0 174.0L67.4 164.5L59.1 150.4L50.6 130.9L42.6 106.5L37.0 80.5L35.4 56.4L39.1 36.7L48.2 23.9L61.1 19.4L75.7 20.9L90.5 25.1L104.5 30.2L117.9 35.8L131.1 42.0L144.2 48.7L157.2 55.6L170.3 62.7L183.3 69.9L196.2 77.1L208.9 84.3L221.2 91.2L233.0 97.9L244.1 104.2L254.3 109.9L263.1 114.9L277.2 122.8L286.6 128.2L292.6 131.5L296.7 133.8L299.2 135.3L300.7 136.1L301.9 136.8L302.4 137.1Z" fill="#141a20" stroke="#c3ccd5" stroke-width=".9"/><path d="M34.0 192.0H308.0M34.0 192.0V16.0" stroke="#3a434c"/><text x="34.0" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.0</text><text x="70.5" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.1</text><text x="107.1" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.2</text><text x="143.6" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.3</text><text x="180.1" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.4</text><text x="216.7" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.5</text><text x="253.2" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.6</text><text x="289.7" y="202" text-anchor="middle" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.7</text><text x="30" y="153.1" text-anchor="end" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.2</text><text x="30" y="111.7" text-anchor="end" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.4</text><text x="30" y="70.3" text-anchor="end" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.6</text><text x="30" y="28.9" text-anchor="end" style="font: 500 6.5px ui-monospace, Menlo, monospace; fill: #59636d">0.8</text><path d="M86.6 185.9l-2.2 2.0" stroke="#7d8791"/><text x="79.9" y="193.9" text-anchor="middle" style="font: 500 7px ui-monospace, Menlo, monospace; fill: #7d8791">460</text><path d="M67.4 164.5l-2.7 1.3" stroke="#7d8791"/><text x="59.2" y="170.4" text-anchor="middle" style="font: 500 7px ui-monospace, Menlo, monospace; fill: #7d8791">480</text><path d="M61.1 19.4l-2.0 -2.2" stroke="#7d8791"/><text x="55.1" y="14.7" text-anchor="middle" style="font: 500 7px ui-monospace, Menlo, monospace; fill: #7d8791">520</text><path d="M117.9 35.8l-1.2 -2.8" stroke="#7d8791"/><text x="114.3" y="29.6" text-anchor="middle" style="font: 500 7px ui-monospace, Menlo, monospace; fill: #7d8791">540</text><path d="M170.3 62.7l0.7 -2.9" stroke="#7d8791"/><text x="172.4" y="55.9" text-anchor="middle" style="font: 500 7px ui-monospace, Menlo, monospace; fill: #7d8791">560</text><path d="M221.2 91.2l2.7 -1.3" stroke="#7d8791"/><text x="229.3" y="89.3" text-anchor="middle" style="font: 500 7px ui-monospace, Menlo, monospace; fill: #7d8791">580</text><path d="M263.1 114.9l3.0 -0.2" stroke="#7d8791"/><text x="272.0" y="116.2" text-anchor="middle" style="font: 500 7px ui-monospace, Menlo, monospace; fill: #7d8791">600</text><circle cx="287.9" cy="128.8" r="4.5" fill="none" stroke="#9aa8b6" stroke-dasharray="1.5 1.5"/><circle cx="96.1" cy="42.9" r="4.5" fill="none" stroke="#9aa8b6" stroke-dasharray="1.5 1.5"/><circle cx="81.8" cy="176.6" r="4.5" fill="none" stroke="#9aa8b6" stroke-dasharray="1.5 1.5"/><circle cx="242.2" cy="103.6" r="4.5" fill="none" stroke="#9aa8b6" stroke-dasharray="1.5 1.5"/><path d="M157.3 117.1L151.2 120.3L151.7 124.9L157.0 122.2Z" fill="none" stroke="#9aa8b6" stroke-width=".8"/><g class="pt" data-bind="ui.d1"><circle cx="287.9" cy="128.9" r="3.4" fill="#ff3b30" stroke="#0a0b0d" stroke-width=".9"/></g><g class="pt" data-bind="ui.d2"><circle cx="287.5" cy="128.7" r="3.4" fill="#ff3b30" stroke="#0a0b0d" stroke-width=".9"/></g><g class="pt" data-bind="ui.d3"><circle cx="95.7" cy="42.7" r="3.4" fill="#3bff6a" stroke="#0a0b0d" stroke-width=".9"/></g><g class="pt" data-bind="ui.d4"><circle cx="96.2" cy="43.1" r="3.4" fill="#3bff6a" stroke="#0a0b0d" stroke-width=".9"/></g><g class="pt" data-bind="ui.d5"><circle cx="81.7" cy="176.4" r="3.4" fill="#3b7bff" stroke="#0a0b0d" stroke-width=".9"/></g><g class="pt" data-bind="ui.d6"><circle cx="81.9" cy="176.9" r="3.4" fill="#3b7bff" stroke="#0a0b0d" stroke-width=".9"/></g><g class="pt" data-bind="ui.d7"><circle cx="242.3" cy="103.6" r="3.4" fill="#ffb02e" stroke="#0a0b0d" stroke-width=".9"/></g><g class="pt" data-bind="ui.d8"><circle cx="154.2" cy="121.2" r="3.4" fill="#f2f4f6" stroke="#0a0b0d" stroke-width=".9"/></g><g class="cx" data-bind="ui.cx"><g class="cy" data-bind="ui.cy"><circle r="6" fill="none" stroke="#f2f4f6" stroke-width="1"/></g></g></svg></div><style>  .inst { width: min(560px, 100%); margin: 0 auto; }  .inst svg { display: block; width: 100%; height: auto; }  .inst text { font-family: system-ui, sans-serif; }  .dp rect { fill: var(--off); }  .dp.on rect, .dp[data-value=true] rect { fill: var(--on); }  .led circle { fill: #2a2f35; transition: fill .15s; }  .led[data-value=true] circle { fill: var(--led, #38e07a); }  .ann text { fill: var(--off); transition: fill .15s; }  .ann[data-value=true] text { fill: var(--on); }  .d7 rect { fill: var(--off); transition: fill .08s; }  .d7[data-value="0"] :is(.sa, .sb, .sc, .sd, .se, .sf) { fill: var(--on); }  .d7[data-value="1"] :is(.sb, .sc) { fill: var(--on); }  .d7[data-value="2"] :is(.sa, .sb, .sd, .se, .sg) { fill: var(--on); }  .d7[data-value="3"] :is(.sa, .sb, .sc, .sd, .sg) { fill: var(--on); }  .d7[data-value="4"] :is(.sb, .sc, .sf, .sg) { fill: var(--on); }  .d7[data-value="5"] :is(.sa, .sc, .sd, .sf, .sg) { fill: var(--on); }  .d7[data-value="6"] :is(.sa, .sc, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="7"] :is(.sa, .sb, .sc) { fill: var(--on); }  .d7[data-value="8"] :is(.sa, .sb, .sc, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="9"] :is(.sa, .sb, .sc, .sd, .sf, .sg) { fill: var(--on); }  .d7[data-value="-"] :is(.sg) { fill: var(--on); }  .d7[data-value="E"] :is(.sa, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="U"] :is(.sb, .sc, .sd, .se, .sf) { fill: var(--on); }  .d7[data-value="r"] :is(.se, .sg) { fill: var(--on); }  .pt { opacity: 0; transform: translateY(-18px); transition: opacity .3s, transform .5s cubic-bezier(.2, .8, .3, 1); }  .pt[data-value=measured] { opacity: 1; transform: none; }  .cx { opacity: 0; transform: translateX(calc(var(--value, 0) * 1px)); transition: transform .3s ease-in-out, opacity .2s; }  .cx[data-value] { opacity: 1; }  .cy { transform: translateY(calc(var(--value, 0) * 1px)); transition: transform .3s ease-in-out; }</style>

The phase

phases/led_color.py
"""Reads the board's eight LEDs with the LED analyzer, one fiber at a time.`ui.cx` and `ui.cy` move the ring to where the LED's chromaticity falls onthe drawn CIE 1931 diagram, `ui.d1` to `ui.d8` drop each point into place.The run records the red D1's x and the white D8's y."""import time# The diagram's scale in panel units: x 0..0.75 over 274.0 px from 34, y 0..0.85 over 176 px up from 192.X0, SX, Y0, SY = 34, 365.3333, 192, 207.0588def measure_leds(ui, measurements, led_analyzer):    for index in range(8):        x, y, mcd = led_analyzer.measure(index)        ui.cx, ui.cy = round(X0 + x * SX, 1), round(Y0 - y * SY, 1)        time.sleep(0.4)        setattr(ui, f"d{index + 1}", "measured")        if index == 0:            measurements.red_x = x        if index == 7:            measurements.white_y = y        time.sleep(1.2)    time.sleep(1.5)

The mocked instrument

plugs/led_analyzer.py
"""Mock LED analyzer: a fiber over each of the board's eight LEDs, returningthe CIE 1931 chromaticity and the intensity of the one lit. Replace it withyour analyzer's driver."""LEDS = [    (0.6950, 0.3046, 182), (0.6938, 0.3058, 176), (0.1689, 0.7212, 410), (0.1702, 0.7189, 398),    (0.1305, 0.0752, 96), (0.1312, 0.0731, 101), (0.5701, 0.4269, 140), (0.3290, 0.3420, 1120),]class LedAnalyzer:    def measure(self, index):        """[x, y, intensity in mcd] of LED D1..D8 (index 0..7)."""        return list(LEDS[index])

Run your first test in minutes