-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (56 loc) · 1.56 KB
/
index.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
var api = require('./api.js');
var say = require('say');
var async = require('async');
var schedule = [];
var count = 0;
var Gpio = require('onoff').Gpio,
button = new Gpio(18, 'in', 'both');
button.watch(function(err, value) {
if(value == 1){
console.log('button clicked');
api.getEvents(function (err, result) {
if (err)
console.log(err);
else {
Intro();
async.times(result.value.length, function () {
async.series([
function (callback) {
Time(result.value[count].start.dateTime);
callback();
},
function (callback) {
Subject(result.value[count].subject);
callback();
},
function (callback) {
++count;
callback();
},
])
});
setTimeout(function () {
say.speak(schedule);
console.log(schedule);
process.exit();
}, 3000);
}
});
}});
function Intro() {
setTimeout(function () {
say.speak('Today schedule is');
}, 1000);
}
function Time(data) {
var cst = new Date(Date.parse(data));
var time = cst.toLocaleTimeString();
time = time.replace(':00 ', ''); // only needed for Raspbian voice reading
schedule.push(time);
}
function Subject(subject){
subject = subject.replace('1:1','1 on 1');
subject = subject.replace('1-1','1 on 1');
subject = subject.replace('FW','');
schedule.push(subject);
}