const LCD = require('raspberrypi-liquid-crystal'); const common = require('./common') const globalVars = require('./globalVars') const clock = require('./clock'); var commaNumber = require('comma-number') const logger = require('perfect-logger'); 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() logger.info('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) => { module.exports.clearLine(3) module.exports.clearLine(4) weatherDescription = weatherDescription.replace(/(^\w{1})|(\s{1}\w{1})/g, match => match.toUpperCase()); if (currentTemp.toString().length == 2) { lcd.printLineSync(1, ' ' + currentTemp + '\xDF') } else { lcd.printLineSync(1, ' ' + currentTemp + '\xDF') } lcd.printLineSync(2, weatherDescription) lcd.printLineSync(3, 'High-' + highTemp + '\xDF' + ' / ' + 'Low-' + lowTemp + '\xDF') }, capitalXtra: async (capitalXtraData) => { lcd.printLineSync(2, capitalXtraData.currentlyPlaying.artist) lcd.printLineSync(3, capitalXtraData.currentlyPlaying.song) }, hassOcto: async (octoData) => { lcd.printLineSync(1, 'State=' + octoData.currentState) lcd.printLineSync(2, 'Progress=' + octoData.jobPercentage) lcd.printLineSync(3, 'Remaining=' + octoData.timeRemaining) }, }