"""Schematic for the 19 mm round XFM-5050-UV LED carrier, drawn with real wires."""
import os, sys, json
sys.path.insert(0, os.path.dirname(__file__))
import kgen
from kgen import Schematic

D = sys.argv[1]            # LEDBoard project dir
kgen.PROJ_LIBS['XFM5050UV'] = os.path.join(D, '..', 'lib', 'XFM5050UV.kicad_sym')

s = Schematic('XFM5050UV-LED', 'XFM-5050-UV LED Carrier', 'B', '2026-11-12', company='MBARI', paper='B',
              comments=('19 mm round board. Wires from stack board S2-Driver J2 (LED+) and J3 (LED-)',
                        'Prefer aluminium MCPCB; FR4 version relies on thermal vias under the LED'))
WIRE_PAD = 'TestPoint:TestPoint_Pad_3.0x3.0mm'

s.text('LED', 76.2, 60.96, 2.0)
s.place('XFM5050UV:XFM-5050-UV', 'D1', 'XFM-5050-UV-D130-GB270-00', 101.6, 76.2,
        {'1': 'LED_A', '2': 'LED_K', '3': 'THERMAL'}, fp='XFM5050UV:XFM-5050-UV',
        props={'Datasheet': 'https://download.luminus.com/datasheets/Luminus_XFM-5050-UV_Datasheet.pdf'},
        ref_at=(96.52, 69.85), val_at=(96.52, 67.31))
# J1 LED+ pad on the left (pin facing right), J3 LED- pad on the right
s.place('Connector_Generic:Conn_01x01', 'J1', 'LED+ wire', 76.2, 76.2, {'1': 'LED_A'}, rot=180, fp=WIRE_PAD,
        ref_at=(68.58, 74.93), val_at=(68.58, 72.39))
s.place('Connector_Generic:Conn_01x01', 'J3', 'LED- wire', 127.0, 76.2, {'1': 'LED_K'}, fp=WIRE_PAD,
        ref_at=(129.54, 74.93), val_at=(129.54, 72.39))
s.wire(s.P('J1', 1), s.P('D1', 1))
s.label('LED_A', 86.36, 76.2, 'up')
s.wire(s.P('D1', 2), s.P('J3', 1))
s.label('LED_K', 115.57, 76.2, 'up')
# centre pad: THERMAL net (copper pours only)
s.wire(s.P('D1', 3), (101.6, 88.9), (106.68, 88.9))
s.label('THERMAL', 101.6, 86.36, 'left')
s.pflag('THERMAL', 106.68, 88.9)

s.text('THERMISTOR', 142.24, 60.96, 2.0)
s.place('Device:Thermistor_NTC', 'RT1', '10k NTCS0603E3103', 152.4, 76.2, {'1': 'NTC_1', '2': 'NTC_2'},
        fp='Resistor_SMD:R_0603_1608Metric', ref_at=(147.32, 86.36), val_at=(147.32, 88.9))
s.place('Connector_Generic:Conn_01x02', 'J2', 'Thermistor BM02B-SRSS-TB', 177.8, 76.2,
        {'1': 'NTC_1', '2': 'NTC_2'}, fp='Connector_JST:JST_SH_BM02B-SRSS-TB_1x02-1MP_P1.00mm_Vertical',
        ref_at=(180.34, 73.66), val_at=(180.34, 81.28))
s.wire(s.P('RT1', 1), (160.02, 72.39), (160.02, 76.2), s.P('J2', 1))
s.label('NTC_1', 160.02, 72.39, 'right')
s.wire(s.P('RT1', 2), (162.56, 80.01), (162.56, 78.74), s.P('J2', 2))
s.label('NTC_2', 156.21, 80.01, 'down')

s.text('D1: 275 nm UV-C LED. Its centre pad is\nthermal only (tied to the copper pours).', 96.52, 93.98, italic=True)
s.text('J1/J3: wire pads for the\nLED cable from S2.', 63.5, 88.9, italic=True)
s.text("RT1: NTC thermistor next to the LED;\nJ2 carries it to the controller's THERM input.", 142.24, 93.98, italic=True)
s.text('''NOTES
Board: 19 mm diameter round, no mounting holes (bond to heatsink with
  thermal adhesive, or clamp it).
J1/J3: SMD wire pads for ~20 AWG (0.5 mm2) wire to stack board S2-Driver
  J2 (LED+ / anode, VLED_UV) and J3 (LED- / cathode, LED_K). 2 A continuous.
D1 centre pad (TH) is tied to the copper pours for heat spreading only;
  it is not connected to anode or cathode.
Driver limits: 2 A typ, 3.2 A abs max; keep Tj < 95 C (Rth j-sp 1.8 C/W).
RT1 sits next to D1 and runs to the controller board's THERM input via
  J2 (JST-SH 1.0 mm, mates with SHR-02V-S).
UV-C (275 nm) is hazardous to eyes and skin; do not view while energised.''', 38.1, 106.68)
s.write(os.path.join(D, 'XFM5050UV-LED.kicad_sch'))
json.dump({f'{r}|{p}': n for (r, p), n in s.intended.items()}, open(os.path.join(os.path.dirname(__file__), 'led_intended.json'), 'w'))
print('ok', len(s.intended), 'pins')
