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/coverlay.py
"""Produce laser-coverlay openings; merge windows leaving <0.5 mm PI webs."""
from pathlib import Path
import pcbnew as k
import json,math
root=Path(__file__).resolve().parents[1];path=root/'manufacturing/rev-b/flex/flex.kicad_pcb';b=k.LoadBoard(str(path))
held=[]
for s in list(b.GetDrawings()):
if s.GetLayer()==k.F_Adhes:b.Remove(s);held.append(s)
data=json.loads((root/'validation/flex-fabrication-finish.json').read_text());windows=data['coverlay_windows']
def distance(a,c):
return math.hypot(max(a[0]-c[2],c[0]-a[2],0),max(a[1]-c[3],c[1]-a[3],0))
again=True
while again:
again=False
for i,a in enumerate(windows):
for j in range(i+1,len(windows)):
c=windows[j]
if distance(a['rectangle_mm'],c['rectangle_mm'])<.5:
r,t=a['rectangle_mm'],c['rectangle_mm']
a['ref']+='+'+c['ref'];a['rectangle_mm']=[min(r[0],t[0]),min(r[1],t[1]),max(r[2],t[2]),max(r[3],t[3])]
windows.pop(j);again=True;break
if again:break
for fp in b.GetFootprints():
if fp.GetReference()=='J_TAIL' or fp.GetReference().startswith('TP'):
for p in fp.Pads():
q=p.GetBoundingBox();windows.append({'ref':fp.GetReference()+':'+p.GetNumber(),'rectangle_mm':[q.GetLeft()/1e6-.1,q.GetTop()/1e6-.1,q.GetRight()/1e6+.1,q.GetBottom()/1e6+.1]})
for w in windows:
x0,y0,x1,y1=w['rectangle_mm'];s=k.PCB_SHAPE(b);s.SetShape(k.SHAPE_T_RECT);s.SetLayer(k.F_Adhes)
s.SetStart(k.VECTOR2I(k.FromMM(x0),k.FromMM(y0)));s.SetEnd(k.VECTOR2I(k.FromMM(x1),k.FromMM(y1)));s.SetFilled(True);s.SetWidth(0);b.Add(s)
assert all(distance(a['rectangle_mm'],c['rectangle_mm'])>=.499 for i,a in enumerate(windows) for c in windows[i+1:]),'Coverlay web below 0.5 mm'
k.SaveBoard(str(path),b)
(root/'validation/flex-coverlay-windows.json').write_text(json.dumps({'minimum_web_mm':.5,'cad_artwork_layer':'F.Adhesive','gerber_role':'TOP COVERLAY OPENINGS, NOT ADHESIVE PASTE','windows':windows},indent=2)+'\n')
print(len(windows),'windows; all PI webs >=0.5 mm')