-
Notifications
You must be signed in to change notification settings - Fork 7
/
stickos-basic.manual.html
346 lines (310 loc) · 12 KB
/
stickos-basic.manual.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html>
<html lang="en">
<!-- StickOS® BASIC -->
<!-- See: https://wicg.github.io/webusb/ -->
<!-- See: https://wicg.github.io/serial/ -->
<!-- top right bottom left -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=1870">
<title>StickOS® BASIC</title>
<style>
body,select,input { background: #ededed }
pre { white-space: pre-wrap; word-wrap: break-word; }
a { text-decoration: none; }
#results { line-height: 1.2; }
#command { width: 96%; font-size:120%; }
#copyright { font-size:65%; padding: 0px; margin: 0px; }
#help { font-size:75%; }
* { overflow-wrap: anywhere; word-wrap: anywhere; }
button { overflow-wrap: normal; word-wrap: normal; }
html,button,input,select { font: 34px Arial, Helvetica, sans-serif; padding: 10px 10px 10px 10px; margin: 0px 0px 10px 0px; }
@media(min-width:80em){ html,button,input { font: 22px Arial, Helvetica, sans-serif; padding: 10px 10px 10px 10px; margin: 0px 0px 10px 0px; } }
@supports(-webkit-touch-callout:none) { button,input { -webkit-appearance: none; border-radius: 2px; } }
body,html { margin: 0px; }
.dark { filter: invert(1); background: #121212; }
</style>
</head>
<body onload='Body()'>
<h1 id="h1">StickOS® BASIC</h1>
<div id="config">
<button type='button'
onclick="if (/\b(Linux|CrOS|Windows)\b/.test(navigator.userAgent) && ! navigator.userAgent.match(/android/i)) {
Comm();
} else {
Usb();
}">Start Connect</button>
<button type='button' id="start1" hidden=true onclick="Comm();">Start Connect Comm</button>
<button type='button' id="start2" hidden=true onclick="Usb();">Start Connect USB</button>
</div>
<div id="help">
<i>
To connect this user interface web-page to your Flea-Scope:
<ol start=0>
<li>be sure you are using a <a href="https://en.wikipedia.org/wiki/Chromium_(web_browser)" target="_blank">Chromium-based web browser</a> that supports <a href="https://wicg.github.io/webusb/" target="_blank">WebUSB</a> and/or <a href="https://wicg.github.io/serial/" target="_blank">Web Serial</a></li>
<li>plug Flea-Scope's micro-USB connector into your computer, tablet, or phone, using a <u>USB data cable</u></li>
<ul>
<li>LED e1 (blue) should blink at 2Hz for 2 blinks, and then settle to a 1Hz blink while Flea-Scope is idle</li>
</ul>
<li><u>click or tap</u> the "Start Connect" button above to authorize web browser access to a selected USB device</li>
<ul>
<li>the web browser will open a WebUSB or Web Serial dialog box</li>
<li>you should see your Flea-Scope device listed in the WebUSB or Web Serial dialog box</li>
</ul>
<li><b><u>click or tap</u> the desired Flea-Scope USB device or serial port (or customized hostname) to select it!</b></li>
<li>finally, <u>click or tap</u> "Connect" to confirm the selected Flea-Scope USB device!</li>
</ol>
</i>
</div>
<pre id='results'></pre>
<input id='command' name='command' disabled='true' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'/>
<br>
<button type='button' onclick='Enter();'>Enter</button>
<button type='button' onclick='Send(String.fromCharCode(3));'>Ctrl-C</button>
<button type='button' onclick='Send(String.fromCharCode(4));'>Ctrl-D</button>
<button type='button' onclick='Paste();'>Paste</button>
<button type='button' onclick='Clear();'>Clear</button>
<button type="button" id="bw" onclick="document.querySelector('body').classList.toggle('dark');">bw</button>
<p id='copyright'>
<a href=https://rtestardi.github.io/pages target=_blank>rtestardi's pages</a>
<a href=https://rtestardi.github.io/StickOS/downloads/quickref.v1.90.pdf target=_blank>StickOS® BASIC Quick Reference Guide</a>
<a href=https://rtestardi.github.io/StickOS/downloads/stickos.v1.90.pdf target=_blank>StickOS® BASIC User’s Guide</a>
<a href=https://rtestardi.github.io/StickOS target=_blank>StickOS® website</a>
<a href=https://github.com/rtestardi/usbte target=_blank>github.com/rtestardi/usbte</a>
<a href=https://github.com/rtestardi/StickOS2 target=_blank>github.com/rtestardi/StickOS2</a>
<script>
'use strict';
var webpage;
var usb;
var comm;
var epin = 2;
var epout = 3;
var reader;
var writer;
var enc = new TextEncoder();
var dec = new TextDecoder();
var lines = [];
var last;
var cursor = 0;
var first = false;
var hostname = "";
// the user loaded the webpage; set up keyboard listeners
function Body()
{
webpage = location.pathname.split("/").slice(-1)[0];
if (webpage.match(/manual/)) {
document.getElementById("start1").hidden = false;
document.getElementById("start2").hidden = false;
document.getElementById("help").innerHTML += "<p>" + navigator.userAgent;
for (var vv in navigator) {
document.getElementById("help").innerHTML += vv + ", ";
}
document.getElementById("help").innerHTML += "</p>";
}
document.body.addEventListener("keydown", function(event) {
if ((event.keyCode === 67 || event.keyCode === 68) && event.ctrlKey && document.activeElement === document.getElementById("command")) {
// ctrl-c or ctrl-d in command line -- flow thru to device
event.preventDefault();
event.stopPropagation();
Send(String.fromCharCode(event.keyCode - 64));
}
if (event.keyCode === 13) {
// enter -- run the command line
event.preventDefault();
Enter();
}
if (event.keyCode === 40) {
// down arrow -- recall a newer command line
event.preventDefault();
UpDown(false);
}
if (event.keyCode === 38) {
// up arrow -- recall an older command line
event.preventDefault();
UpDown(true);
}
});
}
// the user wants to connect to a USB device's bulk endpoints directly
async function Usb()
{
var filter = [
{ vendorId: 0x0403, productId: 0xA660 },
{ vendorId: 0x1b4f, productId: 0xA660 },
{ vendorId: 0x1b4f, productId: 0xE66E },
{ vendorId: 0x04D8, productId: 0xE66E },
];
usb = undefined;
comm = undefined;
reader = undefined;
writer = undefined;
if ('usb' in navigator) {
try {
usb = await navigator.usb.requestDevice({ filters: filter });
await usb.open();
await usb.selectConfiguration(1);
await usb.claimInterface(1);
document.getElementById("config").hidden = true;
document.getElementById("help").hidden = true;
Send("\r");
Send("echo on\r");
Send("prompt on\r");
Send("hostname\r");
setTimeout(Receive, 1);
document.getElementById("command").disabled = false;
document.getElementById("command").focus();
} catch(err) {
document.getElementById("help").innerHTML += "<p><font color='red'>" + err.message.replace(/</g,'<').replace(/>/g,'>') + "</font></p>";
}
} else {
document.getElementById("help").innerHTML += "<p><font color='red'>WebUSB API not found.</font></p>";
}
}
// the user wants to connect to an emulated COM port
async function Comm()
{
var filter = [
{ usbVendorId: 0x0403, usbProductId: 0xA660 },
{ usbVendorId: 0x1b4f, usbProductId: 0xA660 },
{ usbVendorId: 0x1b4f, usbProductId: 0xE66E },
{ usbVendorId: 0x04D8, usbProductId: 0xE66E },
];
usb = undefined;
comm = undefined;
reader = undefined;
writer = undefined;
if ('serial' in navigator) {
try {
comm = await navigator.serial.requestPort({ filters: filter });
await comm.open({ baudRate: 115200, bufferSize: 1024 });
reader = comm.readable.getReader();
writer = comm.writable.getWriter();
document.getElementById("config").hidden = true;
document.getElementById("help").hidden = true;
Send("\r");
Send("echo on\r");
Send("prompt on\r");
Send("hostname\r");
setTimeout(Receive, 1);
document.getElementById("command").disabled = false;
document.getElementById("command").focus();
} catch(err) {
document.getElementById("help").innerHTML += "<p><font color='red'>" + err.message.replace(/</g,'<').replace(/>/g,'>') + "</font></p>";
}
} else {
document.getElementById("help").innerHTML += "<p><font color='red'>Web Serial API not found.</font></p>";
}
}
// receive a string from the device
async function Receive()
{
var j;
var result;
var str;
var temp;
if (usb) {
result = await usb.transferIn(epin, 1024);
str = dec.decode(result.data.buffer);
} else {
result = await reader.read();
str = dec.decode(result.value);
}
if (str.match(/\033[[]2J/)) {
// clear screen on cls XXX -- misses fragmented escape
Clear();
} else {
// gather data
document.getElementById("results").innerHTML += str.replace(/</g,'<').replace(/>/g,'>').replace(/\n/g,'');
// parse gathered data at final prompt up to preceeding prompt
temp = document.getElementById("results").innerHTML;
temp = temp.split(/\r?\n|\r|\n/g);
if (temp[temp.length-1].match(/^> $/)) {
for (j = temp.length-2; j >= 0; j--) {
if (temp[j].match(/^>/)) {
break;
}
}
if (j >= 0) {
temp = temp.slice(j, temp.length);
if (hostname == "" && temp[0].match(/hostname/)) {
hostname = temp[1];
if (hostname != "Flea-Scope") {
document.getElementById("h1").innerHTML += " (" + hostname + ")";
document.title += " (" + hostname + ")";
}
} else if (last.match(/^ *edit/) && temp[0].match(/list/)) {
if (temp[1].match(/^ *[1-9]/)) {
document.getElementById("command").value = temp[1].replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').trim();
}
}
}
}
}
document.getElementById("command").scrollIntoView();
setTimeout(Receive, 1);
}
// send a string to the device
async function Send(str)
{
last = str;
str = str.replace(/^ *edit/, 'list');
if (usb) {
await usb.transferOut(epout, enc.encode(str).buffer);
} else {
await writer.write(enc.encode(str).buffer);
}
document.getElementById("command").value = "";
document.getElementById("command").focus();
}
// the user clicked the Enter button; run the user command line
async function Enter()
{
var str = document.getElementById("command").value;
if (str.length && (! lines.length || str != lines[lines.length-1])) {
lines.push(str);
}
Send(str + "\r");
first = true;
}
// the user typed up-arrow or down-arrow to recall an older or newer command line
function UpDown(up)
{
if (first && up) {
// an initial up-arrow recalls the last hyperlink from the results history
cursor = 0;
}
if (lines.length) {
// recall the requested hyperlink from the results history to the equation line
if (up) {
// older
cursor = (cursor+lines.length-1)%lines.length;
} else {
// newer
cursor = (cursor+1)%lines.length;
}
document.getElementById("command").value = lines[cursor];
first = false;
}
}
// the user clicked the Paste button; paste the clipboard into the command line
async function Paste()
{
var text = await navigator.clipboard.readText();
Send(text + "\r");
}
// the user clicked the Clear button; clear the command, results, and history list
async function Clear()
{
document.getElementById("results").innerHTML = "";
document.getElementById("command").value = "";
document.getElementById("command").focus();
//lines = [];
}
</script>
</body>
</html>