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.
scripts/prepare-published-views.ts
import { readFile, writeFile, mkdir, copyFile } from 'node:fs/promises'
import { deepStrictEqual } from 'node:assert'
import { assertGeometryEqual } from './assert-geometry-equal'
import { convertCircuitJsonToPcbSvg, convertCircuitJsonToStackedSchematicSheetsSvg } from 'circuit-to-svg'
const board = JSON.parse(await readFile('outputs/release/board.circuit.json', 'utf8'))
const built = JSON.parse(await readFile('dist/open-assembly/circuit.json', 'utf8'))
if (built.some((e: any) => e.type.endsWith('_error'))) throw new Error('Build contains circuit errors')
// A preview must never substitute an older validated layout for changed source.
const fields: Record<string, string[]> = {
source_net: ['source_net_id', 'name'],
source_port: ['source_port_id', 'source_component_id', 'name', 'pin_number'],
source_trace: ['connected_source_port_ids', 'connected_source_net_ids'],
pcb_board: ['width', 'height', 'thickness', 'num_layers', 'outline'],
pcb_component: ['center', 'width', 'height', 'layer', 'rotation'],
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_copper_pour: ['shape', 'layer', 'points', 'brep_shape'],
}
const pick = (e: any, keys: string[]) => Object.fromEntries(keys.filter(k => e[k] !== undefined).map(k => [k, e[k]]))
for (const [type, keys] of Object.entries(fields)) {
const geometry = (j: any[]) => j.filter(e => e.type === type).map(e => pick(e, keys))
assertGeometryEqual(geometry(built), geometry(board), `${type}: regenerate and validate fabrication files before publication`)
}
const componentValues = (j: any[]) => j.filter(e => e.type === 'source_component' && e.ftype !== 'printedpart' && e.name !== 'CASE_HARDWARE').map(e => pick(e, ['name', 'ftype', 'resistance', 'capacitance', 'inductance', 'frequency', 'current_rating_amps', 'voltage_rating_volts', 'supplier_part_numbers', 'manufacturer_part_number']))
deepStrictEqual(componentValues(built), componentValues(board), 'Component values differ from the validated BOM')
const routes = (j: any[]) => j.filter(e => e.type === 'pcb_trace').map(e => e.route.map((p: any) => pick(p, ['route_type', 'x', 'y', 'layer', 'width', 'from_layer', 'to_layer', 'via_diameter', 'via_hole_diameter'])))
deepStrictEqual(routes(built), routes(board), 'PCB routing differs from validated fabrication files')
const parts = built.filter((e: any) => e.type === 'source_component' && (e.ftype === 'printedpart' || e.name === 'CASE_HARDWARE'))
const ids = new Set(parts.map((e: any) => e.source_component_id))
const models = built.filter((e: any) => e.type === 'cad_component' && ids.has(e.source_component_id))
if (parts.length !== 6 || models.length !== 6) throw new Error('Incomplete enclosure preview')
for (const e of [...parts, ...models]) {
const key = e.type === 'source_component' ? 'source_component_id' : 'cad_component_id'
if (board.some((b: any) => b.type === e.type && b[key] === e[key])) throw new Error('CAD ID collision')
}
// Show complete routes in the published preview. WebGPU can omit segments marked
// inside a pour even when that pour is hidden. These are display annotations:
// keep every copper coordinate, layer, width, via and pour unchanged.
const visibleBoard = board.map((e: any) => e.type === 'pcb_trace' ? {
...e,
route: e.route.map(({ is_inside_copper_pour, copper_pour_id, ...point }: any) => point),
} : e)
const scene = [...visibleBoard, ...parts, ...models]
if (scene.filter(e => e.type === 'schematic_sheet').length !== 2) throw new Error('Expected two schematic sheets')
const pcb = convertCircuitJsonToPcbSvg(scene, { layer: 'top' })
const schematic = convertCircuitJsonToStackedSchematicSheetsSvg(scene)
for (const entry of ['open-assembly', 'index', 'enclosed']) {
const dir = `dist/${entry}`
await mkdir(dir, { recursive: true })
await writeFile(`${dir}/circuit.json`, JSON.stringify(scene, null, 2))
await writeFile(`${dir}/pcb.svg`, pcb)
await writeFile(`${dir}/schematic.svg`, schematic)
if (entry !== 'open-assembly') await copyFile('dist/open-assembly/3d.png', `${dir}/3d.png`)
}
console.log('Published views use validated PCB geometry, six CAD parts and both schematic sheets')