gokul/macro-six-usbc
A six-key macro keyboard PCB paired with a separate physical enclosure.
- Version
- 0.1.16
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone gokul/macro-six-usbc # download the package files into ./macro-six-usbc
tsci add gokul/macro-six-usbc # add it to your project as @tsci/gokul.macro-six-usbcIn a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
simulation/build-candidate.tsx
PCB
Schematic
import { Circuit } from '@tscircuit/core'
import { MacroKeyboard } from '../lib/macro-keyboard'
import { deepStrictEqual } from 'node:assert'
import { convertCircuitJsonToStackedSchematicSheetsSvg } from 'circuit-to-svg'
const circuit=new Circuit()
circuit.add(<MacroKeyboard includeEnclosure={false} />)
await circuit.renderUntilSettled()
const json=JSON.parse(JSON.stringify(circuit.getCircuitJson()))
const errors=json.filter(e=>e.type.endsWith('_error'))
if(errors.length) throw new Error(JSON.stringify(errors))
const old=await Bun.file('outputs/release/board.circuit.json').json()
// Internal IDs and numeric precision can change between Core versions. Compare physical semantics.
const normalise=(v: unknown): unknown => typeof v==='number' ? Math.round(v*1e6)/1e6 : Array.isArray(v) ? v.map(normalise) : v && typeof v==='object' ? Object.fromEntries(Object.entries(v).filter(([k])=>!k.endsWith('_id')).map(([k,v])=>[k,normalise(v)])) : v
const canonical=(rows: unknown[])=>rows.map(r=>JSON.stringify(normalise(r))).sort()
const sourceConnectivity=(j)=>{
const components=new Map(j.filter(e=>e.type==='source_component').map(e=>[e.source_component_id,e.name]))
const ports=new Map(j.filter(e=>e.type==='source_port').map(e=>[e.source_port_id,`${components.get(e.source_component_id)}:${e.pin_number}`]))
const nets=new Map(j.filter(e=>e.type==='source_net').map(e=>[e.source_net_id,e.name]))
return j.filter(e=>e.type==='source_trace').map(e=>[e.connected_source_port_ids.map(p=>ports.get(p)).sort(),e.connected_source_net_ids.map(n=>nets.get(n)).sort()])
}
deepStrictEqual(canonical(sourceConnectivity(json)),canonical(sourceConnectivity(old)),'Physical pin/net connectivity changed')
const geometryFields={
pcb_board:['center','width','height','thickness','num_layers','outline'],
pcb_smtpad:['shape','x','y','width','height','radius','points','layer','ccw_rotation'],
pcb_plated_hole:['shape','x','y','hole_diameter','outer_diameter','hole_width','hole_height','outer_width','outer_height','layers','ccw_rotation'],
pcb_hole:['hole_shape','x','y','hole_diameter','hole_width','hole_height'],
pcb_via:['x','y','hole_diameter','outer_diameter','layers'],
pcb_trace:['route']}
for(const [type,keys] of Object.entries(geometryFields)){
const geometry=(j)=>canonical(j.filter(e=>e.type===type).map(e=>Object.fromEntries(keys.filter(k=>e[k]!==undefined).map(k=>[k,e[k]]))))
deepStrictEqual(geometry(json),geometry(old),`${type}: physical geometry changed`)
}
const oldComponents=old.filter(e=>e.type==='pcb_component')
for(const c of json.filter(e=>e.type==='pcb_component')){
const previous=oldComponents.find(e=>e.pcb_component_id===c.pcb_component_id)
if(!previous || Math.abs(previous.center.x-c.center.x)>0.0001 || Math.abs(previous.center.y-c.center.y)>0.0001 || previous.rotation!==c.rotation || previous.layer!==c.layer)throw Error('Placement changed')
}
const prohibited=['source_refdes_convention_warning','source_no_power_pin_defined_warning','source_no_ground_pin_defined_warning','source_component_pins_underspecified_warning']
if(json.some(e=>prohibited.includes(e.type)))throw Error('A reported warning remains')
for(const name of ['Q_MAIN','Q_RGB']) {
const c=json.find(e=>e.type==='source_component'&&e.name===name)
const ports=json.filter(e=>e.type==='source_port'&&e.source_component_id===c.source_component_id)
for(const [pin,role] of [[1,'gate'],[2,'source'],[3,'drain']] as const) if(!ports.find(p=>p.pin_number===pin)?.port_hints?.includes(role)) throw Error(`${name} ${role}`)
}
await Bun.write(`${import.meta.dir}/candidate.circuit.json`,JSON.stringify(json,null,2))
await Bun.write(`${import.meta.dir}/candidate-schematic.svg`,convertCircuitJsonToStackedSchematicSheetsSvg(json))
console.log('PASS: zero errors and none of the reported source warnings; pads, drills, saved routes and pin/net connections preserved. Regenerated pours require independent clearance checks.')