forked from johnty/node-red-contrib-i2clcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i2clcd.js
55 lines (43 loc) · 1.46 KB
/
i2clcd.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
module.exports = function(RED) {
LCD = require('i2c-lcd');
var lcd;
function initLCD() {
lcd.init();
};
function LcdNode(config) {
console.log("creating LCD node");
RED.nodes.createNode(this,config);
var node = this;
this.LCD_ADDR = parseInt(config.addr);
console.log("LCD node init @ i2c addr:" + this.LCD_ADDR);
lcd = new LCD("/dev/i2c-1",this.LCD_ADDR);
initLCD();
this.on('input', function(msg) {
console.log("LCD input "+msg.topic);
if (msg.topic.localeCompare("init") == 0) {
lcd.init();
}
if (msg.topic.localeCompare("clear") == 0) {
lcd.clear();
}
if (msg.topic.localeCompare("line1") == 0) {
lcd.setCursor(0,0).then(function() {
lcd.print(msg.payload); });
}
if (msg.topic.localeCompare("line2") == 0) {
lcd.setCursor(0,1).then(function() {
lcd.print(msg.payload); });
}
if (msg.topic.localeCompare("line3") == 0) {
lcd.setCursor(0,2).then(function() {
lcd.print(msg.payload); });
}
if (msg.topic.localeCompare("line4") == 0) {
lcd.setCursor(0,3).then(function() {
lcd.print(msg.payload); });
}
node.send(msg); //pass message through
});
}
RED.nodes.registerType("i2clcd",LcdNode);
}