Drogheda/scripts/2026-09-25_v6_T17_f2_input_fuse.py
2026-09-25 20:27:59 +00:00

67 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""v6 T17 — F2 (24 V vehicle input fuse) gets a real, orderable part.
F2 carried the placeholder "TBD-2A-1812" (value "2A/63V-slow-1812"). The JLC catalogue has
no 1812 fuse that is both 2 A time-lag and rated >= 63 V (1812 PPTCs top out at 33–36 V,
below what the SMBJ33A on /24V_IN lets through during a load dump).
First choice (T17, 25-Sep): Littelfuse 0454002.MR soldered NANO2 (C179005).
REVISED same day at Leo's request — a replaceable fuse in a socket:
Littelfuse 0154002.DR — OMNI-BLOK SMD fuse holder WITH a 2 A / 125 V NANO2 fuse fitted,
9.7 x 5 mm, LCSC C206910 (Extended, 5505 in stock). JLC places the block; in the field the
fuse pulls out of the block and a new NANO2 2 A pushes in — no soldering.
Schematic: Value, Footprint (Fuse:Fuseholder_Littelfuse_Nano2_154x, KiCad stock library) and LCSC.
Board: LCSC value + Value only. The footprint swap (1812 -> 154 holder, 9.7 x 5 mm) is a layout
step: in the PCB editor, right-click F2 -> Change Footprint -> Fuse:Fuseholder_Littelfuse_Nano2_154x.
python3 T17.py hbox-watchdog-v6.kicad_sch hbox-watchdog-v6.kicad_pcb [--apply]
"""
import re, sys, shutil
REF = 'F2'
NEW = {'Value': '2A/125V-NANO2-in-holder', 'LCSC': 'C206910',
'Footprint': 'Fuse:Fuseholder_Littelfuse_Nano2_154x'}
OLD_LCSC = ('TBD-2A-1812', 'C179005') # placeholder, then the first T17 choice
def span(s, i):
d = 0; instr = False; j = i
while True:
c = s[j]
if c == '"' and s[j-1] != '\\': instr = not instr
elif not instr:
if c == '(': d += 1
elif c == ')':
d -= 1
if d == 0: return j + 1
j += 1
def edit(s, head, props, ch, tag):
m = re.search(r'\n\t\t\(property "Reference" "%s"\n' % REF, s)
a = s.rfind('\n\t(' + head, 0, m.start()) + 1; e = span(s, a); b = s[a:e]
for k, v in props.items():
pm = re.search(r'\n\t\t\(property "%s" "([^"]*)"' % k, b)
if not pm: raise SystemExit(f'{tag}: {REF} has no {k} property')
if pm.group(1) == v: continue
if k == 'LCSC' and pm.group(1) not in OLD_LCSC + ('',): raise SystemExit(f'{tag}: unexpected LCSC {pm.group(1)}')
b = b[:pm.start()] + f'\n\t\t(property "{k}" "{v}"' + b[pm.end():]
ch.append(f'{tag} {REF}: {k} "{pm.group(1)}" -> "{v}"')
return s[:a] + b + s[e:]
def main():
sch, pcb = sys.argv[1], sys.argv[2]; apply = '--apply' in sys.argv
S0 = open(sch).read(); P0 = open(pcb).read(); ch = []
S = edit(S0, 'symbol', NEW, ch, 'sch')
P = edit(P0, 'footprint', {'Value': NEW['Value'], 'LCSC': NEW['LCSC']}, ch, 'pcb')
for t in (S, P):
u = re.sub(r'"(?:[^"\\]|\\.)*"', '', t); assert u.count('(') == u.count(')')
print('\n'.join(ch) or 'nothing to do (already applied)')
if ch and apply:
for f, t in ((sch, S), (pcb, P)):
shutil.copy2(f, f + '.T17bak'); open(f, 'w').write(t)
print('APPLIED (backups .T17bak)')
elif ch:
print('DRY RUN — re-run with --apply')
if __name__ == '__main__':
main()