101 lines
3.6 KiB
JavaScript
101 lines
3.6 KiB
JavaScript
const LCD = require('raspberrypi-liquid-crystal');
|
|
const common = require('./common')
|
|
const globalVars = require('./globalVars')
|
|
const clock = require('./clock');
|
|
var commaNumber = require('comma-number')
|
|
|
|
const lcd = new LCD(1, 0x27, 20, 4);
|
|
|
|
lcd.beginSync();
|
|
|
|
module.exports = {
|
|
clearScreen: async () => {
|
|
lcd.clearSync();
|
|
},
|
|
clearLine: async (line) => {
|
|
line = line - 1
|
|
lcd.setCursorSync(0, line);
|
|
lcd.printSync(' ')
|
|
},
|
|
intro: async () => {
|
|
lcd.clearSync();
|
|
lcd.printLineSync(1, 'House Status')
|
|
lcd.setCursorSync(13, 2);
|
|
lcd.printSync('By Karl')
|
|
await common.pause(3000)
|
|
lcd.clearSync();
|
|
},
|
|
heading: async (title) => {
|
|
lcd.setCursorSync(0, 0);
|
|
lcd.printSync(title)
|
|
},
|
|
time: async () => {
|
|
let t = new Date().toUTCString()
|
|
console.log(t + ' get time')
|
|
lcd.setCursorSync(15, 0);
|
|
lcd.printSync(await clock.time())
|
|
},
|
|
waterStatus: async (input) => {
|
|
lcd.printLineSync(2, 'Water=')
|
|
lcd.setCursorSync(6, 2);
|
|
lcd.printSync(' ')
|
|
lcd.setCursorSync(6, 2);
|
|
lcd.printSync(input)
|
|
},
|
|
heatingStatus: async (input) => {
|
|
lcd.printLineSync(2, 'Heating=')
|
|
lcd.setCursorSync(8, 2);
|
|
lcd.printSync(' ')
|
|
lcd.setCursorSync(8, 2);
|
|
lcd.printSync(input)
|
|
},
|
|
NextEvent: async (input) => {
|
|
if (input === 'Not Set') {
|
|
lcd.setCursorSync(0, 3)
|
|
lcd.printSync("Always Off")
|
|
} else {
|
|
if (globalVars.waterOn === "true") {
|
|
lcd.setCursorSync(0, 3)
|
|
lcd.printSync("Switch Off=")
|
|
lcd.setCursorSync(11, 3);
|
|
lcd.printSync(' ')
|
|
lcd.setCursorSync(11, 3);
|
|
lcd.printSync(input)
|
|
} else {
|
|
lcd.setCursorSync(0, 3)
|
|
lcd.printSync("Switch On=")
|
|
lcd.setCursorSync(10, 3);
|
|
lcd.printSync(' ')
|
|
lcd.setCursorSync(10, 3);
|
|
lcd.printSync(input)
|
|
}
|
|
}
|
|
},
|
|
currentRoomTemp: async (temp) => {
|
|
lcd.printLineSync(2, 'Current Temp:' + temp + '\xDF')
|
|
},
|
|
lastSetTemp: async (temp) => {
|
|
lcd.printLineSync(3, 'Last Set Temp:' + temp + '\xDF')
|
|
},
|
|
heatingPageOne: async (heatingStatus, heatingNextEvent) => {
|
|
await module.exports.NextEvent(heatingNextEvent)
|
|
await module.exports.heatingStatus(heatingStatus)
|
|
},
|
|
heatingPageTwo: async (measuredRoomTemp, lastTimerSetPoint) => {
|
|
await module.exports.currentRoomTemp(measuredRoomTemp)
|
|
await module.exports.lastSetTemp(lastTimerSetPoint)
|
|
},
|
|
waterPageOne: async (waterStatus, waterNextEvent) => {
|
|
await module.exports.NextEvent(waterNextEvent)
|
|
await module.exports.waterStatus(waterStatus)
|
|
},
|
|
piHolePage: async (domainsBeingBlocked, queriesToday, queriesBlockedToday, percentageBlocked) => {
|
|
lcd.printLineSync(2, 'Queries=' + commaNumber(queriesToday))
|
|
lcd.printLineSync(3, 'Blocked=' + commaNumber(queriesBlockedToday) + ' (' + percentageBlocked.toFixed() + '%)')
|
|
},
|
|
weather: async (city, weatherDescription, currentTemp, highTemp, lowTemp) => {
|
|
weatherDescription = weatherDescription.replace(/(^\w{1})|(\s{1}\w{1})/g, match => match.toUpperCase());
|
|
lcd.printLineSync(2, weatherDescription + ' - ' + currentTemp + '\xDF')
|
|
lcd.printLineSync(3, 'High-' + highTemp + '\xDF' + ' / ' + 'Low-' + lowTemp + '\xDF')
|
|
}
|
|
} |