-
Notifications
You must be signed in to change notification settings - Fork 0
/
ir-remote.js
44 lines (39 loc) · 1.25 KB
/
ir-remote.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
var lirc = require('lirc_node')
function IRRemote(config) {
this.remoteName = config.remoteName
this.commadInProgress = false
this.queuedCommand = undefined
this.queueCallback = undefined
lirc.init(() => this.irsend = lirc.irsend)
}
IRRemote.prototype.sendCommand = function (cmd, cb) {
if (!this.irsend) {
if (cb) cb('init in progress')
return
}
if (this.commadInProgress) {
if (this.queuedCommand) {
if (this.queueCallback) {
this.queueCallback('queued command superceded', this.queuedCommand)
}
}
this.queuedCommand = cmd
this.queueCallback = cb
return
}
this.commadInProgress = true
this.irsend.send_once(this.remoteName, cmd, (err) => this.irsendCallback(err, cmd, cb))
}
IRRemote.prototype.irsendCallback = function (err, cmd, sendCallback) {
if (sendCallback) {
sendCallback(err, cmd)
}
if (!this.queuedCommand) {
this.commadInProgress = false
return
}
this.irsend.send_once(this.remoteName, this.queuedCommand, (err) => this.irsendCallback(err, cmd, this.queueCallback))
this.queuedCommand = undefined
this.queueCallback = undefined
}
exports = module.exports = IRRemote