-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigitalPin.js
60 lines (54 loc) · 1.48 KB
/
DigitalPin.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
+(function(factory) {
if (typeof exports === 'undefined') {
factory(webduino || {});
} else {
module.exports = factory;
}
}(function(scope) {
'use strict';
var DigitalPin_MESSAGE = [0x04, 0x40];
var DigitalPinEvent = {
READ: 'read',
READ_ERROR: 'readError'
};
var Module = scope.Module,
BoardEvent = scope.BoardEvent,
proto;
var self;
var string = '';
var list = [];
var readCallback = function() {}
DigitalPin.prototype = proto = Object.create(Module.prototype, {
constructor: {
value: DigitalPin
}
});
function DigitalPin(board, pin) {
Module.call(this);
self = this;
self.pin = pin;
self.val = 0;
this._board = board;
self._messageHandler = onMessage.bind(this);
board.on(BoardEvent.SYSEX_MESSAGE, self._messageHandler);
}
function onMessage(event) {
var message = event.message;
if (message[0] !== DigitalPin_MESSAGE[0] || message[1] !== DigitalPin_MESSAGE[1]) {
return;
} else {
processDigitalPinData(this, message);
}
}
function processDigitalPinData(self, data) {
var rxData = [];
// data[2]: pin , data[3]: pinValue
self.pin = data[2];
self.val = data[3];
readCallback();
}
proto.read = function(callback) {
readCallback = callback;
}
scope.module.DigitalPin = DigitalPin;
}));