-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
45 lines (36 loc) · 1.29 KB
/
example.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
var rc = require('./piswitch');
// The RC-Switch wiki and related material are very helpful:
// https://code.google.com/p/rc-switch/
// This library is meant to be compatible, so any device that works with
// RC-Switch for Arduino *should* work here.
// Note that you'll need to export the pin with `gpio export [PIN] out`
// when using 'sys' (non-root) mode, which is recommended.
// compare: http://wiringpi.com/reference/setup/
// pin chart: http://pi.gadgetoid.com/pinout/
rc.setup({
mode: 'sys', // alternative: change to gpio and use root
pulseLength: 330, // this works for me, but 350 is very common
protocol: 1
});
if (process.argv.length < 3) {
console.log("Usage: node example <code> [<type> [off]]\n"
+ " e.g., node example ff0f00ffffff tristate");
return;
}
var code = process.argv[2];
var type = process.argv[3];
var offFlag = process.argv[4];
var offMsg = '';
var off;
if (typeof type === 'undefined') {
console.log("[INFO] Implicitly declared as binary.");
type = 'binary';
}
if (typeof offFlag !== 'undefined' && offFlag === 'off') {
off = true;
offMsg = '-OFF';
} else if (type !== 'binary' && type !== 'tristate') {
offMsg = '-ON';
}
console.log("[SEND] " + code + offMsg + " (type declared as: '" + type + "')");
rc.send(code, type, off);