mohan-bee/fitness-band
A 4-layer BLE wearable mainboard with Li-ion charging/protection, 3.3/1.8 V power regulation, motion and battery sensing, plus a folded 2-layer flex sensor board carrying MAX30102 optical and TMP117 temperature sensors.
- Version
- 0.0.2
- License
- unset
- Stars
- 0
scripts/merge-flex-vias.py
"""Join overlapping same-net vias with surface links, retaining one plated hole.
The 0.15 mm links fit inside the existing 0.45 mm copper union. Re-run native DRC.
"""
import pcbnew as k
from pathlib import Path
import json,math
root=Path(__file__).resolve().parents[1]
path=root/'manufacturing/rev-b/flex/flex.kicad_pcb';b=k.LoadBoard(str(path))
vias=[v for v in b.GetTracks() if v.GetClass()=='PCB_VIA'];removed=[];report=[]
for i,a in enumerate(vias):
if a in removed:continue
for c in vias[i+1:]:
if c in removed or a.GetNetCode()!=c.GetNetCode():continue
p,q=a.GetPosition(),c.GetPosition();d=math.hypot(p.x-q.x,p.y-q.y)/1e6
if 0.001<d<0.4:
for layer in (k.F_Cu,k.B_Cu):
t=k.PCB_TRACK(b);t.SetStart(p);t.SetEnd(q);t.SetWidth(k.FromMM(.15));t.SetLayer(layer);t.SetNetCode(a.GetNetCode());b.Add(t)
b.Remove(c);removed.append(c)
report.append({'net':a.GetNetname(),'center_distance_mm':d,'retained':[p.x/1e6,p.y/1e6],'removed':[q.x/1e6,q.y/1e6]})
k.SaveBoard(str(path),b)
(root/'validation/flex-via-normalization.json').write_text(json.dumps(report,indent=2)+'\n')
print('Merged',len(removed),'overlapping same-net via pairs')