-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
250 lines (209 loc) · 6.87 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!-- nRFConnect -->
<!-- https://medium.com/@j.salonen/building-a-progressive-web-app-for-communicating-with-a-bluetooth-low-energy-device-e1e0a7bd2622 -->
<!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" />
<title>Revopoint DualAxis Turntable</title>
</head>
<body>
<button onclick="connect()">Connect</button>
<div id="control" style="background-color: bisque">
<p>Rotate</p>
<p>
<button id="ct_backward"> ←</button>
<input type="text" id="ct_turnangle" value="10" />
<button id="ct_forward">→</button>
<button onclick="bluetoothSend('+CT,TURNANGLE=360;')">360° (r)</button>
<button onclick="bluetoothSend('+CT,STOP;')">Stop Rotation (e)</button>
</p>
<p>Tilt</p>
<button id="cr_backward">+</button>
<input type="text" id="cr_turnangle" value="5" />
<button id="cr_forward">-</button>
<button id="cr_zero">To Zero (q)</button> - (w) (s) are singlestep
</div>
<div id="scan_proc" style="background-color: aquamarine">
<p>
Turnangle per Step
<input type="text" id="sp_turnangle" value="10" />
</p>
<p>
Pause between move in ms
<input type="text" id="sp_pause" value="2500" />
</p>
<p>How often: <input type="text" id="sp_steps" value="36" /></p>
<p>
<button id="sp_start">sp_start</button>
</p>
<p>
<button id="sp_pause">sp_pause</button>
</p>
<p>
<button id="sp_stop">sp_stop</button>
</p>
<p>
<button id="sp_step_forward">sp_step_forward</button>
</p>
<p>
<button id="sp_step_back">sp_step_back</button>
</p>
<p id="sp_status" style="color:red;"></p>
</div>
<div id="info" style="background-color:greenyellow">
<p>Rotations Speed</p>
<input type="range" min="35.64" max="100" value="35.64" id="rotation_speed" onchange="set_rotation_speed(this)"
style="direction: rtl; width: 400px" />
</div>
<script>
/**
* Mit nRFConnect verbinden
* Services anschauen und die wo man braucht beim verbinden angeben
* Schauen in welchen PrimaryService der Befehl / Characteristic geschrieben werden muss
**/
let server = false;
let tiltvalue = 0;
let sp_current_step = 0;
let spInterval = false;
async function connect() {
const device = await navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: [0xffe0, 0xffe1],
});
server = await device.gatt.connect();
console.log("Connected! Server: ", server);
return server;
}
async function bluetoothSend(cmd) {
var enc = new TextEncoder();
const service = await server.getPrimaryService(0xffe0);
const characteristic = await service.getCharacteristic(0xffe1);
await characteristic.writeValue(enc.encode(cmd));
var read = await characteristic.readValue();
var read_string = await new TextDecoder().decode(read);
console.log(read_string);
return await read_string;
}
function set_rotation_speed(event) {
console.log(`+CT,TURNSPEED=${event.value};`);
bluetoothSend(`+CT,TURNSPEED=${event.value};`);
}
document.getElementById("sp_start").addEventListener("click", (event) => {
sp_current_step = 0;
document.getElementById('sp_status').innerHTML = `Starting Interval`;
spInterval = setInterval(() => {
sp_current_step++;
bluetoothSend(
`+CT,TURNANGLE=${document.getElementById("sp_turnangle").value};`
);
document.getElementById('sp_status').innerHTML = `Step: ${sp_current_step}`;
if (
sp_current_step ==
parseInt(document.getElementById("sp_steps").value)
) {
clearInterval(spInterval);
document.getElementById('sp_status').innerHTML = '';
}
}, parseInt(document.getElementById("sp_pause").value));
});
document.getElementById("sp_stop").addEventListener("click", (event) => {
sp_current_step = 0;
document.getElementById('sp_status').innerHTML = '';
clearInterval(spInterval);
});
document.getElementById("sp_pause").addEventListener("click", (event) => {
clearInterval(spInterval);
});
document
.getElementById("sp_step_back")
.addEventListener("click", (event) => {
bluetoothSend(
`+CT,TURNANGLE=-${document.getElementById("sp_turnangle").value};`
);
});
document
.getElementById("sp_step_forward")
.addEventListener("click", (event) => {
bluetoothSend(
`+CT,TURNANGLE=${document.getElementById("sp_turnangle").value};`
);
});
document
.getElementById("ct_forward")
.addEventListener("click", (event) => {
bluetoothSend(
`+CT,TURNANGLE=${document.getElementById("ct_turnangle").value};`
);
});
document
.getElementById("ct_backward")
.addEventListener("click", (event) => {
bluetoothSend(
`+CT,TURNANGLE=-${document.getElementById("ct_turnangle").value};`
);
});
document
.getElementById("cr_forward")
.addEventListener("click", (event) => {
bluetoothSend(
`+CR,TILTVALUE=${document.getElementById("cr_turnangle").value};`
);
});
document
.getElementById("cr_backward")
.addEventListener("click", (event) => {
bluetoothSend(
`+CR,TILTVALUE=-${document.getElementById("cr_turnangle").value};`
);
});
document.getElementById("cr_zero").addEventListener("click", (event) => {
bluetoothSend(`+CR,TILTVALUE=0;`);
tiltvalue = 0;
});
document.addEventListener("keydown", (e) => {
if (!e.repeat) {
console.log(`Key "${e.key}" pressed [event: keydown]`);
} else {
console.log(`Key "${e.key}" repeating [event: keydown]`);
}
switch (e.key) {
case "d":
bluetoothSend("+CT,TURNANGLE=15;");
break;
case "a":
bluetoothSend("+CT,TURNANGLE=-15;");
break;
case "w":
tiltvalue = tiltvalue + 1;
if (tiltvalue > 30) {
tiltvalue = 30;
}
bluetoothSend(`+CR,TILTVALUE=${tiltvalue};`);
break;
case "s":
tiltvalue = tiltvalue + -1;
if (tiltvalue < -30) {
tiltvalue = -30;
}
console.log(tiltvalue);
bluetoothSend(`+CR,TILTVALUE=${tiltvalue};`);
break;
case "e":
bluetoothSend('+CT,STOP;')
break;
case "q":
bluetoothSend(`+CR,TILTVALUE=0;`);
tiltvalue = 0;
break;
case "r":
bluetoothSend(`+CT,TURNCONTINUE=-1;`);
break;
default:
break;
}
});
</script>
</body>
</html>