2020-09-14 12:28:58 +01:00

51 lines
1.0 KiB
JavaScript

const { Gpio } = require('onoff');
const hotwater = require('./modules/hotwater')
const common = require('./libs/common')
const globalVars = require('./libs/globalVars')
const led = require('./libs/led')
const lcd = require('./libs/lcd')
async function main() {
lcd.clearScreen()
await lcd.intro()
lcd.time()
setInterval(lcd.time, 55000)
setInterval(hotwater.getStatus, 5000)
const heatingSwitch = new Gpio('17', 'in', 'both');
const appSwitch = new Gpio('23', 'in', 'both');
heatingSwitch.watch(async (err, value) => {
if (err) {
console.log('Error', err);
}
if (value === 1) {
if (globalVars.waterOn === 'true') {
common.request(0)
} else {
common.request(1)
}
}
})
appSwitch.watch(async (err, value) => {
if (err) {
console.log('Error', err);
}
if (value === 1) {
console.log('pressed')
}
})
}
process.stdin.resume();
process.on('SIGINT', function () {
lcd.clearScreen()
led.set('off')
process.exit(1)
});
main()