Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add ability to download config #69

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ We will be actively montoring this and fix any issues when we can!
* Development happens here on `YAGSL-Example`. `YAGSL` and `YAGSL-Lib` are updated on a nightly
basis.

### TL;DR Make your configuration [here](https://broncbotz3481.github.io/YAGSL-Example/) and put it into the structure bellow.
### TL;DR Generate and download your configuration [here](https://broncbotz3481.github.io/YAGSL-Example/) and unzip it so that it follows structure below:

```text
deploy
Expand Down
38 changes: 38 additions & 0 deletions docs/assets/js/v2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@



function getFreeSpeedFromMotors() {
let motor_count = {}
let modules = ['frontright', 'frontleft', 'backright', 'backleft'];
Expand Down Expand Up @@ -100,6 +103,41 @@ function copyText(name) {
navigator.clipboard.writeText(text);
}


function getText(name) {
let text = $(`#${name}-json`).text();
return text;
}

//function from https://github.com/eligrey/FileSaver.js/issues/774
const saveAs = (blob, name) => {
// Namespace is used to prevent conflict w/ Chrome Poper Blocker extension (Issue https://github.com/eligrey/FileSaver.js/issues/561)
const a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
a.download = name
a.rel = 'noopener'
a.href = URL.createObjectURL(blob)

setTimeout(() => URL.revokeObjectURL(a.href), 40 /* sec */ * 1000)
setTimeout(() => a.click(), 0)
}

function zipDownload() {
const zip = new JSZip();
let swf = zip.folder("swerve")
let cp = swf.file("controllerproperties.json", getText("controllerproperties"));
let sd = swf.file("swervedrive.json", getText("swervedrive"));
let mod = swf.folder("modules")
let pp = mod.file("physicalproperties.json", getText("physicalproperties"));
let fl = mod.file("frontleft.json", getText("frontleft"));
let fr = mod.file("frontright.json", getText("frontright"));
let bl = mod.file("backleft.json", getText("backleft"));
let br = mod.file("backright.json", getText("backright"));
let pidf = mod.file("pidfproperties.json", getText("pidfproperties"));

zip.generateAsync({type:"blob"}).then(function (blob) {saveAs(blob, "YAGSL Config.zip")});
console.log("Downloaded YAGSL Config zip");
}

$(function () {
const tooltipTriggerList = document.querySelectorAll(
'[data-bs-toggle="tooltip"]'); // Initialize tooltips: https://getbootstrap.com/docs/5.3/components/tooltips/#enable-tooltips
Expand Down
7 changes: 7 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,9 @@ <h1 class="display-6">Module Tuning</h1>
</div>
</div>
</div>
<div id="download-button">
<button class="btn btn-primary btn-lg mt-2 mb-3" id="download" type="button" onclick="zipDownload()">Download</button>
</div>
</div>
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script crossorigin="anonymous" src="https://kit.fontawesome.com/1d72776854.js"></script>
Expand All @@ -916,7 +919,11 @@ <h1 class="display-6">Module Tuning</h1>
src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>

<script
src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js"></script>
<script src="assets/js/v2.js"></script>

</body>

</html>