working
This commit is contained in:
parent
26173b42ab
commit
a56e1d95b6
31
app.js
31
app.js
@ -4,15 +4,13 @@ const common = require('./libs/common')
|
||||
const globalVars = require('./libs/globalVars')
|
||||
const led = require('./libs/led')
|
||||
const lcd = require('./libs/lcd')
|
||||
|
||||
const menu = require('./modules/mainMenu')
|
||||
|
||||
async function main() {
|
||||
lcd.clearScreen()
|
||||
await lcd.intro()
|
||||
lcd.time()
|
||||
setInterval(lcd.time, 55000)
|
||||
setInterval(hotwater.getStatus, 5000)
|
||||
|
||||
menu.home()
|
||||
|
||||
const heatingSwitch = new Gpio('17', '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) => {
|
||||
if (err) {
|
||||
console.log('Error', err);
|
||||
}
|
||||
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();
|
||||
|
@ -1,6 +1,7 @@
|
||||
class globalVariables {
|
||||
waterOn = "";
|
||||
waterNextEvent = "";
|
||||
waterPolling = 0
|
||||
}
|
||||
|
||||
module.exports = new globalVariables();
|
26
libs/lcd.js
26
libs/lcd.js
@ -21,11 +21,12 @@ module.exports = {
|
||||
lcd.printLineSync(1, 'MiGenie Status')
|
||||
lcd.printLineSync(2, ' By Karl')
|
||||
await common.pause(3000)
|
||||
module.exports.heading('Water-')
|
||||
lcd.clearSync();
|
||||
},
|
||||
heading: async (title) => {
|
||||
lcd.clearSync();
|
||||
lcd.printLineSync(2, title)
|
||||
lcd.setCursorSync(0, 0);
|
||||
lcd.printSync(title)
|
||||
module.exports.time()
|
||||
},
|
||||
time: async () => {
|
||||
lcd.setCursorSync(15, 0);
|
||||
@ -34,16 +35,25 @@ module.exports = {
|
||||
lcd.printSync(f)
|
||||
},
|
||||
waterStatus: async (input) => {
|
||||
lcd.printLineSync(2, 'Water=')
|
||||
lcd.setCursorSync(6, 2);
|
||||
lcd.printSync(' ')
|
||||
lcd.setCursorSync(6, 2);
|
||||
lcd.printSync(input)
|
||||
},
|
||||
waterNextEvent: async (input) => {
|
||||
lcd.printLineSync(3, 'Next Event-')
|
||||
lcd.setCursorSync(11, 3);
|
||||
lcd.printSync(' ')
|
||||
lcd.setCursorSync(11, 3);
|
||||
lcd.printSync(input)
|
||||
if (globalVars.waterOn === "true") {
|
||||
lcd.printLineSync(3, 'Switch Off=')
|
||||
lcd.setCursorSync(11, 3);
|
||||
lcd.printSync(' ')
|
||||
lcd.setCursorSync(11, 3);
|
||||
lcd.printSync(input)
|
||||
} else {
|
||||
lcd.printLineSync(3, 'Switch On=')
|
||||
lcd.setCursorSync(10, 3);
|
||||
lcd.printSync(' ')
|
||||
lcd.setCursorSync(10, 3);
|
||||
lcd.printSync(input)
|
||||
}
|
||||
},
|
||||
}
|
@ -24,37 +24,37 @@ module.exports = {
|
||||
});
|
||||
|
||||
// Once we're done streaming the response, parse it as json.
|
||||
response.on('end',async function () {
|
||||
response.on('end', async function () {
|
||||
var data = JSON.parse(content);
|
||||
let waterOn = data.waterOn
|
||||
|
||||
|
||||
var time = await common.nextEvent(data.nextScheduleEventUtcTime)
|
||||
|
||||
globalVars.waterNextEvent = time
|
||||
|
||||
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
||||
if (waterOn === 'true') {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Heating')
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
led.set('red')
|
||||
globalVars.waterOn = waterOn
|
||||
} else {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Not Heating')
|
||||
led.set('blue')
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
}
|
||||
} else {
|
||||
if (waterOn != globalVars.waterOn) {
|
||||
if (waterOn === 'true') {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Heating')
|
||||
led.set('red')
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
} else {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Not Heating')
|
||||
led.set('blue')
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
}
|
||||
}
|
||||
|
26
modules/mainMenu.js
Normal file
26
modules/mainMenu.js
Normal 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
10
package-lock.json
generated
@ -397,11 +397,6 @@
|
||||
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
|
||||
"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": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
@ -497,6 +492,11 @@
|
||||
"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": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.0.0.tgz",
|
||||
|
@ -15,6 +15,7 @@
|
||||
"onoff": "^6.0.0",
|
||||
"pigpio": "^3.2.3",
|
||||
"raspberrypi-liquid-crystal": "^1.15.0",
|
||||
"require-directory": "^2.1.1",
|
||||
"socket.io": "^2.3.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user