-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebbit.html
120 lines (113 loc) · 3.28 KB
/
webbit.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
114
115
116
117
118
119
120
<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>Blockly & MicroPython</h1>
<button id="eraseFw">清除韌體</button>
<button id="blockly">燒錄 Blockly</button>
<button id="mpython">燒錄 MicroPython</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>
<script type="text/javascript">
let esp
let getUSB = document.getElementById("getUSB")
let eraseFw = document.getElementById("eraseFw")
blockly.onclick = async () => {
esp = new ESP({
baudrate: 115200 * 2
})
await esp.init()
esp.burn([
["./board/webbit/firmware.bin", 0]
])
}
mpython.onclick = async () => {
esp = new ESP({
baudrate: 115200 * 2
})
await esp.init()
esp.burn([
//["./board/webbit/firmware-esp32-GENERIC.bin", 0x1000]
["./board/webbit/local.bin", 0x1000]
])
}
eraseFw.onclick = async () => {
esp = new ESP({
baudrate: 115200 * 2
})
await esp.init()
esp.erase()
}
//////////////////////////////////////////
var repl = new REPL()
fetch('./webbit.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>