This repository was archived by the owner on Aug 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMMM-Swipe.js
More file actions
95 lines (90 loc) · 2.91 KB
/
Copy pathMMM-Swipe.js
File metadata and controls
95 lines (90 loc) · 2.91 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* Magic Mirror
* Module: MMM-Swipe
*
* By Luke Moch
* MIT Licensed
*/
Module.register("MMM-Swipe", {
defaults : {
echoLeftPin: "",
triggerLeftPin: "",
echoRightPin: "",
triggerRightPin: "",
leftDistance: "",
rightDistance: "",
useAsButton: false,
buttonPin: "",
sensorTimeout: 500,
animationSpeed: 200,
sampleInterval: 300,
swipeSpeed: 1000,
verbose: false,
calibrate: true
},
start: function() {
var self = this;
var previousNote = null;
var notificationData = null;
var notificationInfo = null;
var displayData = null;
var currentData = 0;
console.log('Starting Module: ' + this.name);
if(self.config.useAsButton === true && self.config.buttonPin < 27) {
self.sendSocketNotification('INIT_BUTTON', self.config.buttonPin);
}
if(self.config.echoLeftPin < 27 && self.config.echoRightPin < 27 && self.config.triggerLeftPin < 27 && self.config.triggerRightPin < 27) {
setInterval(function () {
if (self.currentData === 1) {
if(self.notificationInfo === 'MOVEMENT') {
self.sendNotification(self.notificationInfo, self.notificationData);
if(self.notificationData === 'Press' && self.config.useAsButton === true) {
self.sendSocketNotification('PRESS', self.config.buttonPin);
}
}
self.displayData = self.notificationData;
if (self.config.verbose === true || self.config.calibrate === true) {
self.currentData = 2;
} else {
self.currentData = 0;
}
} else if (self.config.calibrate === true) {
self.sendSocketNotification('CALIBRATE', self.config);
} else {
self.currentData = 0;
self.notificationInfo = null;
self.displayData = null;
self.sendSocketNotification('INIT', self.config);
}
if (self.currentData === 2) {
self.updateDom(self.config.animationSpeed);
self.currentData = 0;
}
}, self.config.sampleInterval);
} else {
console.log("Improper Pin configuration. Please use BCM Numbering");
}
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'CALIBRATION') {
this.notificationData = "<table border=\"1\" cellpadding=\"5\"><tr align=\"center\"><th>Left</td><th>Right</td></tr><tr align=\"center\"><td>" + payload[0] + "</td><td>" + payload[1] + "</td></tr></table>";
this.currentData = 1;
} else if(notification === 'MOVEMENT' && this.previousNote !== 'MOVEMENT' && this.currentData === 0) {
this.previousNote = notification;
this.notificationData = payload;
this.notificationInfo = notification;
this.currentData = 1;
} else if(notification === 'STATUS' && this.currentData === 0) {
this.previousNote = notification;
this.notificationData = payload;
this.currentData = 1;
}
},
getDom: function() {
var wrapper = document.createElement("div");
if(this.displayData !== undefined) {
wrapper.innerHTML = this.displayData;
wrapper.className = "dimmed light small";
}
return wrapper;
}
});