forked from noopkat/avrgirl-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
94 lines (83 loc) · 3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!doctype html>
<html>
<head>
<title>avrgirl test</title>
<link href="https://fonts.googleapis.com/css?family=Baloo+Bhaina|Cabin+Sketch|Fugaz+One|Itim|Sacramento&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="main">
<div class="wrapper">
<div class="bot">
<h1>Upload-o-matic</h1>
<p>Choose a program to upload to an arduino</p>
<form id="uploadForm">
<label>Board:
<select id="boardType">
<option value="uno">Uno</option>
<option value="mega">Mega</option>
</select>
</label>
<label>Program:
<div class="fileButtonWrapper">
<button id="fileButton" type="button" aria-controls="fileInput">Choose file</button>
<input id="fileInput" tabindex="-1" type="file"/>
<span id="fileName">no file chosen</span>
</div>
</label>
<button type="submit" id="uploadBtn">Upload!</button>
</form>
</div>
<div class="board">
<img src="images/ArduinoUno.svg"/>
</div>
<div id="pipe"></div>
<div id="progress"></div>
<div id="gear"><img src="images/gear4.svg"/></div>
</div>
</div>
<script src="/js/avrgirl-arduino.global.js" charset="UTF-8"></script>
<script>
function handleSubmit(e) {
e.preventDefault();
let filecontents;
const file = fileInput.files[0];
const reader = new FileReader();
const board = boardType.value;
reader.onload = function(event) {
filecontents = event.target.result;
let avrgirl = new AvrgirlArduino({
board: board,
debug: true
});
gear.classList.add('spinning');
avrgirl.flash(filecontents, (error) => {
gear.classList.remove('spinning');
progress.textContent = "done!";
if (error) {
console.error(error);
} else {
console.info('done correctly.');
}
});
};
reader.readAsArrayBuffer(file);
}
const uploadForm = document.getElementById('uploadForm');
const fileInput = document.getElementById('fileInput');
const fileButton = document.getElementById('fileButton');
const fileName = document.getElementById('fileName');
const boardType = document.getElementById('boardType');
const uploadBtn = document.getElementById('uploadBtn');
const log = document.getElementById('log');
const progress = document.getElementById('progress');
const gear = document.getElementById('gear');
uploadForm.addEventListener('submit', handleSubmit, false);
fileButton.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) fileName.textContent = file.name;
});
</script>
</body>
</html>