-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathShock.js
More file actions
47 lines (38 loc) · 901 Bytes
/
Shock.js
File metadata and controls
47 lines (38 loc) · 901 Bytes
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
+(function (factory) {
if (typeof exports === 'undefined') {
factory(webduino || {});
} else {
module.exports = factory;
}
}(function (scope) {
'use strict';
var PinEvent = scope.PinEvent,
Pin = scope.Pin,
Module = scope.Module;
var ShockEvent = {
HIGH: 'high',
LOW: 'low'
};
function Shock(board, pin) {
Module.call(this);
this._board = board;
this._pin = pin;
board.setDigitalPinMode(pin.number, Pin.DIN);
this._pin.value = Pin.HIGH;
this._pin.on(PinEvent.CHANGE, onPinChange.bind(this));
}
function onPinChange(pin) {
if (pin.value === Pin.HIGH) {
this.emit(ShockEvent.HIGH);
} else {
this.emit(ShockEvent.LOW);
}
}
Shock.prototype = Object.create(Module.prototype, {
constructor: {
value: Shock
}
});
scope.module.ShockEvent = ShockEvent;
scope.module.Shock = Shock;
}));