-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
88 lines (81 loc) · 2.36 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
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width">
<title>PybricksHub test</title>
</head><body>
<h1>PybricksHub test</h1>
<button id=btnconnect>connect</button>
<button id=btndisconnect>disconnect</button>
<button id=btnrepl>REPL</button>
<br>
<textarea id=taout></textarea><br>
<input id=inp><button id=btnsend>send</button><button id=btnclear>clear</button><br>
<textarea id=taprog>from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
hub = PrimeHub()
hub.light.on(Color.RED)
hub.display.off()
for i in range(0, 4):
hub.display.pixel(i, i, 100)
wait(500)
</textarea><br>
<button id=btnset>set program</button>
<button id=btnstart>start program</button>
<button id=btnstop>stop program</button>
<style>
* {
box-sizing: border-box;
}
body {
margin: 1em;
}
textarea {
width: 100%;
height: 10em;
margin: .5em 0;
padding: .2em;
}
</style>
<script type="module">
import { PybricksHub } from "./PybricksHub.js";
const hub = new PybricksHub();
hub.setReceiver(s => {
taout.value += s;
taout.scrollTop = taout.scrollHeight;
});
btnconnect.onclick = async () => {
await hub.connect();
await hub.startREPL();
};
btndisconnect.onclick = async () => {
await hub.disconnect();
};
btnsend.onclick = async () => {
const s = inp.value;
await hub.send(s + "\r\n");
inp.value = "";
};
btnclear.onclick = async () => {
taout.value = "";
};
btnrepl.onclick = async () => {
await hub.stopProgram();
await hub.startREPL();
};
btnstop.onclick = async () => {
await hub.stopProgram();
};
btnstart.onclick = async () => {
await hub.stopProgram();
await hub.startProgram();
};
btnset.onclick = async () => {
await hub.stopProgram();
await hub.setProgram(taprog.value);
};
</script>
<hr>
docs: <a href=https://docs.pybricks.com/en/latest/>Pybricks Documentation — pybricks v3.2.0 documentation</a><br>
fimware: <a href=https://code4fukui.github.io/pybricks-firmware/>install Pybrics firmawre</a><br>
<a href="https://github.com/code4fukui/PybricksHub.js/">src on GitHub</a> (forked from <a href=https://github.com/pybricks/pybricks-code>pybricks-code</a> in <a href=https://pybricks.com/>Pybricks</a>)<br>