-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinio.js
57 lines (42 loc) · 1.15 KB
/
pinio.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
'use strict';
var ChildProcess = require('child_process');
function PinIO(pin){
this.pin = pin;
this.lastOn = + Date();
this.lastOff = + Date();
//this.setRelayOff();
}
PinIO.prototype.getStatus = function(){
return this.status;
};
PinIO.prototype.isOn = function(){
return this.status === 1;
};
PinIO.prototype.isOff = function(){
return this.status === 0;
};
PinIO.prototype.getTimeOn = function(){
return + new Date() - this.lastOn;
};
PinIO.prototype.getTimeOff = function(){
return + new Date() - this.lastOff;
};
PinIO.prototype.getMinutesOn = function(){
return this.isOn() * (+ new Date() - this.lastOn) / 60000;
};
PinIO.prototype.getMinutesOff = function(){
return this.isOff() * (+ new Date() - this.lastOff) / 60000;
};
PinIO.prototype.setRelayOn = function(){
var cmd = "gpioctl dirout-high " + this.pin;
ChildProcess.execSync(cmd);
this.status = 1;
this.lastOn = + new Date();
};
PinIO.prototype.setRelayOff = function(){
var cmd = "gpioctl dirout-low " + this.pin;
ChildProcess.execSync(cmd);
this.status = 0;
this.lastOff = + new Date();
};
module.exports = PinIO;