-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebai.html
128 lines (118 loc) · 3.83 KB
/
webai.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
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript" src="lib/repl.js"></script>
<script src="lib/kflash/pako_inflate.min.js"></script>
<script src="lib/kflash/crc.js"></script>
<title>Document</title>
</head>
<body>
<select id="baudrate">
<option value="2000000">低 - 2000000</option>
<option value="3000000" selected>高 - 3000000</option>
</select>
<button id="connect">準備韌體中...</button><span id="progress"></span>
<span id="interval"></span>
<button id="connectK210">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/61693fc6275255003bc38569/800x.webp?source_format=jpg'
width='320' height='240'>
<script type="text/javascript">
var repl = new REPL()
fetch('./esp32.py').then(function (response) {
return response.text();
}).then(async function (text) {
ctx.value = text;
msg.innerHTML = '';
});
connectK210.addEventListener('click', async () => {
connectK210.disabled = true;
msg.innerHTML = 'connecting...';
resp.value = '';
await repl.usbConnect();
await repl.enter('');
resp.value = '';
var output = '';
await repl.write(`
print('REPL Ready...')
`, function (data) {
output += (data + "\r\n");
resp.value = output;
return {
value: '',
done: false
}
});
connectK210.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('k210')
var writeLen = await repl.uploadFile('k210', 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('k210');
snapshot.disabled = false;
})
</script>
</body>
<script type="module">
connect.disabled = true;
import kflash from "./lib/kflash/kflash.js";
fetch("./board/webai/webai_v1.0.7.bin")
.then((response) => {
if (response.status === 200)
return response.blob();
else
throw new Error('Firmware is not Found')
})
.then((data) => {
const firmware = data;
connect.innerHTML = '更新韌體'
console.log(firmware);
connect.disabled = false;
connect.onclick = async () => {
let start_time = null;
await kflash.requestSerialPort();
kflash.setBaudRate(baudrate.options[baudrate.selectedIndex].value);
await kflash.write(0x000000, firmware, (percent) => {
if (percent === 0) start_time = new Date();
const end_time = new Date();
progress.innerHTML = `進度 ${percent}%`;
interval.innerHTML = `時間 ${(end_time - start_time) / 1000}s`;
});
};
});
</script>
</html>