-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
88 lines (73 loc) · 1.97 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const express = require('express');
const app = express();
const path = require('path');
const fs = require('fs');
const Marantz = require('./night-mode-toggler');
const lirc = require('lirc_node');
const port = 8080;
// Returns landing page.
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.get('/main.css', (req, res) => {
res.contentType('text/css');
res.sendFile(path.join(__dirname + '/main.css'));
});
/**
* Returns initial status of Marantz amp so UI can be updated.
*/
app.get('/status', (req, res) => {
Marantz.getStatus((status) => {
res.contentType('application/json');
res.send(status);
});
});
/**
* Endpoints to modify Marantz amp.
*/
app.get('/enableVoice', (req, res) => {
Marantz.enableVoice();
res.send('enhance voice enabled');
});
app.get('/disableVoice', (req, res) => {
Marantz.disableVoice();
res.send('enhance voice disabled');
});
app.get('/enableNightMode', (req, res) => {
Marantz.enableNightMode();
res.send('night mode enabled');
});
app.get('/disableNightMode', (req, res) => {
Marantz.disableNightMode();
res.send('night mode disabled');
});
app.get('*', function(req, res) {
fs.readFile('./' + req.params['0'], (err, data) => {
if (err) {
res.send('Oops! Couldn\'t find that file.');
} else {
res.contentType(req.params['0']);
res.send(data);
}
res.end();
});
});
app.listen(port, () => console.log(`Marantz app listening on port ${port}!`));
// Sets up listening to commands from LG remote.
lirc.init();
// Disable Voice
lirc.addListener('KEY_1', 'LG_AKB73715601', (data) => {
Marantz.enableVoice();
}, 400);
// Enable Voice
lirc.addListener('KEY_2', 'LG_AKB73715601', (data) => {
Marantz.disableVoice();
}, 400);
// Enable Night Mode
lirc.addListener('KEY_4', 'LG_AKB73715601', (data) => {
Marantz.enableNightMode();
}, 400);
// Disable Night Mode
lirc.addListener('KEY_5', 'LG_AKB73715601', (data) => {
Marantz.disableNightMode();
}, 400);