forked from Megabytemb/kano-wand-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
40 lines (33 loc) · 897 Bytes
/
example.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
var noble = require('noble-mac');
const KanoWand = require('./index');
var wand = new KanoWand();
noble.on('stateChange', function(state) {
if (state === 'poweredOn') {
noble.startScanning();
} else {
noble.stopScanning();
}
});
noble.on('discover', function(peripheral) {
let deviceName = peripheral.advertisement.localName || "";
if (deviceName.startsWith("Kano-Wand")) {
noble.stopScanning();
console.log("foundWand");
peripheral.connect(function(error) {
wand.init(peripheral)
.then(()=> {
wand.vibrate(1);
});
});
}
});
wand.spells.subscribe((spell) => {
console.log(spell);
});
process.stdin.on('keypress', (str, key) => {
if (key.ctrl && key.name === 'c') {
process.exit();
} else {
wand.reset_position();
}
});