diff --git a/app.js b/app.js index 907c35f..986ee4b 100644 --- a/app.js +++ b/app.js @@ -2,12 +2,15 @@ const { Gpio } = require('onoff'); const poll = require('./poll') const common = require('./libs/common') const globalVars = require('./libs/globalVars') +const lcd = require('./libs/lcd') +lcd.heading() +// lcd.time() poll.setInterval const switchIn = new Gpio('17', 'in', 'both'); -switchIn.watch((err, value) => { +switchIn.watch( async (err, value) => { if (err) { console.log('Error', err); } diff --git a/lcd.js b/lcd.js new file mode 100644 index 0000000..b8f119d --- /dev/null +++ b/lcd.js @@ -0,0 +1,11 @@ +const LCD = require('raspberrypi-liquid-crystal'); + +const lcd = new LCD(1, 0x27, 20, 4); + +lcd.beginSync(); + +lcd.clearSync(); +lcd.printLineSync(0, 'Welcome to KWorld'); +lcd.printLineSync(1, ' then'); +lcd.printLineSync(2, 'This is line 3'); +lcd.printLineSync(3, 'This is line 4'); \ No newline at end of file diff --git a/libs/lcd.js b/libs/lcd.js new file mode 100644 index 0000000..8bd57cc --- /dev/null +++ b/libs/lcd.js @@ -0,0 +1,22 @@ +const LCD = require('raspberrypi-liquid-crystal'); + +const lcd = new LCD(1, 0x27, 20, 4); + +lcd.beginSync(); + +module.exports = { + heading: async () => { + lcd.clearSync(); + lcd.printLineSync(0, 'MiGenie Hot Water') + lcd.printLineSync(1, ' By Karl') + }, + time: async () => { + lcd.setCursorSync(10,2); + lcd.printSync('time') + }, + updateScreen: async (input) => { + lcd.setCursorSync(3, 0); + lcd.printLineSync(3, input) + }, + +} \ No newline at end of file diff --git a/poll.js b/poll.js index a3e9fde..ea7d768 100644 --- a/poll.js +++ b/poll.js @@ -6,6 +6,8 @@ const redLED = new Gpio('4', 'out'); const blueLED = new Gpio('27', 'out') const greenLED = new Gpio('22', 'out') +const lcd = require('./libs/lcd') + setInterval(function () { var rest_options = { @@ -29,11 +31,13 @@ setInterval(function () { let waterOn = data.waterOn globalVars.waterOn = waterOn if (waterOn === 'true') { + lcd.updateScreen('Heating') redLED.writeSync(1) blueLED.writeSync(0) greenLED.writeSync(0) } else { + lcd.updateScreen('Not Heating') blueLED.writeSync(1) redLED.writeSync(0) greenLED.writeSync(0) @@ -44,6 +48,7 @@ setInterval(function () { // Report errors request.on('error', function (error) { + lcd.updateScreen('Error') redLED.writeSync(0) blueLED.writeSync(0) greenLED.writeSync(1) diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..7061074 --- /dev/null +++ b/public/index.html @@ -0,0 +1,24 @@ + + +
+ +