-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoc.html
74 lines (69 loc) · 1.97 KB
/
poc.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
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>CH340G in a Browser - Proof of Concept</title>
<style>
body {
font-family: sans-serif;
}
p#marquee {
border-width: 1px;
border-style: solid;
padding: 3px;
}
</style>
</head>
<body>
<p>This code is just a POC, nobody would be prepared to describe it as
"robust".</p>
<p>But if you
<button id="click-bait" type="button">Click this 'ere button</button>
an endless marquee of test data should start streaming from the test device...
right here:</p>
<p id="marquee"> </p>
<script>
window.addEventListener(
"load",
() => {
const getReader = async () => {
const port = await navigator.serial.requestPort({
"filters": [
{ "usbVendorId": 0x1A86, "usbProductId": 0x7523 }
]
});
await port.open({ "baudRate": 9600 });
return port.readable.getReader();
}
const decoder = new TextDecoder();
const read = async (reader) => {
const { value, done } = await reader.read();
if (done) {
reader.releaseLock();
return null;
}
return decoder.decode(value)
}
var text = "";
const trimText = (newText, size) => {
text = text + newText
return text.length > size ? text.slice(-size) : text;
}
document.getElementById("click-bait").addEventListener(
"click",
async () => {
const reader = await getReader();
const marquee = document.getElementById("marquee");
var newText;
do {
newText = await read(reader);
if (newText) {
marquee.innerText = trimText(newText, 180);
}
} while (newText !== null);
}
);
}
);
</script>
</body>
</html>