MustafaMulla29/rp2040-bldc-motor-controller-new

A USB‑C PD–powered RP2040 BLDC motor controller PCB with 3.3 V logic, MCT8329A sensorless commutation, three MOSFET half-bridges, protected power switching, USB data, controls, and motor connectors.

Version
0.3.82
License
unset
Stars
0

scripts/assembly-geometry.ts

import { createHash } from "node:crypto"

// Source-filesystem metadata differs between a local checkout and the registry.
// The portable assembly is tied to the actual PCB/CAD geometry instead.
export function hashPcbGeometry(rows: Record<string, any>[]): string {
  const canonical = (value: any): any => {
    if (Array.isArray(value)) return value.map(canonical)
    if (value && typeof value === "object") return Object.fromEntries(
      Object.keys(value).sort().filter(k => value[k] != null)
        .map(k => [k, canonical(value[k])]),
    )
    if (typeof value === "string") return value.replace(/&cachebust_origin=[^&]*/g, "")
    return value
  }
  const geometry = rows.filter(r => r.type.startsWith("pcb_") ||
    (r.type === "cad_component" && r.pcb_component_id))
  return createHash("sha256").update(JSON.stringify(canonical(geometry))).digest("hex")
}