rushabhcodes/simple-usb-c-pd-peltier-driver
Reference-based four-layer USB-C PD Peltier driver with RP2040 control, adjustable voltage/current limits, fan power and temperature probes.
- Version
- 0.3.1
- License
- MIT
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone rushabhcodes/simple-usb-c-pd-peltier-driver # download the package files into ./simple-usb-c-pd-peltier-driver
tsci add rushabhcodes/simple-usb-c-pd-peltier-driver # add it to your project as @tsci/rushabhcodes.simple-usb-c-pd-peltier-driverIn 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/preview-source.ts
import { createHash } from "node:crypto"
const hash = (data: Uint8Array | string) => createHash("sha256").update(data).digest("hex")
function canonical(value: unknown): unknown {
if (Array.isArray(value)) return value.map(canonical)
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => [k, canonical(v)]))
return value
}
export function fingerprintSources(files: Array<{ path: string; data: Uint8Array }>) {
const sources: Record<string, string> = {}
for (const { path, data } of [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)) {
let bytes: Uint8Array | string = data
if (path === "package.json") {
const pkg = JSON.parse(Buffer.from(data).toString())
// Registry release numbering is metadata, not a board/model input.
delete pkg.version
bytes = JSON.stringify(canonical(pkg))
}
sources[path] = hash(bytes)
}
return { fingerprint: hash(JSON.stringify(sources)), sources }
}
export function changedSources(expected: Record<string, string>, actual: Record<string, string>) {
return [...new Set([...Object.keys(expected), ...Object.keys(actual)])].sort().filter(path => expected[path] !== actual[path])
}