Skip to content

Instantly share code, notes, and snippets.

@Kraballa
Created August 14, 2022 12:27
Show Gist options
  • Save Kraballa/046b77f2e78a3a9764e317d99cb63052 to your computer and use it in GitHub Desktop.
Save Kraballa/046b77f2e78a3a9764e317d99cb63052 to your computer and use it in GitHub Desktop.
function build(chain) {
let fileData = "";
fileData += "Version 4\nSHEET 1 880 680\n";
//add all wires
fileData += "WIRE 32 -256 32 -272\n" +
"WIRE 32 -208 32 -256\n" +
"WIRE 32 -96 32 -128\n" +
"WIRE -128 -48 -128 -64\n" +
"WIRE -128 16 -128 -48\n" +
"WIRE -96 16 -128 16\n" +
"FLAG 32 -96 0\n" +
"FLAG 32 -256 U1\n" +
"FLAG -128 -48 U1\n";
//wire up resistors
var pos = 0;
for (let i = 0; i < chain.res.length; i++) {
pos = -16 + i * 128;
fileData += "WIRE " + (pos + 48) + " 16 " + pos + " 16\n";
}
//place ground at the end of the resistors
fileData += "FLAG " + (pos + 48) + " 16 0\n";
//add voltage source
fileData += "SYMBOL voltage 32 -224 R0\n" +
"WINDOW 123 0 0 Left 0\n" +
"WINDOW 39 0 0 Left 0\n" +
"SYMATTR InstName V1\n" +
"SYMATTR Value " + chain.volt + "\n";
//add all resistors
for (let i = 0; i < chain.res.length; i++) {
fileData +="SYMBOL res " + (i * 128) + " 0 R90\n"; //position
fileData += "WINDOW 0 0 56 VBottom 2\n";
fileData += "WINDOW 3 32 56 VTop 2\n";
fileData += "SYMATTR InstName R" + (i + 1) + "\n"; //name
fileData += "SYMATTR Value " + chain.res[i] + "R\n"; //resistance value
}
return fileData;
}
function download(data, filename) {
const blob = new Blob([data], {type: 'text/csv'});
if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename);
}
else{
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
}
export {build, download};
@Kraballa
Copy link
Author

export resChains created with this script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment