Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChSotiriou committed Dec 30, 2024
0 parents commit 52076f5
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 0 deletions.
14 changes: 14 additions & 0 deletions createOverview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import yaml
from jinja2 import Environment, FileSystemLoader, select_autoescape

env = Environment(
loader=FileSystemLoader("templates"),
autoescape=select_autoescape()
)
template = env.get_template('index.jinja')

tools = yaml.safe_load(open("./tools.yaml"))

rendered_html = template.render(tools=tools)

open("dist/index.html", 'w').write(rendered_html)
68 changes: 68 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Tools</title>
<!-- Bootstrap CSS link -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

<div class="container mt-5">
<h1 class="text-center mb-4">A whole bunch of Simple Tools</h1>


<h2 class="text-left mb-4">KiCAD</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Tools</th>
<th>Description</th>
</tr>
</thead>
<tbody>

<tr>
<td><a href="tools/kicad/pcb-outline-creator" class="btn btn-link">PCB Outline Creator</a></td>
<td>Create a rectangular PCB outline with rounded corners</td>
</tr>

<tr>
<td><a href="tools/kicad/library-loader" class="btn btn-link">Library Downloader</a></td>
<td>Extract KiCAD files from SamacSys library (e.g. Mouser download)</td>
</tr>

</tbody>
</table>

<h2 class="text-left mb-4">LTSpice</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Tools</th>
<th>Description</th>
</tr>
</thead>
<tbody>

<tr>
<td><a href="tools/ltspice/multiParameterSweep" class="btn btn-link">MultiParameter Sweep</a></td>
<td>Simplifies creating a multiparameter sweep in LTSpice</td>
</tr>

</tbody>
</table>



</div>

<!-- Bootstrap JS and Popper.js (for responsive features) -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
</body>

</html>
16 changes: 16 additions & 0 deletions dist/tools/kicad/library-loader/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body {
background: #131418;
text-align: center;
margin-top: 10%;
color: #f8f8f2;
}

#lib {
margin-top: 2em;
}

#submit_btn {
margin-top: 2em;
width: 25%;
height: 2em;
}
23 changes: 23 additions & 0 deletions dist/tools/kicad/library-loader/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>KiCad Library Downloader</title>
<script type="text/javascript" src="js/main.js" defer></script>
<script type="text/javascript" src="js/zip.min.js"></script>
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen">
</head>

<body>
<h1>KiCad Library Downloader</h1>
<input type="file"
id="lib" name="library"
accept="application/zip">
<br></br>
<input type="submit" id='submit_btn' value="Get Library Files" />

</body>

</html>
43 changes: 43 additions & 0 deletions dist/tools/kicad/library-loader/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const FILE_INPUT_ID = "lib"
const SUBMIT_ID = 'submit_btn'

btn = document.getElementById(SUBMIT_ID)
btn.addEventListener("click", async () => {
files = document.getElementById("lib").files
if (files.length == 1) {
file = new zip.ZipReader(new zip.BlobReader(files[0]))
entries = await file.getEntries()
kicad_files = entries.filter(entry => {
filename = entry.filename
return filename.includes("KiCad") && (filename.endsWith(".lib") || filename.endsWith(".kicad_mod"))
})
model = entries.filter(entry => entry.filename.endsWith(".stp"))[0]
lib_files = kicad_files.concat(model)

const zipFileWriter = new zip.BlobWriter();
const zipWriter = new zip.ZipWriter(zipFileWriter);

for (i = 0; i < lib_files.length; i++) {
blobWriter = new zip.BlobWriter()
filename = lib_files[i].filename.split("/").at(-1)
console.log(filename)
blob = await lib_files[i].getData(blobWriter)
blobReader = new zip.BlobReader(blob)
zipWriter.add(filename, blobReader)
}

blobURL = URL.createObjectURL(await zipWriter.close());
if (blobURL) {
const anchor = document.createElement("a");
const clickEvent = new MouseEvent("click");
anchor.href = blobURL;
anchor.download = "library.zip";
anchor.dispatchEvent(clickEvent);
}
downloadButton.disabled = true;
event.preventDefault();
} else {
alert("No zip file selected")
}

})
1 change: 1 addition & 0 deletions dist/tools/kicad/library-loader/js/zip.min.js

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions dist/tools/kicad/pcb-outline-creator/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
body {
background: #131418;
text-align: center;
margin-top: 10%;
color: #f8f8f2;
}

label {
color: #f8f8f2;
font-size: 1.25em;
}

.container {
justify-content: center;
display: grid;
grid-template-columns: 10% 15% 10% 15% 10% 15%;
grid-template-rows: 1fr 1fr 15fr;
gap: 1em 1em;
grid-auto-flow: row;
grid-template-areas:
". ."
". .";
}

#output {
grid-column: 1/-1;
}

textarea {
overflow-y: scroll;
/* width: 75%; */
/* height: 100px; */
resize: none; /* Remove this if you want the user to resize the textarea */
}

.submit_btn {
grid-column: span 2;
}
59 changes: 59 additions & 0 deletions dist/tools/kicad/pcb-outline-creator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>KiCad PCB Outline Creator</title>
<script src="js/main.js" defer></script>
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen">
</head>

<body>

<h1>KiCad PCB Outline Creator</h1>
<div class="container">
<label class="lbl">Width (mm)</label><input type="number" name="rect_width" id="rect_width" value="50">
<label class="lbl">Height (mm)</label><input type="number" name="rect_height" id="rect_height" value="50">
<label class="lbl">Corner Radius (mm)</label><input type="number" name="fillet" id="fillet" value="5">
<label class="lbl">Layer (mm)</label>
<select name="layer" id="layer_select">
<option>F.Cu</option>
<option>In1.Cu</option>
<option>In2.Cu</option>
<option>B.Cu</option>
<option>B.Adhes</option>
<option>F.Adhes</option>
<option>B.Paste</option>
<option>F.Paste</option>
<option>B.SilkS</option>
<option>F.SilkS</option>
<option>B.Mask</option>
<option>F.Mask</option>
<option>Dwgs.User</option>
<option>Cmts.User</option>
<option>Eco1.User</option>
<option>Eco2.User</option>
<option selected="selected">Edge.Cuts</option>
<option>Margin</option>
<option>B.CrtYd</option>
<option>F.CrtYd</option>
<option>B.Fab</option>
<option>F.Fab</option>
<option>User.1</option>
<option>User.2</option>
<option>User.3</option>
<option>User.4</option>
<option>User.5</option>
<option>User.6</option>
<option>User.7</option>
<option>User.8</option>
<option>User.9</option>
</select>
<input type="submit" id='submit_btn' class="submit_btn" value="Generate" />
<textarea name="output" id="output" readonly></textarea>
</div>

</body>

</html>
55 changes: 55 additions & 0 deletions dist/tools/kicad/pcb-outline-creator/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
ID = 0

function getLine(x1, y1, x2, y2, layer = "Edge.Cuts") {
ID++
return `(gr_line (start ${x1} ${y1}) (end ${x2} ${y2}) (layer "${layer}") (tstamp ${ID}))`
}

function getArc(startx, starty, midx, midy, endx, endy, layer = "Edge.Cuts") {
ID++
return `(gr_arc (start ${startx} ${starty}) (mid ${midx} ${midy}) (end ${endx} ${endy}) (layer "${layer}") (tstamp ${ID}))`
}

const WIDTH_ID = 'rect_width'
const HEIGHT_ID = 'rect_height'
const FILLET_ID = 'fillet'
const LAYER_SELECT_ID = 'layer_select'
const SUBMIT_ID = 'submit_btn'

btn = document.getElementById(SUBMIT_ID)
btn.addEventListener("click", () => {
width = document.getElementById(WIDTH_ID).value
height = document.getElementById(HEIGHT_ID).value
fillet = document.getElementById(FILLET_ID).value
layer = document.getElementById(LAYER_SELECT_ID).value
arc_delta = Math.sin(Math.PI / 4) * fillet

ID = 0

output_text = "(kicad_pcb (version 20211014) (generator pcbnew)"
output_text += '(net 0 "")'

output_text += getLine(fillet, 0, width - fillet, 0, layer)
output_text += getLine(0, fillet, 0, height - fillet, layer)
output_text += getLine(fillet, height, width - fillet, height, layer)
output_text += getLine(width, fillet, width, height - fillet, layer)

output_text += getArc(0, fillet, fillet - arc_delta, fillet - arc_delta, fillet, 0, layer)
output_text += getArc(0, height - fillet, fillet - arc_delta, height - fillet - arc_delta, fillet, height, layer)
output_text += getArc(width - fillet, 0, width - fillet + arc_delta, fillet - arc_delta, width, fillet, layer)
output_text += getArc(width - fillet, height, width - fillet + arc_delta, height - fillet - arc_delta, width, height - fillet, layer)

output_text += ')'

document.getElementById('output').value = output_text
if (window.isSecureContext && navigator.clipboard)
navigator.clipboard.writeText(output_text);

setTimeout(function() {
if (window.isSecureContext && navigator.clipboard) {
alert("Outline has been copied to clipboard. Just hit Control-V in KiCad to paste.")
} else {
alert("Outline has been generated. Copy it from below and paste into kicad.")
}
}, 50);
})
11 changes: 11 additions & 0 deletions dist/tools/ltspice/multiParameterSweep/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
background-color: #f8f9fa;
}

.container {
max-width: 600px;
}

h2 {
color: #343a40;
}
Loading

0 comments on commit 52076f5

Please sign in to comment.