imrishabh18/fitness_watch

This circuit integrates an ESP-12E microcontroller with various sensors, relays, and power management components, including an AO3400A transistor for switching loads, to enable wireless control and sensing functions.

Version
1.0.11
License
unset
Stars
0

scripts/audit-assembly.mjs

import assert from 'node:assert/strict'
import { readFileSync, writeFileSync } from 'node:fs'
const circuit = JSON.parse(readFileSync('dist/index/circuit.json', 'utf8'))
const components = circuit.filter(e => e.type === 'source_component')
const byName = new Map(components.map(e => [e.name, e]))
const port = (name, pin) => circuit.find(e => e.type === 'source_port' && e.source_component_id === byName.get(name)?.source_component_id && Number(e.pin_number) === pin)
const key = e => e?.subcircuit_connectivity_map_key
let count = 0
function connected(a,b) {
  assert.ok(key(port(...a)), `Missing connected port ${a}`)
  assert.equal(key(port(...a)),key(port(...b)),`${a} must connect to ${b}`)
  count++
}
for (const [a,b] of [
  [['U2',20],['U4',23]], [['U2',19],['U4',24]],
  [['U2',20],['U5',2]], [['U2',19],['U5',3]],
  [['U2',20],['DS1',3]], [['U2',19],['DS1',4]],
  [['U2',20],['R15',1]], [['U2',19],['R16',1]],
  [['U5',13],['U2',6]], [['U5',13],['R17',1]], [['U4',12],['U2',7]],
  [['U4',10],['C8',1]], [['U4',20],['C10',1]],
  [['U2',5],['R9',1]], [['R9',2],['Q1',1]], [['Q1',1],['R13',1]],
  [['M1',1],['Q1',3]], [['M1',1],['D2',2]], [['M1',2],['D2',1]],
  [['U2',18],['R14',1]], [['U2',18],['SW_NAV',1]], [['U2',1],['SW_RST',1]],
  [['J2',2],['U2',22]], [['J2',3],['U2',21]], [['J1',1],['U1',1]], [['J1',1],['U1',3]], [['J1',1],['C3',1]],
]) connected(a,b)
for(const pin of [['U2',8],['U4',8],['U4',13],['U5',9],['U5',10],['U6',1],['U6',3],['DS1',2],['M1',2],['R14',2],['R15',2],['R16',2],['R17',2],['C9',1],['C11',1],['C12',1],['C13',1],['C14',1]]) connected(pin,['U1',5])
for(const pin of [['U5',11],['C15',1],['C16',1]]) connected(pin,['U6',5])
for(const pin of [['U2',15],['U4',1],['U4',9],['U4',11],['U4',18],['U5',4],['U5',12],['U6',2],['DS1',1],['J1',2],['Q1',2],['R13',2],...Array.from({length:9},(_,i)=>[`C${i+8}`,2])]) connected(pin,['U1',2])
assert.notEqual(key(port('U5',11)),key(port('U1',5)),'MAX30102 VDD must be separate from 3.3 V')
assert.notEqual(key(port('U5',11)),key(port('U1',2)),'1.8 V shorted to ground')
for(const [name,code] of [['U4','C24112'],['U5','C6454833'],['U6','C79924'],['M1','C2759984'],['DS1','C5248081'],['C10','C1604'],['C11','C57112'],['C15','C19666']])
  assert.ok(byName.get(name)?.supplier_part_numbers?.jlcpcb?.includes(code),`${name} wrong supplier part`)
for(const name of ['J4','R7','R8','C5']) assert.ok(!byName.has(name),`${name}: obsolete analog sensor circuitry`)
for(const name of ['J3','U3','R1','R2','D1','C1','C2','R10','R11','Q2','D3','R12']) assert.ok(!byName.has(name), `${name}: charging circuitry must be removed`)
assert.notEqual(key(port('J1',1)),key(port('U1',5)),'Battery must not bypass the regulator')
assert.equal(circuit.find(x=>x.type==='pcb_component' && x.source_component_id===byName.get('M1').source_component_id).layer,'top')
assert.ok(!port('U4',25),'MPU6050 die pad must not have a solder land')
for(const name of ['U4','U5','U6','M1','DS1']) {
  const pcb=circuit.find(e=>e.type==='pcb_component' && e.source_component_id===byName.get(name).source_component_id)
  assert.equal(pcb.do_not_place,false,`${name} must be populated`)
}
const errors=circuit.filter(e=>e.type.endsWith('_error'))
const result={electricalConnectionAssertionsPassed:count,pcbComponents:components.length,
  pcbErrorCount:errors.length,pcbErrorTypes:[...new Set(errors.map(e=>e.type))],
  fabricationReleaseStatus:errors.length ? 'HOLD_FOR_ROUTING_MECHANICAL_FIRMWARE_AND_POWER_VALIDATION' : 'HOLD_FOR_MECHANICAL_FIRMWARE_AND_POWER_VALIDATION',
  note:'Logical connectivity and selected parts are checked separately from PCB routing; errors must be zero before fabrication.'}
writeFileSync('dist/index/assembly-audit.json',JSON.stringify(result,null,2)+'\n')
console.log(JSON.stringify(result,null,2))
assert.equal(errors.length,0,'PCB errors remain; do not fabricate')