working next event line
This commit is contained in:
parent
1eeffaed4a
commit
26173b42ab
@ -18,4 +18,22 @@ module.exports = {
|
||||
pause: async (time) => {
|
||||
await new Promise(resolve => setTimeout(resolve, time));
|
||||
},
|
||||
nextEvent: async (time) => {
|
||||
|
||||
time = time.match(/.{11}$/gm)
|
||||
time = time[0].toLowerCase()
|
||||
|
||||
var hours = parseInt(time.substr(0, 2));
|
||||
if (time.indexOf('am') != -1 && hours == 12) {
|
||||
time = time.replace('12', '0');
|
||||
}
|
||||
if (time.indexOf('pm') != -1 && hours < 12) {
|
||||
time = time.replace(hours, (hours + 12));
|
||||
}
|
||||
|
||||
|
||||
time = time.replace(/(am|pm)/, '');
|
||||
time = time.replace(/ /g,'')
|
||||
return time.substring(0, time.length - 3);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
class globalVariables {
|
||||
waterOn = "";
|
||||
initialWater = "";
|
||||
waterNextEvent = "";
|
||||
}
|
||||
|
||||
module.exports = new globalVariables();
|
18
libs/lcd.js
18
libs/lcd.js
@ -2,7 +2,6 @@ const LCD = require('raspberrypi-liquid-crystal');
|
||||
const common = require('./common')
|
||||
const globalVars = require('./globalVars')
|
||||
const clock = require('./clock');
|
||||
const { time } = require('./clock');
|
||||
|
||||
const lcd = new LCD(1, 0x27, 20, 4);
|
||||
|
||||
@ -22,7 +21,7 @@ module.exports = {
|
||||
lcd.printLineSync(1, 'MiGenie Status')
|
||||
lcd.printLineSync(2, ' By Karl')
|
||||
await common.pause(3000)
|
||||
module.exports.heading('Hot Water')
|
||||
module.exports.heading('Water-')
|
||||
},
|
||||
heading: async (title) => {
|
||||
lcd.clearSync();
|
||||
@ -34,10 +33,17 @@ module.exports = {
|
||||
f = await clock.time()
|
||||
lcd.printSync(f)
|
||||
},
|
||||
heatingStatus: async (input) => {
|
||||
lcd.setCursorSync(0, 3);
|
||||
waterStatus: async (input) => {
|
||||
lcd.setCursorSync(6, 2);
|
||||
lcd.printSync(' ')
|
||||
lcd.setCursorSync(0, 3);
|
||||
lcd.printSync(' ' + input)
|
||||
lcd.setCursorSync(6, 2);
|
||||
lcd.printSync(input)
|
||||
},
|
||||
waterNextEvent: async (input) => {
|
||||
lcd.printLineSync(3, 'Next Event-')
|
||||
lcd.setCursorSync(11, 3);
|
||||
lcd.printSync(' ')
|
||||
lcd.setCursorSync(11, 3);
|
||||
lcd.printSync(input)
|
||||
},
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
const http = require('http')
|
||||
const globalVars = require('../libs/globalVars')
|
||||
const led = require('../libs/led')
|
||||
const common = require('../libs/common')
|
||||
|
||||
const lcd = require('../libs/lcd')
|
||||
|
||||
@ -23,29 +24,38 @@ module.exports = {
|
||||
});
|
||||
|
||||
// Once we're done streaming the response, parse it as json.
|
||||
response.on('end', function () {
|
||||
response.on('end',async function () {
|
||||
var data = JSON.parse(content);
|
||||
let waterOn = data.waterOn
|
||||
|
||||
var time = await common.nextEvent(data.nextScheduleEventUtcTime)
|
||||
|
||||
globalVars.waterNextEvent = time
|
||||
|
||||
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
||||
if (waterOn === 'true') {
|
||||
lcd.heatingStatus('Heating')
|
||||
lcd.waterStatus('Heating')
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
led.set('red')
|
||||
globalVars.waterOn = waterOn
|
||||
} else {
|
||||
lcd.heatingStatus('Not Heating')
|
||||
lcd.waterStatus('Not Heating')
|
||||
led.set('blue')
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
}
|
||||
} else {
|
||||
if (waterOn != globalVars.waterOn) {
|
||||
if (waterOn === 'true') {
|
||||
lcd.heatingStatus('Heating')
|
||||
lcd.waterStatus('Heating')
|
||||
led.set('red')
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
} else {
|
||||
lcd.heatingStatus('Not Heating')
|
||||
lcd.waterStatus('Not Heating')
|
||||
led.set('blue')
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,9 +64,9 @@ module.exports = {
|
||||
|
||||
// Report errors
|
||||
request.on('error', function (error) {
|
||||
lcd.heatingStatus('Error')
|
||||
lcd.waterStatus('Error')
|
||||
led.set('green')
|
||||
lcd.heatingStatus('Error No Data')
|
||||
lcd.waterStatus('Error No Data')
|
||||
globalVars.waterOn = 'error'
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user