-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
executable file
·46 lines (40 loc) · 1.34 KB
/
app.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
#!/usr/bin/env node
const { program } = require('commander');
const { scan_devices, calibrate, run, debug, run_active } = require('./ble');
program
.option('--calibrate', 'calibrate the ble rssi values', 'first_time')
.option('--start', 'start scanning')
.option('--threshold <int>', 'Set the rssi threshold', -70)
.option('--debug', 'debug uuid')
.option('--local-name <name> ', 'debug uuid')
.option('--uuid <uuid> ', 'debug uuid')
.option('--active <uuid> ', 'active mode', false);
program.parse(process.argv);
const options = program.opts();
(async () => {
if (options.start) {
if (Math.abs(options.threshold) < 50) {
console.log('Invalid threshold, must be lower than -50');
process.exit();
}
if (!options.uuid && !options.localName) {
console.log('Provide a name or uuid of the device');
process.exit();
}
if (options.active) {
await run_active(options.uuid, options.localName, options.threshold);
} else {
await run(options.uuid, options.localName, options.threshold);
}
} else if (options.debug) {
debug(options.debug);
} else if (options.calibrate) {
if (options.uuid || options.localName) {
console.log('Calibrating for device ', options.uuid || options.localName);
calibrate(options.uuid, options.localName);
} else {
console.log('scan all devices and print it');
scan_devices();
}
}
})();