-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp32cam.html
113 lines (105 loc) · 3.65 KB
/
esp32cam.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<html lang="en">
<head>
<script type="text/javascript" src="lib/repl.js"></script>
<script src="lib/WebSerial.js"></script>
<script src="lib/esptool/pako/pako_deflate.js"></script>
<script src="lib/esptool/slip.js"></script>
<script src="lib/esptool/md5.js"></script>
<script src="lib/esptool/esptool.js"></script>
</head>
<body>
<h1>MicroPython</h1>
<button id="getUSB">燒錄韌體</button>
<button id="eraseFw">清除韌體</button>
<button id="connect">connect</button>
<button id="run">run</button>
<button id="upload">upload</button>
<button id="snapshot">snapshot</button><br><br>
<div id='msg'>wait to connect...</div>
<textarea id="ctx" rows="10" style="width:480px"></textarea><br>
<textarea id="resp" rows="10" style="width:480px"></textarea>
<img id='photo'
src='https://shoplineimg.com/5b8cd726af6fe90005f4de3b/5d5220614738510023ab2864/800x.webp?source_format=jpg'
width='320' height='320'>
<script type="text/javascript">
let esp
let getUSB = document.getElementById("getUSB")
let eraseFw = document.getElementById("eraseFw")
getUSB.onclick = async () => {
esp = new ESP({
baudrate: 115200 * 2 /* 為燒錄速度 */
})
await esp.init()
esp.burn([
["./board/esp32cam/esp32cam.bin", 0x1000]
])
}
eraseFw.onclick = async () => {
esp = new ESP({
baudrate: 115200 * 8 /* 為燒錄速度 */
})
await esp.init()
esp.erase()
}
//////////////////////////////////////////
var repl = new REPL()
fetch('./esp32.py').then(function (response) {
return response.text();
}).then(async function (text) {
ctx.value = text;
msg.innerHTML = '';
});
connect.addEventListener('click', async () => {
connect.disabled = true;
msg.innerHTML = 'connecting...';
resp.value = '';
await repl.usbConnect();
await repl.enter('esp32');
resp.value = '';
var output = '';
await repl.write(`
print('REPL Ready...')
`, function (data) {
output += (data + "\r\n");
resp.value = output;
return {
value: '',
done: false
}
});
connect.disabled = false;
msg.innerHTML = 'connected';
})
run.addEventListener('click', async () => {
run.disabled = true;
resp.value = '';
var output = '';
await repl.write(ctx.value, function (data) {
output += (data + "\r\n");
resp.value = output;
return {
value: '',
done: false
}
});
run.disabled = false;
})
upload.addEventListener('click', async () => {
upload.disabled = true;
var file = 'main.py';
await repl.usbConnect();
msg.innerHTML = 'uploading...';
await repl.enter('esp32')
var writeLen = await repl.uploadFile('esp32', file, ctx.value);
msg.innerHTML = 'upload ' + file + " ," + writeLen + " Bytes";
await repl.restart();
upload.disabled = false;
})
snapshot.addEventListener('click', async () => {
snapshot.disabled = true;
photo.src = await repl.snapshot();
snapshot.disabled = false;
})
</script>
</body>
</html>