forked from happyworm/PerceptiveMedia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
132 lines (130 loc) · 3.41 KB
/
test.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
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
<html>
<head><title>Testing analogRead</title>
<script src="client.js" charset="utf-8" type="text/javascript"></script>
<script type="text/javascript">
var ultrasonic = 0;
var light = 0;
var mic = 0;
var micSize = 20;
var micVals = [0,0,0,0,0,0,0,0,0,0];
var micIdx = 0;
var line = 0;
var smoothIdx = function(val)
{
var ret = 0;
micSize = $('#micSize')[0].value;
micIdx++;
if (micIdx == micSize) micIdx = 0;
micVals[micIdx] = val;
//console.log("Smoothing...");
for (i =0; i < micSize; i++)
{
ret = ret + micVals[i];
//console.log(ret);
}
$('#ret').text(ret);
return ret/micSize;
}
var smooth = function(smoothedVal, val)
{
var smoothingFactor = $('#factor')[0].value;
return (smoothedVal*smoothingFactor)+(val*(1-smoothingFactor));
}
arUpdateSlider_39 = function(x) {
if (x.value) {
$("#P9_39").text(x.value);
ultrasonic = smooth(ultrasonic, x.value);
$("#ultrasonic").text(ultrasonic);
}
};
arUpdateSlider_33 = function(x) {
if (x.value) {
$("#P9_33").text(x.value);
//mic = smooth(mic, x.value);
mic = smoothIdx(x.value);
$("#mic").text(mic);
}
};
arUpdateSlider_35 = function(x) {
if (x.value) {
$("#P9_35").text(x.value);
light = smooth(light, x.value);
$("#light").text(light);
}
};
arUpdateSlider_37 = function(x) {
if (x.value) {
$("#P9_37").text(x.value);
line = smooth(line, x.value);
$("#line").text(line);
}
};
var interval39 = setInterval(function() {
analogRead(bone.P9_39, arUpdateSlider_39);
}, 100);
var interval33 = setInterval(function() {
smoothedRead(bone.P9_33, arUpdateSlider_33);
}, 100);
var interval35 = setInterval(function() {
analogRead(bone.P9_35, arUpdateSlider_35);
}, 100);
var interval37 = setInterval(function() {
analogRead(bone.P9_37, arUpdateSlider_37);
}, 100);
function scan() {
$("#btresults").html("Scanning...");
bluetoothscan(function(scan_results) {
console.log(scan_results);
var devices = scan_results.value;
var output = devices.length+" devices found:<br><br>";
for (var i =0; i < devices.length; i++) {
output += i+" - ";
output += "address: "+devices[i].btaddr;
output += ", class: "+devices[i].class;
output += ", clock offset: "+devices[i].clock_offset;
output += "<br/>";
}
$("#btresults").html(output);
});
}
</script>
</head>
<body>
<h1>Testing analogRead</h1>
<p>Smoothing factor: <input type="text" name="factor" id="factor" value="0.5"></p>
<p>Mic sample count: <input type="text" name="micSize" id="micSize" value="15"></p>
<p>Ret: <span id="ret">0</span></p>
<table>
<tr>
<td></td>
<td>Smoothed</td>
<td>Raw</td>
</tr>
<tr>
<td>P9_39, ultrasonic:</td>
<td width="200px"><span id="ultrasonic">0</span></td>
<td><span id="P9_39">here</span></td>
</tr>
<tr>
<td>P9_33, mic</td>
<td><span id="mic">0</span></td>
<td><span id="P9_33">here</span></td>
</tr>
<tr>
<td>P9_35, light</td>
<td><span id="light">0</span></td>
<td><span id="P9_35">here</span></td>
</tr>
<tr>
<td>P9_37, line-out</td>
<td><span id="line">0</span></td>
<td><span id="P9_37">here</span></td>
</tr>
</table>
<h1>Testing Bluetooth Scan</h1>
<button id="btscan" onclick="scan()">Click to scan for Bluetooth devices</button>
<p>Scan results:</p>
<div id="btresults">
</div>
</body>
</html>