Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
113 lines (92 loc) · 3.22 KB
/
Copy pathtest.js
File metadata and controls
113 lines (92 loc) · 3.22 KB
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
// tsc libomapi\libomapi.ts libomapi/omapi-test.ts -rootdir . --lib es2015,dom && node libomapi/omapi-test.js
// /usr/local/bin/tsc --lib es2015 libomapi.ts -rootdir .
/* eslint no-console: "off", new-cap: "off" */
var libomapi = require('./libomapi.js');
//import * as libomapi from './libomapi';
var om = new libomapi.Om();
function timeout(delay) {
return new Promise(resolve => setTimeout(resolve, delay));
}
function DumpDevice(id) {
console.log("----------");
console.log("Device: " + id);
console.log("OmGetBatteryLevel(" + id + ")");
var battery = om.OmGetBatteryLevel(id);
console.log("= " + battery);
console.log("OmGetVersion(" + id + ")");
var version = om.OmGetVersion(id)
console.log("= " + version);
/*
(async() => {
console.log("OmGetBatteryLevelAsync(" + id + ")");
var batteryAsync = await om.OmGetBatteryLevelAsync(id);
console.log("batt= " + batteryAsync);
console.log("OmGetVersionAsync(" + id + ")");
var versionAsync = await om.OmGetVersionAsync(id)
console.log("ver= " + versionAsync);
})().catch(err => {
console.error(err.stack);
});
*/
console.log("OmGetDataFilename(" + id + ")");
var filename = om.OmGetDataFilename(id)
console.log("= " + filename);
console.log("OmGetDevicePort(" + id + ")");
var port = om.OmGetDevicePort(id)
console.log("= " + port);
console.log("OmGetDevicePath(" + id + ")");
var path = om.OmGetDevicePath(id)
console.log("= " + path);
console.log("==========");
}
om.OmSetLogCallback(function(message) {
console.log("LOGCALLBACK: " + message);
})
om.OmSetDeviceCallback(function(deviceId, status) {
console.log("DEVICECALLBACK: " + deviceId + " (" + status + ")");
if (status === libomapi.OM_DEVICE_STATUS.OM_DEVICE_CONNECTED) {
DumpDevice(deviceId);
}
})
async function start() {
console.log("OmStartup()");
await om.OmStartupAsync(om.OM_VERSION);
console.log("OmGetDeviceIds()");
var deviceIds = om.OmGetDeviceIds();
console.log("IDs:", deviceIds);
for (var i = 0; i < deviceIds.length; i++) {
var id = deviceIds[i];
console.log("Device: " + id);
//await DumpDevice(id);
}
}
/*
async function doIdentify(id) {
const n = 6;
// Flash
for (var i = 0; i < n; i += 1) {
console.log("LED:", id, 5); // eslint-disable-line no-console
await om.OmSetLedAsync(id, 5); // eslint-disable-line no-await-in-loop
console.log("TIMEOUT1"); // eslint-disable-line no-console
await timeout(250); // eslint-disable-line no-await-in-loop
console.log("LED:", id, 7); // eslint-disable-line no-console
await om.OmSetLedAsync(id, 7); // eslint-disable-line no-await-in-loop
console.log("TIMEOUT2"); // eslint-disable-line no-console
await timeout(250); // eslint-disable-line no-await-in-loop
}
// Auto
console.log("RESET..."); // eslint-disable-line no-console
await om.OmSetLedAsync(id, -1);
}
*/
setTimeout(function() {
console.log("60s timeout expired");
console.log("OmShutdown()");
om.OmShutdown();
}, 60 * 1000);
/*
if (deviceIds.length > 0) {
doIdentify(deviceIds[0]);
}
*/
start();