-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
243 lines (223 loc) · 8.48 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Telescience calculator</title>
<style>
td:nth-child(odd) {
text-align: right;
}
span.value {
font-family: monospace;
}
button.fullWidth {
display: block;
width: 100%;
}
div.left {
padding: 1em;
float: left;
}
.e2toggle {
display: none;
}
</style>
</head>
<body>
<div class="left">
<h1>Telescience calculator</h1>
<p>Calculate (
<input type="radio" autocomplete="off" checked name="calibMode" id="modePower" value="power"> <label for="modePower">power</label>
<input type="radio" autocomplete="off" name="calibMode" id="modeElevation" value="elevation"> <label for="modeElevation">elevation</label>
) first.</p>
<table>
<tbody>
<tr>
<td><em>x<sub>pad</sub></em> =</td><td><input id="telepadX" placeholder="Pad X" type="number" min="0" max="255" /></td>
<td><em>y<sub>pad</sub></em> =</td><td><input id="telepadY" placeholder="Pad Y" type="number" min="0" max="255" /></td>
</tr>
<tr>
<td><em>x</em><sub>1</sub> = </td><td><input id="calibX1" placeholder="1st X" type="number" min="0" max="255" autocomplete="off" /></td>
<td><em>y</em><sub>1</sub> = </td><td><input id="calibY1" placeholder="1st Y" type="number" min="0" max="255" autocomplete="off" /></td>
</tr>
<tr>
<td><em>x</em><sub>2</sub> = </td><td><input id="calibX2" placeholder="2nd X" type="number" min="0" max="255" autocomplete="off" /></td>
<td><em>y</em><sub>2</sub> = </td><td><input id="calibY2" placeholder="2nd Y" type="number" min="0" max="255" autocomplete="off" /></td>
</tr>
<tr>
<td><em>φ</em> =</td><td><input id="calibBearing" placeholder="bearing" type="number" autocomplete="off" /></td>
<td><em>θ<sub>1</sub></em> =</td><td><input id="calibElevation1" placeholder="elevation 1" type="number" autocomplete="off" /></td>
</tr>
<tr>
<td><em>P<sub>1</sub></em> =</td><td><select id="calibPower1">
<option>5</option>
<option>10</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>40</option>
<option>50</option>
<option>80</option>
<option>100</option>
</select></td>
<td class="p2toggle"><em>P<sub>2</sub></em> =</td><td class="p2toggle"><select id="calibPower2">
<option>5</option>
<option>10</option>
<option>20</option>
<option>25</option>
<option>30</option>
<option>40</option>
<option>50</option>
<option>80</option>
<option>100</option>
</select></td>
<td class="e2toggle"><em>θ<sub>2</sub></em> =</td><td class="e2toggle"><input id="calibElevation2" placeholder="elevation 2" type="number" autocomplete="off" /></td>
</tr>
<tr>
<td colspan="4"><button type="button" class="fullWidth" id="btn_calculateErrors">Calculate Errors ↓</button></td>
</tr>
</tbody>
</table>
<p>Δφ = <span class="value" id="bearingErrorValue">undefined</span>; Δθ = <span class="value" id="elevationErrorValue">undefined</span>; ΔP = <span class="value" id="powerErrorValue">undefined</span>.</p>
<table>
<tbody>
<tr>
<td><em>x<sub>targ</sub></em> =</td><td><input id="targetXValue" placeholder="desired X" type="number" min="1" max="255" /></td>
<td><em>y<sub>targ</sub></em> =</td><td><input id="targetYValue" placeholder="desired Y" type="number" min="1" max="255" /></td>
</tr>
<tr>
<td colspan="4"><button type="button" class="fullWidth" id="btn_triangulate">Triangulate coordinates</button></td>
</tr>
</tbody>
</table>
<p>φ<sub>targ</sub> = <span class="value" id="bearingValue">undefined</span>; θ<sub>targ</sub> = <span class="value" id="elevationValue">undefined</span>; P<sub>targ</sub> = <span class="value" id="powerValue">undefined</span>.</p>
</div>
<div class="left">
<h1>Instructions</h1>
<h2>Power mode</h2>
<p class="lore">Recommended settings for calibration: φ = 45° × n; θ = 22°.</p>
<p class="lore">We need two tests to calculate power error correctly.</p>
<p class="lore">Sometimes elevation can be NaN, or be very inaccurate.</p>
<h2>Elevation mode</h2>
<p class="lore">Recommended settings for calibration: φ = 0°; θ<sub>1</sub> = 45°; θ<sub>2</sub> = 50°.</p>
<p class="lore">This is one is supposed to be more consistent than previous one.</p>
<p class="lore">Although small error occurence is much higher.</p>
</div>
<div class="left">
<h1>Quick access</h1>
<ul id="qalist">
<li><a href="javascript:addQuickAccess(false)">add quick access...</a></li>
</ul>
</div>
<script>
function _gid(id) {
return document.getElementById(id);
}
function addQuickAccess(cc) {
let temp = JSON.parse(localStorage['quickAccess']);
temp.push([prompt('Enter label'), parseInt(prompt('Enter X coordinate')), parseInt(prompt('Enter Y coordinate'))]);
localStorage['quickAccess'] = JSON.stringify(temp);
renderQuickAccess(cc);
}
function removeQuickAccess(index, cc) {
let temp = JSON.parse(localStorage['quickAccess']);
temp.splice(index, 1);
localStorage['quickAccess'] = JSON.stringify(temp);
renderQuickAccess(cc);
}
function renderQuickAccess(calculateCoordinates) {
const quickLink = `<li><a href="javascript:addQuickAccess(${calculateCoordinates})">add quick access...</a></li>`;
qalist.innerHTML = '';
let qalinks = JSON.parse(localStorage['quickAccess']);
for(l in qalinks) {
let coords = '';
if(calculateCoordinates)
coords = triangulate({
x: qalinks[l][1],
y: qalinks[l][2]
}, {
x: parseInt(telepadX.value),
y: parseInt(telepadY.value)
}, errors);
qalist.innerHTML += `<li>${qalinks[l][0]} (${qalinks[l][1]}, ${qalinks[l][2]})${calculateCoordinates ? [' (' + coords.bearing.toFixed(2), coords.elevation.toFixed(2), coords.power].join(', ') + ')' : ''} <a href="javascript:removeQuickAccess(${l}, ${calculateCoordinates})">×</a> </li> `;
}
qalist.innerHTML += quickLink;
}
localStorage['quickAccess'] = (localStorage['quickAccess'] || "[]");
var qalist = _gid('qalist');
renderQuickAccess(false);
var bearingValue = _gid('bearingValue');
var elevationValue = _gid('elevationValue');
var powerValue = _gid('powerValue');
var bearingErrorValue = _gid('bearingErrorValue');
var elevationErrorValue = _gid('elevationErrorValue');
var powerErrorValue = _gid('powerErrorValue');
var modePower = _gid('modePower');
var modeElevation = _gid('modeElevation');
var telepadX = _gid('telepadX');
var telepadY = _gid('telepadY');
var calibX1 = _gid('calibX1');
var calibY1 = _gid('calibY1');
var calibX2 = _gid('calibX2');
var calibY2 = _gid('calibY2');
var calibBearing = _gid('calibBearing');
var calibElevation1 = _gid('calibElevation1');
var calibElevation2 = _gid('calibElevation2');
var calibPower1 = _gid('calibPower1');
var calibPower2 = _gid('calibPower2');
var targetXValue = _gid('targetXValue');
var targetYValue = _gid('targetYValue');
var errors = {};
modePower.addEventListener('change', () => {
if(modePower.checked) {
[...document.getElementsByClassName('p2toggle')].forEach((item) => {
item.style.display = "table-cell";
});
[...document.getElementsByClassName('e2toggle')].forEach((item) => {
item.style.display = "none";
});
}
});
modeElevation.addEventListener('change', () => {
if(modeElevation.checked) {
[...document.getElementsByClassName('e2toggle')].forEach((item) => {
item.style.display = "table-cell";
});
[...document.getElementsByClassName('p2toggle')].forEach((item) => {
item.style.display = "none";
});
}
});
modePower.select();
_gid('btn_calculateErrors').addEventListener('click', () => {
errors = calculateErrors({
x: parseInt(telepadX.value),
y: parseInt(telepadY.value)
}, {
x: parseInt(calibX1.value),
y: parseInt(calibY1.value)
}, {
x: parseInt(calibX2.value),
y: parseInt(calibY2.value)
}, parseInt(calibBearing.value), parseInt(calibElevation1.value), parseInt(calibElevation2.value), parseInt(calibPower1.value), parseInt(calibPower2.value), modePower.checked);
bearingErrorValue.innerText = errors.bearing;
elevationErrorValue.innerText = errors.elevation;
powerErrorValue.innerText = errors.power;
renderQuickAccess(true);
});
_gid('btn_triangulate').addEventListener('click', () => {
let coords = triangulate({
x: parseInt(targetXValue.value),
y: parseInt(targetYValue.value)
}, {
x: parseInt(telepadX.value),
y: parseInt(telepadY.value)
}, errors);
bearingValue.innerText = coords.bearing.toFixed(2);
elevationValue.innerText = coords.elevation.toFixed(2);
powerValue.innerText = coords.power.toFixed(2);
});
</script>
<script src="./telesci.js"></script>
</body>
</html>