This commit is contained in:
Karl Hudgell 2020-09-14 18:42:09 +01:00
parent 26173b42ab
commit a56e1d95b6
7 changed files with 81 additions and 26 deletions

29
app.js
View File

@ -4,14 +4,12 @@ const common = require('./libs/common')
const globalVars = require('./libs/globalVars') const globalVars = require('./libs/globalVars')
const led = require('./libs/led') const led = require('./libs/led')
const lcd = require('./libs/lcd') const lcd = require('./libs/lcd')
const menu = require('./modules/mainMenu')
async function main() { async function main() {
lcd.clearScreen() lcd.clearScreen()
await lcd.intro() await lcd.intro()
lcd.time() menu.home()
setInterval(lcd.time, 55000)
setInterval(hotwater.getStatus, 5000)
const heatingSwitch = new Gpio('17', 'in', 'both'); const heatingSwitch = new Gpio('17', 'in', 'both');
const appSwitch = new Gpio('23', 'in', 'both'); const appSwitch = new Gpio('23', 'in', 'both');
@ -29,15 +27,34 @@ async function main() {
} }
}) })
const arr = ['hotwater', 'main-menu']
arrLength = arr.length
let i = 0
appSwitch.watch(async (err, value) => { appSwitch.watch(async (err, value) => {
if (err) { if (err) {
console.log('Error', err); console.log('Error', err);
} }
if (value === 1) { if (value === 1) {
console.log('pressed') switch (arr[i]) {
case 'hotwater':
menu.hotWater()
break;
case 'main-menu':
globalVars.waterPolling = 0
setInterval(hotwater.getStatus, globalVars.waterPolling)
led.set('off')
menu.home()
break;
default:
break;
}
console.log(arr[i])
i = i + 1
if (i === arrLength) {
i = 0
}
} }
}) })
} }
process.stdin.resume(); process.stdin.resume();

View File

@ -1,6 +1,7 @@
class globalVariables { class globalVariables {
waterOn = ""; waterOn = "";
waterNextEvent = ""; waterNextEvent = "";
waterPolling = 0
} }
module.exports = new globalVariables(); module.exports = new globalVariables();

View File

@ -21,11 +21,12 @@ module.exports = {
lcd.printLineSync(1, 'MiGenie Status') lcd.printLineSync(1, 'MiGenie Status')
lcd.printLineSync(2, ' By Karl') lcd.printLineSync(2, ' By Karl')
await common.pause(3000) await common.pause(3000)
module.exports.heading('Water-') lcd.clearSync();
}, },
heading: async (title) => { heading: async (title) => {
lcd.clearSync(); lcd.setCursorSync(0, 0);
lcd.printLineSync(2, title) lcd.printSync(title)
module.exports.time()
}, },
time: async () => { time: async () => {
lcd.setCursorSync(15, 0); lcd.setCursorSync(15, 0);
@ -34,16 +35,25 @@ module.exports = {
lcd.printSync(f) lcd.printSync(f)
}, },
waterStatus: async (input) => { waterStatus: async (input) => {
lcd.printLineSync(2, 'Water=')
lcd.setCursorSync(6, 2); lcd.setCursorSync(6, 2);
lcd.printSync(' ') lcd.printSync(' ')
lcd.setCursorSync(6, 2); lcd.setCursorSync(6, 2);
lcd.printSync(input) lcd.printSync(input)
}, },
waterNextEvent: async (input) => { waterNextEvent: async (input) => {
lcd.printLineSync(3, 'Next Event-') if (globalVars.waterOn === "true") {
lcd.printLineSync(3, 'Switch Off=')
lcd.setCursorSync(11, 3); lcd.setCursorSync(11, 3);
lcd.printSync(' ') lcd.printSync(' ')
lcd.setCursorSync(11, 3); lcd.setCursorSync(11, 3);
lcd.printSync(input) lcd.printSync(input)
} else {
lcd.printLineSync(3, 'Switch On=')
lcd.setCursorSync(10, 3);
lcd.printSync(' ')
lcd.setCursorSync(10, 3);
lcd.printSync(input)
}
}, },
} }

View File

@ -34,27 +34,27 @@ module.exports = {
if (globalVars.waterOn === "" || globalVars.waterOn === "error") { if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
if (waterOn === 'true') { if (waterOn === 'true') {
globalVars.waterOn = waterOn
lcd.waterStatus('Heating') lcd.waterStatus('Heating')
lcd.waterNextEvent(globalVars.waterNextEvent) lcd.waterNextEvent(globalVars.waterNextEvent)
led.set('red') led.set('red')
globalVars.waterOn = waterOn
} else { } else {
globalVars.waterOn = waterOn
lcd.waterStatus('Not Heating') lcd.waterStatus('Not Heating')
led.set('blue') led.set('blue')
globalVars.waterOn = waterOn
lcd.waterNextEvent(globalVars.waterNextEvent) lcd.waterNextEvent(globalVars.waterNextEvent)
} }
} else { } else {
if (waterOn != globalVars.waterOn) { if (waterOn != globalVars.waterOn) {
if (waterOn === 'true') { if (waterOn === 'true') {
globalVars.waterOn = waterOn
lcd.waterStatus('Heating') lcd.waterStatus('Heating')
led.set('red') led.set('red')
globalVars.waterOn = waterOn
lcd.waterNextEvent(globalVars.waterNextEvent) lcd.waterNextEvent(globalVars.waterNextEvent)
} else { } else {
globalVars.waterOn = waterOn
lcd.waterStatus('Not Heating') lcd.waterStatus('Not Heating')
led.set('blue') led.set('blue')
globalVars.waterOn = waterOn
lcd.waterNextEvent(globalVars.waterNextEvent) lcd.waterNextEvent(globalVars.waterNextEvent)
} }
} }

26
modules/mainMenu.js Normal file
View File

@ -0,0 +1,26 @@
const http = require('http')
const globalVars = require('../libs/globalVars')
const led = require('../libs/led')
const common = require('../libs/common')
const modules = require('../modules/hotwater')
const screen = require('../libs/lcd')
module.exports = {
home: () => {
clearInterval(globalVars.waterPolling);
screen.clearScreen()
screen.heading('Main Menu')
},
hotWater: () => {
globalVars.waterPolling = 30000
screen.clearScreen()
screen.heading('Hot Water')
setInterval(screen.time, 55000)
modules.getStatus()
globalVars.waterPolling = setInterval(() => {
modules.getStatus()
}, 30000);
}
}

10
package-lock.json generated
View File

@ -397,11 +397,6 @@
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ=="
}, },
"moment": {
"version": "2.28.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.28.0.tgz",
"integrity": "sha512-Z5KOjYmnHyd/ukynmFd/WwyXHd7L4J9vTI/nn5Ap9AVUgaAE15VvQ9MOGmJJygEUklupqIrFnor/tjTwRU+tQw=="
},
"ms": { "ms": {
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@ -497,6 +492,11 @@
"sleep": "^6.1.0" "sleep": "^6.1.0"
} }
}, },
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I="
},
"resolve-alpn": { "resolve-alpn": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.0.0.tgz", "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.0.0.tgz",

View File

@ -15,6 +15,7 @@
"onoff": "^6.0.0", "onoff": "^6.0.0",
"pigpio": "^3.2.3", "pigpio": "^3.2.3",
"raspberrypi-liquid-crystal": "^1.15.0", "raspberrypi-liquid-crystal": "^1.15.0",
"require-directory": "^2.1.1",
"socket.io": "^2.3.0" "socket.io": "^2.3.0"
} }
} }