-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathserial_test.js.test
50 lines (43 loc) · 1.2 KB
/
serial_test.js.test
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
/*
Gordon Williams (gw@pur3.co.uk)
Simple loopback test
*/
(function() {
function init() {
}
var getPorts = function(callback) {
callback([{path:"TEST", // path passed to 'open' (and displayed to user)
description:"test", // description displayed to user
type:"test", // bluetooth|usb|socket - used to show icon in UI
// autoconnect : true // automatically conect to this (without the connect menu)
}], true/*instantPorts*/);
};
var rcb, dcb;
var openSerial=function(serialPort, openCallback, receiveCallback, disconnectCallback) {
rcb = receiveCallback;
dcb = disconnectCallback;
setTimeout(function() {
openCallback({ hello : 42 });
}, 500);
};
var closeSerial = function() {
if (dcb) {
dcb();
dcb = rcb = undefined;
}
};
var writeSerial = function(data, callback) {
callback();
setTimeout(function() {
rcb(Espruino.Core.Utils.stringToArrayBuffer(data));
}, 10);
};
Espruino.Core.Serial.devices.push({
"name" : "Test",
"init" : init,
"getPorts": getPorts,
"open": openSerial,
"write": writeSerial,
"close": closeSerial,
});
})();