forked from node-red/node-red-nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mraa-gpio-led.js
82 lines (80 loc) · 3.06 KB
/
mraa-gpio-led.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module.exports = function(RED) {
var m = require('mraa');
function LEDNode(n) {
RED.nodes.createNode(this, n);
this.pin = Number(n.pin);
this.led0 = new m.Led(0); /*user-led1-green*/
this.led1 = new m.Led(1); /*user-led1-red*/
this.led2 = new m.Led(2); /*user-led2-green*/
this.led3 = new m.Led(3); /*user-led2-red*/
this.on("input", function(msg) {
if (msg.payload == "1") {
switch(this.pin)
{
case 0: /*User0 Led Green*/
this.led0.setBrightness(1);
break;
case 1: /*User0 Led Red*/
this.led1.setBrightness(1);
break;
case 2: /*User0 Orange*/
this.led0.setBrightness(1);
this.led1.setBrightness(1);
break;
case 3: /*User1 Led Green*/
this.led2.setBrightness(1);
break;
case 4: /*User1 Led Red*/
this.led3.setBrightness(1);
break;
case 5: /*User1 Orange*/
this.led2.setBrightness(1);
this.led3.setBrightness(1);
break;
default:
break;
}
}
else {
switch(this.pin)
{
case 0: /*User1 Led Green*/
this.led0.setBrightness(0);
break;
case 1: /*User1 Led Red*/
this.led1.setBrightness(0);
break;
case 2: /*User1 Orange*/
this.led0.setBrightness(0);
this.led1.setBrightness(0);
break;
case 3: /*User2 Led Green*/
this.led2.setBrightness(0);
break;
case 4: /*User2 Led Red*/
this.led3.setBrightness(0);
break;
case 5: /*User2 Orange*/
this.led2.setBrightness(0);
this.led3.setBrightness(0);
break;
default:
break;
}
}
});
this.on('close', function() {
this.led0.close();
this.led1.close();
this.led2.close();
this.led3.close();
});
}
RED.nodes.registerType("mraa-gpio-led", LEDNode);
RED.httpAdmin.get('/mraa-gpio/:id', RED.auth.needsPermission('mraa-gpio.read'), function(req,res) {
res.json(m.getPlatformType());
});
RED.httpAdmin.get('/mraa-version/:id', RED.auth.needsPermission('mraa-version.read'), function(req,res) {
res.json(m.getVersion());
});
}