1 | #Infrared
|
2 | Driver for the ir-attx4 Tessel infrared module ([Attinyx4](http://www.atmel.com/Images/doc8006.pdf)).
|
3 |
|
4 | ##Installation
|
5 | ```sh
|
6 | npm install ir-attx4
|
7 | ```
|
8 | ##Example
|
9 | ```js
|
10 | /*********************************************
|
11 | This infrared module example transmits the
|
12 | power signal sequence of an Insignia brand
|
13 | television every three seconds, while also
|
14 | listening for (and logging) any incoming
|
15 | infrared data.
|
16 | *********************************************/
|
17 |
|
18 | // Any copyright is dedicated to the Public Domain.
|
19 | // http://creativecommons.org/publicdomain/zero/1.0/
|
20 |
|
21 | var tessel = require('tessel');
|
22 |
|
23 | // Connect the IR module to port a
|
24 | var hardware = tessel.port['A'];
|
25 |
|
26 | // Import library and connect to module
|
27 | var infrared = require('../').use(hardware);
|
28 |
|
29 | var counter = 0;
|
30 |
|
31 | // When we're connected
|
32 | infrared.on('ready', function() {
|
33 | if (!err) {
|
34 | console.log("Connected to IR!");
|
35 |
|
36 | // Start turning tv on and off every 3 seconds
|
37 | setInterval(powerTV, 3000);
|
38 | }
|
39 | else {
|
40 | console.log("Err initializing: ", err.message );
|
41 | }
|
42 | });
|
43 |
|
44 | // If we get data, print it out
|
45 | infrared.on('data', function(data) {
|
46 | console.log("Received RX Data: ", data);
|
47 | });
|
48 |
|
49 | var powerTV = function() {
|
50 |
|
51 | // Make a buffer off on/off durations (each duration is 16 bits)
|
52 | var powerBuffer = new Buffer([0, 178, 255, 168, 0, 12, 255, 246, 0, 13, 255, 225, 0, 13, 255, 224, 0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247, 0, 13, 255, 247, 0, 13, 255, 224, 0, 12, 255, 224, 0, 13, 255, 247, 0, 13, 255, 224, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247, 0, 13, 255, 224, 0, 12, 255, 224, 0, 13, 255, 225, 0, 13, 255, 224, 0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247, 0, 13, 255, 247, 0, 13, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 224, 0, 13, 255, 224, 0, 12, 255, 224, 0, 12, 255, 224, 0, 12]);
|
53 |
|
54 | // Send the signal at 38 kHz
|
55 | infrared.sendRawSignal(38, powerBuffer, function(err) {
|
56 | if (err) console.log("Unable to send signal: ", err);
|
57 | else {
|
58 | console.log("TV Should be powered...");
|
59 | }
|
60 | });
|
61 | };
|
62 | ```
|
63 |
|
64 | ##Methods
|
65 |
|
66 | ##### * `infrared.sendRawSignal(frequency, signalDurations, callback)` The primary method for sending data. The first argument is a frequency of signal in Hz, typically 38 but can range from 36 to 40. The second argument is a buffer of unsigned 16 bit integers representing the number of microseconds the transmission should be on. The max length of the signal durations is 100 durations.
|
67 |
|
68 | ##### * `infrared.setListening(set, callback)` Determines whether the module is listening for incoming signals. Will automatically be set and unset depending on listeners for the `data` event.
|
69 |
|
70 |
|
71 | ## Events
|
72 |
|
73 | ##### * `infrared.on('data', callback(data))` Emitted when an infrared signal is detected.
|
74 |
|
75 | ##### * `infrared.on('error', callback(err))` Emitted when there is an error communicating with the module.
|
76 |
|
77 | ##### * `infrared.on('ready', callback())` Emitted upon first successful communication between the Tessel and the module.
|
78 |
|
79 |
|
80 | ## License
|
81 |
|
82 | Released under the MIT and Apache 2.0 licenses.
|
83 |
|