2020-09-12 11:42:02 +01:00
|
|
|
const { Gpio } = require('onoff');
|
2020-09-14 12:11:37 +01:00
|
|
|
const hotwater = require('./modules/hotwater')
|
2020-09-12 11:42:02 +01:00
|
|
|
const common = require('./libs/common')
|
|
|
|
const globalVars = require('./libs/globalVars')
|
2020-09-14 12:11:37 +01:00
|
|
|
const led = require('./libs/led')
|
2020-09-14 08:17:22 +01:00
|
|
|
const lcd = require('./libs/lcd')
|
2020-09-11 12:42:13 +01:00
|
|
|
|
2020-09-14 12:11:37 +01:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
lcd.clearScreen()
|
|
|
|
await lcd.intro()
|
2020-09-14 12:27:18 +01:00
|
|
|
setInterval(lcd.time, 55000)
|
|
|
|
setInterval(hotwater.getStatus, 5000)
|
2020-09-14 12:11:37 +01:00
|
|
|
|
|
|
|
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);
|
2020-09-12 11:42:02 +01:00
|
|
|
}
|
2020-09-14 12:11:37 +01:00
|
|
|
if (value === 1) {
|
|
|
|
console.log('pressed')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
process.stdin.resume();
|
|
|
|
|
|
|
|
process.on('SIGINT', function () {
|
|
|
|
lcd.clearScreen()
|
|
|
|
led.set('off')
|
|
|
|
process.exit(1)
|
|
|
|
});
|
|
|
|
|
|
|
|
main()
|