abse/gameboy-advance

A tscircuit package created by abse.

Version
0.0.45
License
unset
Stars
0

checks/display-cable-clearance.ts

PCBPCB preview for checks/display-cable-clearance.ts
SchematicSchematic preview for checks/display-cable-clearance.ts
import {readFileSync,writeFileSync} from 'node:fs'
const c=JSON.parse(readFileSync('dist/index/circuit.json','utf8'))
const source=c.find((e:any)=>e.type==='source_component'&&e.name==='R_LCD_LED')
const cad=c.find((e:any)=>e.type==='cad_component'&&e.source_component_id===source.source_component_id)
const manifest=JSON.parse(readFileSync('mechanical/manifest.json','utf8'))
const corridor=manifest.parts.find((e:any)=>e.id==='lcd-flex-clearance').bounds
const wheel=manifest.parts.find((e:any)=>e.id==='volume-wheel').bounds
if(cad.rotation.x!==0||cad.rotation.y!==0||cad.model_origin_position.x!==0||cad.model_origin_position.y!==0||cad.model_origin_position.z!==0)throw Error('Recalculate tilted/offset backlight resistor envelope')
// Supplier OBJ: x[-1.6,1.6],y[-0.8,0.8],z[0,0.56]mm. Rotate its actual envelope.
const a=cad.rotation.z*Math.PI/180,halfX=1.6*Math.abs(Math.cos(a))+.8*Math.abs(Math.sin(a))
const halfY=1.6*Math.abs(Math.sin(a))+.8*Math.abs(Math.cos(a))
const bounds=[[cad.position.x-halfX,cad.position.y-halfY,cad.position.z],[cad.position.x+halfX,cad.position.y+halfY,cad.position.z+.56]]
const cableGap=corridor[0][0]-bounds[1][0],wheelGap=bounds[0][0]-wheel[1][0]
if(cableGap<.5||wheelGap<.5)throw Error('Backlight resistor obstructs cable corridor or wheel envelope')
writeFileSync('dist/index/display-cable-clearance.json',JSON.stringify({part:'R_LCD_LED',positionMm:cad.position,rotationDegrees:cad.rotation.z,supplierBodyBoundsMm:bounds,corridorBoundsMm:corridor,volumeWheelBoundsMm:wheel,cableXSeparationMm:cableGap,wheelXSeparationMm:wheelGap,minimumNominalBodyGapMm:.5,method:'Disjoint rotated supplier-model and conservative cable / wheel envelopes',connectorPlacementUnchanged:true,physicalCableBendAndInsertionTestStillRequired:true,pass:true},null,2))
console.log('Upper backlight resistor clearance: cable',cableGap.toFixed(3),'mm; wheel',wheelGap.toFixed(3),'mm')