-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
64 lines (55 loc) · 1.59 KB
/
node_helper.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
55
56
57
58
59
60
61
62
63
64
/* Magic Mirror
* Node Helper: MMM-Hover
*
* By Dancj
* MIT Licensed.
*/
var NodeHelper = require("node_helper");
var Hover = require("hover-nodejs");
module.exports = NodeHelper.create({
start: function () {
this.started = false;
},
// Override socketNotificationReceived method.
/* socketNotificationReceived(notification, payload)
* This method is called when a socket notification arrives.
*
* argument notification string - The identifier of the noitication.
* argument payload mixed - The payload of the notification.
*/
socketNotificationReceived: function(notification, payload) {
if (notification === "CONFIG" && this.started == false) {
const self = this;
self.config = payload;
var i2cBus = 1;
var hover = new Hover(
self.config.i2cAddress,
self.config.pinTs,
self.config.pinReset,
i2cBus);
hover.init().then(function() {
if (self.config.debug) {
console.log("[Hover] board ready for input");
}
hover.listen(
function (event) {
if (self.config.debug) {
console.log("[Hover] handled event: " + event);
}
if (event.substr(0,3) === "tap") {
self.sendSocketNotification("TAP", event.substr(4));
} else if (event.substr(0,5) === "swipe"){
self.sendSocketNotification("SWIPE", event.substr(6));
} else {
console.log("[Hover] unknown event received from board: " + event);
}
},
self.config.pollRate || self.config.defaultRate
);
}, function (err) {
console.error("[Hover] Could not init hover board: " + err);
});
self.started = true;
}
}
});