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