-
Notifications
You must be signed in to change notification settings - Fork 14
/
wa-joystick.html
59 lines (49 loc) · 1.35 KB
/
wa-joystick.html
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
<html>
<head>
<script type="text/javascript" src="../webduino-js/src/module/Button.js"></script>
<script type="text/javascript" src="../webduino-js/src/module/Joystick.js"></script>
</head>
<body>
<script>
(function() {
var proto = Object.create(HTMLElement.prototype, {
x: {
get: function() {
return this.getAttribute('x');
}
},
y: {
get: function() {
return this.getAttribute('y');
}
},
z: {
get: function() {
return this.getAttribute('z');
}
}
});
proto.init_ = function(board) {
var Joystick = webduino.module.Joystick;
var JoystickEvent = webduino.module.JoystickEvent;
var events = new webduino.Events();
var joystick = new Joystick(board, this.x, this.y, board.getDigitalPin(this.z));
this.events_ = events;
this.joystick = joystick;
joystick.on(JoystickEvent.MESSAGE, function(x, y, z) {
events.emit('message', Array.prototype.slice.apply(arguments));
});
};
proto.on = function(eventType, handler) {
this.events_.on(eventType, handler);
};
proto.off = function(eventType, handler) {
this.events_.off(eventType, handler);
};
document.registerElement('wa-joystick', {
prototype: proto
});
})();
</script>
</body>
</html>