72 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-09-12 11:42:02 +01:00
const { Gpio } = require('onoff');
2020-09-21 21:38:46 +01:00
const hotwater = require('./modules/water')
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-14 18:42:09 +01:00
const menu = require('./modules/mainMenu')
2020-09-14 12:11:37 +01:00
async function main() {
lcd.clearScreen()
await lcd.intro()
2020-09-21 21:53:55 +01:00
menu.home()
2020-09-21 21:38:46 +01:00
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)
}
}
})
2020-09-21 21:38:46 +01:00
const arr = ['water', 'heating', 'mainMenu']
2020-09-14 18:42:09 +01:00
arrLength = arr.length
let i = 0
2020-09-14 12:11:37 +01:00
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) {
2020-09-14 18:42:09 +01:00
switch (arr[i]) {
2020-09-21 21:38:46 +01:00
case 'water':
await menu.water()
break;
case 'mainMenu':
clearInterval(globalVars.heatingPolling)
led.set('off')
await menu.home()
2020-09-14 18:42:09 +01:00
break;
2020-09-21 21:38:46 +01:00
case 'heating':
clearInterval(globalVars.waterPolling)
2020-09-14 18:42:09 +01:00
led.set('off')
2020-09-21 21:38:46 +01:00
await menu.heating()
2020-09-14 18:42:09 +01:00
break;
default:
break;
}
console.log(arr[i])
i = i + 1
if (i === arrLength) {
i = 0
}
2020-09-14 12:11:37 +01:00
}
})
}
process.stdin.resume();
process.on('SIGINT', function () {
lcd.clearScreen()
led.set('off')
process.exit(1)
});
main()