-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathwa-relay.html
More file actions
70 lines (58 loc) · 1.38 KB
/
wa-relay.html
File metadata and controls
70 lines (58 loc) · 1.38 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
<html>
<head>
<script type="text/javascript" src="../webduino-js/src/module/Relay.js"></script>
</head>
<body>
<script>
(function() {
var proto = Object.create(HTMLElement.prototype, {
pin: {
get: function() {
return this.getAttribute('pin');
},
set: function(val) {
this.setAttribute('pin', val);
}
},
state: {
get: function() {
return this.getAttribute('state');
},
set: function(val) {
this.setAttribute('state', val);
}
}
});
proto.init_ = function(board) {
var observer, config,
Relay = webduino.module.Relay;
this.relay = new Relay(board, board.getDigitalPin(this.pin));
if (this.state === 'on') {
this.on();
}
};
proto.on = function(callback) {
this.relay.on(callback);
};
proto.off = function(callback) {
this.relay.off(callback);
};
proto.toggle = function(callback) {
this.relay.toggle(callback);
};
proto.attributeChangedCallback = function(attrName, oldVal, newVal) {
if (this.relay) {
switch (attrName) {
case 'state':
newVal === "on" ? this.on() : this.off();
break;
}
}
};
document.registerElement('wa-relay', {
prototype: proto
});
})();
</script>
</body>
</html>