forked from blackberry/WebWorks-Community-APIs
/
index.html
65 lines (58 loc) · 1.66 KB
/
index.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
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
<style>
button{
width: 100%;
border:none;
height:50px;
margin-top:10px;
}
#stop-buttons{
width:100%;
}
</style>
</head>
<body>
<div id="color-selection">
<label>Colors</label>
<br>
<input type="checkbox" name="color" value="FF0000">Red<br>
<input type="checkbox" name="color" value="00FF00">Green<br>
<input type="checkbox" name="color" value="0000FF">Blue<br>
</div>
<label>Blink Count</label>
<input type="text" value="1" name="blinkCount" id="blinkCount" />
<button id="start" onclick="startLed()">start led</button>
<div id="stop-buttons">
</div>
<script src="webworks-1.0.2.9.js"></script>
<script>
var stopButtons = document.getElementById('stop-buttons');
function startLed(){
var colors = document.getElementsByName("color");
var currColor = 0;
for(var i = 0; i < colors.length; i++){
if(colors[i].checked){
currColor = parseInt(colors[i].value, 16) | currColor;
}
}
var id = webworks.bbalert.led.startLed(currColor.toString(16), document.getElementById("blinkCount").value);
var button = document.createElement("button")
var buttonContent = document.createTextNode("Stop Led - " + id);
button.appendChild(buttonContent);
button.setAttribute("id", id);
button.onclick = function (){
webworks.bbalert.led.stopLed(this.id);
stopButtons.removeChild(this);
};
stopButtons.appendChild(button);
}
window.addEventListener("load", function(e) {
document.addEventListener("webworksready", ready);
}, false);
</script>
</body>
</html>