forked from jasonthiago/BoneScript-SocketIO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlLedDemo.html
More file actions
156 lines (149 loc) · 5.61 KB
/
HtmlLedDemo.html
File metadata and controls
156 lines (149 loc) · 5.61 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>BeagleBone Black Demo</title>
<!-- jQuery and jQuery Mobile -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<!-- Code for socket.io and device orientation handling -->
<script>
var socket = io.connect();
// Send data through socket
function ledRed(value){
socket.emit('ledRed', value);
}
function ledGreen(value){
socket.emit('ledGreen', value);
}
function ledYellow(value){
socket.emit('ledYellow', value);
}
function Demo(value){
socket.emit('demo', value);
}
// Take actions based on device orientation (works on mobile devices only)
if (window.DeviceOrientationEvent) {
// Listen for the deviceorientation event and handle the raw data
window.addEventListener('deviceorientation', function(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
// beta is the front-to-back tilt in degrees, where front is positive
var tiltFB = eventData.beta;
// call orientation event handler
if (Gyro.value == 'on'){
deviceOrientationHandler(tiltLR, tiltFB);
}
}, false);
}
else {
console.log("DeviceOrientation is NOT supported");
}
function deviceOrientationHandler(LeftRight, FrontBack){
// normalize and limit values between 0 and 100
LeftRight = Math.min(Math.max(Math.round(LeftRight), -100), 100);
FrontBack = Math.min(Math.max(Math.round(FrontBack), -100), 100);
//LeftRight = Math.round((LeftRight/180)*100);
//FrontBack = Math.round((LeftRight/180)*50);
if (LeftRight >= 0) {
ledGreen(LeftRight);
ledRed(0);
}
if (LeftRight <= 0) {
ledRed(Math.abs(LeftRight));
ledGreen(0);
}
if (FrontBack <= 0) {
ledYellow(Math.abs(FrontBack));
}
if (FrontBack > 0) {
ledYellow(0);
}
}
function demoSwitch(sel){
if (sel.value == "on") {
$("#Gyro").val('off').slider('refresh').slider('disable');
$("#slider1").val('0').slider('refresh').slider('disable');
$("#slider2").val('0').slider('refresh').slider('disable');
$("#slider3").val('0').slider('refresh').slider('disable');
socket.emit('demo', sel.value);
} else if (sel.value == "off") {
socket.emit('demo', sel.value);
$('#Gyro').slider('enable');
$("#slider1").slider('enable');
$("#slider2").slider('enable');
$("#slider3").slider('enable');
}
}
function gyroSwitch(sel){
if (sel.value == "on") {
$("#Demo").val('off').slider('refresh').slider('disable');
$("#slider1").val('0').slider('refresh').slider('disable');
$("#slider2").val('0').slider('refresh').slider('disable');
$("#slider3").val('0').slider('refresh').slider('disable');
} else if (sel.value == "off") {
$('#Demo').slider('enable');
$("#slider1").slider('enable');
$("#slider2").slider('enable');
$("#slider3").slider('enable');
}
}
</script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
<div data-theme="a" data-role="header">
<h3>
BeagleBone Black
</h3>
</div>
<div data-role="content">
<div data-role="fieldcontain">
<label for="slider1">
Red LED
</label>
<input id="slider1" type="range" name="slider" value="0" min="0" max="100"
data-highlight="false" data-theme="b" onChange="ledRed(value);">
</div>
<div data-role="fieldcontain">
<label for="slider2">
Yellow LED
</label>
<input id="slider2" type="range" name="slider" value="0" min="0" max="100"
data-highlight="false" data-theme="b" onChange="ledYellow(value);">
</div>
<div data-role="fieldcontain">
<label for="slider3">
Green LED
</label>
<input id="slider3" type="range" name="slider" value="0" min="0" max="100"
data-highlight="false" data-theme="b" onChange="ledGreen(value);">
</div>
<div data-role="fieldcontain">
<label for="Demo">
Demo Mode
</label>
<select name="toggleswitch1" id="Demo" data-theme="b" data-role="slider" onchange="demoSwitch(this);">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="Gyro">
Gyroscope
</label>
<select name="toggleswitch2" id="Gyro" data-theme="b" data-role="slider" onchange="gyroSwitch(this);">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
</div>
</div>
</body>
</html>