-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (47 loc) · 1.22 KB
/
index.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
51
52
53
54
const debug = require('debug')('gate-addon-sensortag');
const EventEmitter = require('events');
const SensorTag = require('@instathings/sensortag');
const enableSensors = require('./sensors/enable');
const setPeriod = require('./sensors/setPeriod');
const setListeners = require('./sensors/setListeners');
const notify = require('./sensors/notify');
class GateAddOnSensorTag extends EventEmitter {
constructor(allDevices) {
super();
this.data = {
accel: 0,
lux: 0,
hum: 0,
temp: 0,
pres: 0,
gyro: { x: 0, y: 0, z: 0 },
magn: { x: 0, y: 0, z: 0 },
};
this.knownDevices = allDevices.bluetooth || [];
}
init() {
debug('Discover start');
SensorTag.discover((sensorTag) => {
debug('Found one SensorTag');
sensorTag.connectAndSetup((err) => {
if (err) {
throw err;
}
enableSensors(sensorTag);
setPeriod(sensorTag);
notify(sensorTag);
setListeners.call(this, sensorTag);
this.start();
});
});
}
start(device) {
setInterval(() => {
debug(this.data);
this.emit('data', this.data);
}, 5000);
}
stop() { }
control() { }
}
module.exports = GateAddOnSensorTag;