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-usbc

In 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/add-schematic-function-notes.ts

// Place handbook function notes in free schematic space after automatic layout.
// No manual schematic coordinates, PCB records or electrical connections change.
export function addSchematicFunctionNotes(circuit: any[]): void {
  for (let i = circuit.length - 1; i >= 0; i--) {
    if (circuit[i].type === 'schematic_text' && circuit[i].schematic_text_id?.startsWith('schematic_text_function_')) circuit.splice(i, 1)
  }
  const notes = [
    ['U1', 'USB HID MCU; 16 MHz crystal, 8 MHz CPU'],
    ['U_ESD', 'USB ESD protection; 5 V'],
    ...Array.from({ length: 6 }, (_, i) => [`U_RGB${i + 1}`, `U_RGB${i + 1}: RGB LED; switched 5 V`]),
  ]
  type Box = { left: number; right: number; bottom: number; top: number }
  const overlaps = (a: Box, b: Box) => a.left < b.right && a.right > b.left && a.bottom < b.top && a.top > b.bottom
  const box = (x: number, y: number, w: number, h: number): Box => ({ left: x - w / 2 - .15, right: x + w / 2 + .15, bottom: y - h / 2 - .15, top: y + h / 2 + .15 })
  for (const [name, text] of notes) {
    const source = circuit.find(e => e.type === 'source_component' && e.name === name)
    const chip = circuit.find(e => e.type === 'schematic_component' && e.source_component_id === source?.source_component_id)
    if (!chip) throw new Error(`Missing schematic symbol for ${name}`)
    const obstacles: Box[] = []
    for (const e of circuit.filter(e => e.schematic_sheet_id === chip.schematic_sheet_id)) {
      if (e.type === 'schematic_component') obstacles.push(box(e.center.x, e.center.y, e.size.width + 1.8, e.size.height + 1.2))
      if (e.type === 'schematic_text') obstacles.push(box(e.position.x, e.position.y, e.text.length * (e.font_size ?? .18) * .7, (e.font_size ?? .18) * 2))
      if (e.type === 'schematic_net_label') obstacles.push(box(e.center.x, e.center.y, Math.max(.5, (e.text ?? '').length * .13), .4))
      if (e.type === 'schematic_trace') for (const edge of e.edges) obstacles.push(box((edge.from.x + edge.to.x) / 2, (edge.from.y + edge.to.y) / 2, Math.abs(edge.to.x - edge.from.x), Math.abs(edge.to.y - edge.from.y)))
    }
    const width = text.length * .16 * .65
    const candidates: { x: number; y: number; distance: number }[] = []
    for (let dx = -16; dx <= 16; dx++) for (let dy = -16; dy <= 16; dy++) {
      const x = chip.center.x + dx * .3, y = chip.center.y + dy * .3
      candidates.push({ x, y, distance: name.startsWith("U_RGB") ? (dx + 10) ** 2 + (dy + 2) ** 2 : dx * dx + dy * dy })
    }
    const position = candidates.sort((a, b) => a.distance - b.distance).find(p => !obstacles.some(o => overlaps(box(p.x, p.y, width, .2), o)))
    if (!position) throw new Error(`No clear space for ${name} function note`)
    circuit.push({ type: 'schematic_text', schematic_text_id: `schematic_text_function_${name}`, schematic_component_id: chip.schematic_component_id, schematic_sheet_id: chip.schematic_sheet_id, anchor: 'center', text, font_size: .16, color: '#000000', rotation: 0, position: { x: position.x, y: position.y } })
  }
}