abse/gameboy-advance
A tscircuit package created by abse.
- Version
- 0.0.45
- License
- unset
- Stars
- 0
checks/usb-led-electrical.ts
PCB
Schematic
import{readFileSync,writeFileSync}from'node:fs';const c=JSON.parse(readFileSync('dist/index/circuit.json','utf8'));const comps=new Map(c.filter((e:any)=>e.type==='source_component').map((e:any)=>[e.name,e]));const ports=c.filter((e:any)=>e.type==='source_port');const p=(name:string,pin:string)=>ports.find((e:any)=>e.source_component_id===(comps.get(name)as any)?.source_component_id&&(e.name===pin||e.port_hints?.includes(pin)));const net=(n:string,pin:string)=>p(n,pin)?.subcircuit_connectivity_map_key;const assert=(x:any,m:string)=>{if(!x)throw Error(m)};assert((comps.get('R_USB_PRESENT')as any).resistance===1000,'Wrong LED resistance');assert(net('R_USB_PRESENT','pin1')===c.find((e:any)=>e.type==='source_net'&&e.name==='VBUS').subcircuit_connectivity_map_key,'LED supply must be VBUS');assert(net('R_USB_PRESENT','pin2')===net('D_USB_PRESENT','anode'),'Missing series path');assert(net('D_USB_PRESENT','cathode')===net('U1','GND'),'Wrong LED cathode net');assert(net('D_USB_PRESENT','anode')!==net('U1','GND'),'LED anode short');const led=comps.get('D_USB_PRESENT')as any;assert(led.supplier_part_numbers.jlcpcb[0]==='C2297','LED supplier mismatch');const pc=c.find((e:any)=>e.type==='pcb_component'&&e.source_component_id===led.source_component_id);assert(pc.layer==='bottom'&&pc.center.x===9&&pc.center.y===38.5,'Wrong LED position/layer');const maxCurrentA=5.5/990,maxResistorW=5.5**2/990;assert(maxCurrentA<.006&&maxResistorW<.0625,'Indicator overload');const report={pass:true,mode:'USB VBUS present; independent of firmware and battery switch',led:'KT-0805G',jlcpcb:'C2297',resistorOhm:1000,maxCurrentAAt5V5Including1PercentR:maxCurrentA,maxResistorWWithShortedLED:maxResistorW,layer:'bottom',positionMm:[9,38.5],physicalSupplyAndBrightnessTestRequired:true};writeFileSync('dist/index/usb-led-electrical.json',JSON.stringify(report,null,2));console.log('USB power indicator checks passed',report);