MustafaMulla29/rp2040-bldc-motor-controller-new
73×72 mm 4-layer USB‑C PD (5/9/15/20 V) RP2040 controller PCB with protected power switching, MCT8329A sensorless BLDC three-phase MOSFET bridge, USB data/programming, onboard controls, and three motor outputs feeding a 2212 motor through rigid bullet adapters.
- Version
- 0.3.100
- License
- unset
- Stars
- 0
scripts/check-rgb-status.mjs
/** Verify the exported RGB circuit, including channel polarity and current limiting. */
import assert from 'node:assert/strict'
import { readFileSync, writeFileSync } from 'node:fs'
import { createHash } from 'node:crypto'
const raw = readFileSync(process.argv[2] ?? 'dist/index/circuit.json')
const c = JSON.parse(raw)
const parts = new Map(c.filter(x => x.type === 'source_component').map(x => [x.name, x]))
const nets = new Map(c.filter(x => x.type === 'source_net').map(x => [x.name, x.subcircuit_connectivity_map_key]))
const expected = {
U5: { 13: 'STATUS_RED', 37: 'STATUS_LED', 29: 'STATUS_BLUE' },
R48: { 1: 'STATUS_RED', 2: 'LED_R_A' },
R47: { 1: 'STATUS_LED', 2: 'LED_A' },
R49: { 1: 'STATUS_BLUE', 2: 'LED_B_A' },
LED1: { 1: 'LED_A', 2: 'LED_B_A', 3: 'LED_R_A', 4: 'GND' },
}
let checkedPins = 0
for (const [name, pins] of Object.entries(expected)) {
for (const [number, net] of Object.entries(pins)) {
const ports = c.filter(x => x.type === 'source_port' &&
x.source_component_id === parts.get(name)?.source_component_id && x.pin_number === Number(number))
assert.equal(ports.length, 1, `${name}.${number}: missing or duplicate port`)
assert.ok(nets.has(net), `Missing ${net}`)
assert.equal(ports[0].subcircuit_connectivity_map_key, nets.get(net), `${name}.${number}: wrong net`)
checkedPins++
}
}
assert.equal(parts.get('LED1').manufacturer_part_number, 'TJ-S1615SW6TGLCCSRGB-A5')
for (const name of ['R47', 'R48', 'R49']) assert.equal(parts.get(name).resistance, 1000)
const board = c.find(x => x.type === 'pcb_board')
assert.deepEqual([board.width, board.height], [73, 72], 'RGB change must not enlarge the board')
const pcbLed = c.find(x => x.type === 'pcb_component' && x.source_component_id === parts.get('LED1').source_component_id)
assert.equal(pcbLed.layer, 'top')
assert.ok(c.some(x => x.type.startsWith('pcb_courtyard_') && x.pcb_component_id === pcbLed.pcb_component_id))
assert.ok(c.some(x => x.type === 'pcb_silkscreen_text' && x.text === 'STATUS' && x.layer === 'top'))
const maxShortedChannelMa = 3.465 / 990 * 1000
assert.ok(maxShortedChannelMa <= 3.5)
const result = { status: 'PASS', sha256: createHash('sha256').update(raw).digest('hex'),
checkedPins, gpio: { red: 10, green: 25, blue: 18 }, commonCathodePin: 4,
boardSizeMm: [73, 72], resistorsOhms: 1000, maxShortedChannelMa,
note: 'Topology, footprint presence and resistor arithmetic only; optical brightness and hardware operation need prototype testing.' }
writeFileSync('dist/rgb-status.json', JSON.stringify(result, null, 2) + '\n')
console.log(JSON.stringify(result, null, 2))