-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathowon.js
50 lines (42 loc) · 1.3 KB
/
owon.js
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
'use strict';
const log = require("loglevel");
const BT = require("./webbluetooth");
const utils = require("./utils");
const State = BT.State;
const btState = BT.btState;
async function Start() {
log.info("Start called...");
if (!btState.started) {
btState.state = State.NOT_CONNECTED;
BT.stateMachine(); // Start it
}
else if (btState.state == State.ERROR) {
btState.state = State.NOT_CONNECTED; // Try to restart
}
await utils.waitFor(() => btState.state == State.IDLE || btState.state == State.STOPPED);
log.info("Pairing completed, state :", btState.state);
return (btState.state != State.STOPPED);
}
async function Stop() {
log.info("Stop request received");
btState.stopRequest = true;
await utils.sleep(100);
while(btState.started || (btState.state != State.STOPPED && btState.state != State.NOT_CONNECTED))
{
btState.stopRequest = true;
await utils.sleep(100);
}
btState.command = null;
btState.stopRequest = false;
log.warn("Stopped on request.");
return true;
}
function SetLogLevel(level) {
log.setLevel(level, false);
}
exports.Start = Start;
exports.Stop = Stop;
exports.SetLogLevel = SetLogLevel;
exports.btState = BT.btState;
exports.State = BT.State;
exports.SetPacketLog = BT.SetPacketLog;