Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Enabled downloading log as a CSV #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ <h1>WebJack Demo</h1>
<p>
<button class="btn-baud">Change baud</button>
<button class="btn-freq">Change frequencies</button>
<button class="btn-dl">Download</button>
</p>

<script>
Expand Down Expand Up @@ -169,6 +170,21 @@ <h1>WebJack Demo</h1>
var baud = prompt('Enter a baud (speed) that is a factor of 44100 and under 1225',441);
if (baud) connection.setBaud(baud);
});
$('.btn-dl').click(function() {
// unicode and data type header for download href
var csv = "data:text/csv;charset=utf-8," + connection.history.received.join('\n');
// encode received data for utf8
var encodedUri = encodeURI(csv);

// hidden link created for HTML download attribute
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", new Date().toJSON().slice(0,10).replace(/-/g,'/')+'.csv');
document.body.appendChild(link); // Required for FF
link.click();
// removed hidden html link for cleanliness
document.body.removeChild(link);
});

</script>
<script src="fft/sketch.js"></script>
Expand Down