forked from jman294/talkback
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathold.js
More file actions
executable file
·164 lines (150 loc) · 3.86 KB
/
old.js
File metadata and controls
executable file
·164 lines (150 loc) · 3.86 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
var player = require('play-sound')()
var greenBean = require('green-bean')
var uname = require('node-uname')
var fs = require('fs')
var gotPi = false
var unameInfo = uname()
if (unameInfo.machine) {
if (unameInfo.machine.indexOf('x86') === 0) {
} else {
gotPi = true
}
} else {
console.log('No machine info found.')
}
if (gotPi) {
var gpio = require('rpi-gpio')
gpio.on('change', function (channel, value) {
console.log(languages[language])
// When the button is released
if (value === false) {
language++
if (language > languages.length - 1) {
language = 0
}
}
})
gpio.setup(7, gpio.DIR_IN, gpio.EDGE_BOTH)
}
// All supported languages
var languages = [
'en',
'es'
]
// Current language
var language = 0
// List of chimes
var chimes = [
'chime',
'chime_big_ben',
'chime_x'
]
// Current chime
var chime = 0
var codes = {
1: 'basket_clean',
2: 'rinse_and_spin',
3: 'quick_rinse',
4: 'bulky_items',
5: 'sanitize',
6: 'towels_and_sheets',
7: 'steam_refresh',
8: 'normal',
9: 'whites',
10: 'darks',
11: 'jeans',
12: 'hand_wash',
13: 'delicates',
14: 'speed_wash',
15: 'heavy_duty',
16: 'allergen',
17: 'power_clean',
18: 'rinse_and_spin',
19: 'single_item',
20: 'colors',
21: 'cold_wash',
128: 'cottons',
129: 'easy_care',
130: 'active_wear',
131: 'time_dry',
132: 'dewrinkle',
133: 'air_fluff',
134: 'steam_refresh',
135: 'steam_dewrinkle',
136: 'speed_dry',
137: 'mixed',
138: 'speed_dry',
139: 'casuals',
140: 'warm_up',
141: 'energy-saver'
}
const INTERVAL = 60000
const CHECK_INTERVAL = 15000
const INTERVAL_COUNTER = INTERVAL / CHECK_INTERVAL
greenBean.connect('laundry', function (laundry) {
console.log('Connected to some laundries')
var requestCycleSelectedStatus = (function (callback) {
var oldSelection = -10
return function () {
laundry.cycleSelected.read(function (value) {
// Value parameter is the code returned by the washer describing the cycle selected
if (value === 0 || codes[value] === undefined) {
console.error('Selection is Undefined or unknown: ' + value)
} else {
console.log('New selection : ' + value + ', which is ' + codes[value])
if (value === oldSelection) {
console.log('The selection did not change.')
return
}
oldSelection = value
console.log('Playing a sound for the new selection.')
playSound(getCycleCodeSoundPath(value))
}
})
}
})()
var requestMachineStatus = (function () {
var beepCount = 0
var isEndOfCycle = false
return function (laundry, intervalCounter) {
console.log('beepCount: ' + beepCount, ' isEndOfCycle: ' + isEndOfCycle, +' ' + intervalCounter)
laundry.machineStatus.read(function (machineStatus) {
// 4: End of cycle
if (machineStatus === 4) {
isEndOfCycle = true
} else {
// 0: Off (We still want isEndOfCycle to be true when it is off)
if (machineStatus !== 0) {
beepCount = 0
isEndOfCycle = false
}
}
if (isEndOfCycle) {
beepCount++
if (beepCount % intervalCounter === 0) {
beepCount = 0
console.log('playing buzzer')
playSound('./buzzers/' + chimes[chime] + '.wav')
}
}
})
}
})()
setInterval(function () {
console.log('Requesting cycle status.')
requestCycleSelectedStatus()
}, 1000)
setInterval(function () {
requestMachineStatus(laundry, INTERVAL_COUNTER)
}, CHECK_INTERVAL)
})
function getCycleCodeSoundPath (code) {
return './voices/' + languages[language] + '/' + codes[code] + '.mp3'
}
function playSound (path) {
if (fs.existsSync(path)) {
player.play(path)
} else {
console.error('Sound file does not exist: ' + path)
}
}