-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathIRLed.js
More file actions
76 lines (66 loc) · 1.61 KB
/
IRLed.js
File metadata and controls
76 lines (66 loc) · 1.61 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
+(function (global, factory) {
if (typeof exports === 'undefined') {
factory(global.webduino || {});
} else {
module.exports = factory;
}
}(this, function (scope) {
'use strict';
var Module = scope.Module,
proto;
/**
* The IRLed Class.
*
* IR LED (Infrared LED) is widely used for remote controls and night-vision cameras.
*
* @namespace webduino.module
* @class IRLed
* @constructor
* @param {webduino.Board} board The board that the IRLed is attached to.
* @param {String} encode Encode which IRLed used.
* @extends webduino.Module
*/
function IRLed(board, encode) {
Module.call(this);
this._board = board;
this._encode = encode;
this._board.send([0xf4, 0x09, 0x03, 0xe9, 0x00, 0x00]);
}
IRLed.prototype = proto = Object.create(Module.prototype, {
constructor: {
value: IRLed
}
});
/**
* Send IR code.
*
* @method send
* @param {String} code Hexadecimal String to send.
*/
proto.send = function (code) {
var aryCode = [0x09, 0x04];
var ary;
code = code || this._encode;
if (code) {
ary = code.match(/\w{2}/g);
// data length
aryCode.push(ary.length * 8);
ary.forEach(function (val) {
for (var i = 0, len = val.length; i < len; i++) {
aryCode.push(val.charCodeAt(i));
}
});
this._board.sendSysex(0x04, aryCode);
}
};
/**
* Update code.
*
* @method updateEncode
* @param {String} code Hexadecimal to update.
*/
proto.updateEncode = function (code) {
this._encode = code;
};
scope.module.IRLed = IRLed;
}));