-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio-scout.js
50 lines (38 loc) · 1.07 KB
/
gpio-scout.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
const config = require('./config');
const Scout = require(process.lynxari.scout);
const Gpio = require('./gpio');
module.exports = class GpioScout extends Scout {
constructor(opts) {
super();
if (typeof opts !== 'undefined') {
// copy all config options defined in the server
for (const key in opts) {
if (typeof opts[key] !== 'undefined') {
config[key] = opts[key];
}
}
}
if (config.name === undefined) { config.name = "GPIO" }
this.name = config.name;
this.gpio = new Gpio(config);
}
init(next) {
const query = this.server.where({name: this.name});
const self = this;
this.server.find(query, function(err, results) {
if (!err) {
if (results[0]) {
self.provision(results[0], self.gpio);
self.server.info('Provisioned known device ' + self.name);
} else {
self.discover(self.gpio);
self.server.info('Discovered new device ' + self.name);
}
}
else {
self.server.error(err);
}
});
next();
}
}