-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
261 lines (234 loc) · 7.53 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<!DOCTYPE html>
<html>
<head>
<title>Frenzy Navigation Remote</title>
<style>
body * {
font-family: "Monaco", "Lucida Console", "Trebuchet MS", monospace;
}
#marksTable {
position:absolute;
top:0;
left:0;
border: 1px solid;
height: 68vh;
width: 100%;
}
#marksTable tr, #marksTable td {
height: 10vh;
}
#marksTable button {
text-align: center;
font-size: 3vh;
border-radius: 10px;
width: 100%;
height: 100%;
}
.enabled {
color: #006100;
background: #c6efce;
}
.disabled {
color: #9c0006;
background: #ffc7ce;
}
.selected {
color: #000000;
background: #ffffff;
}
dialog {
width: 90vw;
height: 65vh;
}
dialog button {
font-size: 2vh;
}
dialog select {
font-size:large;
text-align:center;
}
</style>
</head>
<body onload = "startUp()">
<div>
<table id="marksTable">
<tr>
<td><button id="TOP_MARK" onclick="markButtonClicked('TOP_MARK')">TOP MARK</button></td>
<td>
<button id="WING_MARK" onclick="markButtonClicked('WING_MARK')" style="width:60%">WING MARK</button>
<select id="WING_MARK Direction" style="width:35%; height:80%; vertical-align:middle; font-size:3vh" onchange="computeWingMark()">
<option value="port">P</option>
<option value="starboard">S</option>
</select>
</td>
</tr>
<tr>
<td><button id="BOTTOM_MARK" onclick="markButtonClicked('BOTTOM_MARK')">BOTTOM MARK</button></td>
<td><button id="RAMSGATE" onclick="markButtonClicked('RAMSGATE')">RAMSGATE</button></td>
</tr>
<tr>
<td><button id="BRIGHTON" onclick="markButtonClicked('BRIGHTON')">BRIGHTON</button></td>
<td><button id="AIRPORT" onclick="markButtonClicked('AIRPORT')">AIRPORT</button></td>
</tr>
<tr>
<td><button id="KURNELL" onclick="markButtonClicked('KURNELL')">KURNELL</button></td>
<td><button id="QUIBRAY" onclick="markButtonClicked('QUIBRAY')">QUIBRAY</button></td>
</tr>
<tr>
<td><button id="OUTER_TOWRA" onclick="markButtonClicked('OUTER_TOWRA')">OUTER TOWRA</button></td>
<td><button id="TAYLOR_BAR" onclick="markButtonClicked('TAYLOR_BAR')">TAYLOR BAR</button></td>
</tr>
<tr>
<td><button id="CAPTAIN_COOK" onclick="markButtonClicked('CAPTAIN_COOK')">CAPTAIN COOK</button></td>
<td><button id="WAVERIDER" onclick="markButtonClicked('WAVERIDER')">WAVERIDER</button></td>
</tr>
</table>
</div>
<dialog id="setMarks" class="dialog">
<button id="setTopMark" style="position:absolute; width:35%; left:10%; height:15%; top:10%"
onclick="document.getElementById('setMarks').close(); setMarkClicked('TOP_MARK')">SET TOP MARK</button>
<button id="cancelTopMark" style="position:absolute; width:35%; left:55%; height:15%; top:10%"
onclick="document.getElementById('setMarks').close(); cancelMarkClicked('TOP_MARK')">CLEAR TOP MARK</button>
<button id="setBottomMark" style="position:absolute; width:35%; left:10%; height:15%; top:30%"
onclick="document.getElementById('setMarks').close(); setMarkClicked('BOTTOM_MARK')">SET BOTTOM MARK</button>
<button id="cancelBottomMark" style="position:absolute; width:35%; left:55%; height:15%; top:30%"
onclick="document.getElementById('setMarks').close(); cancelMarkClicked('BOTTOM_MARK')">CLEAR BOTTOM MARK</button>
<button id="setMarksCancel" style="position:absolute; width:60%; left:20%; height:15%; top:80%"
onclick="document.getElementById('setMarks').close()">Cancel</button>
</dialog>
</body>
<script>
var stats = {
targetMark: null,
marks: {
"TOP_MARK": { // temporary mark, pinged
status: "disabled",
},
"WING_MARK": { // temporary mark, computed from top and bottom mark locations
status: "disabled",
direction: 'port',
},
"BOTTOM_MARK": { // temporary mark, pinged
status: "disabled",
},
'RAMSGATE': {
status: "enabled",
},
'BRIGHTON': {
status: "enabled",
},
'AIRPORT': {
status: "enabled",
},
'KURNELL': {
status: "enabled",
},
'QUIBRAY': {
status: "enabled",
},
'OUTER_TOWRA': {
status: "enabled",
},
'TAYLOR_BAR': { // outermost of two piles
status: "enabled",
},
'CAPTAIN_COOK': { // CAPTAIN_COOK Buoy: Red pillar buoy (lat. 33º 59.9’S; long. 151º 13.1’E)
status: "enabled",
},
'WAVERIDER': { // Yellow Spherical buoy with aerial (lat. 34 02.43’S; long. 151º 15.18’E)
// approximately 1NM East of Cape Baily
status: "enabled",
}
}
}
function startUp() {
for (let mark in stats.marks) {
console.log(mark);
var m = document.getElementById(mark);
m.className = stats.marks[mark].status;
}
connectDisplay();
}
function error(err) {
console.log(`ERROR(${err.code}): ${err.message}`);
}
function UpdateUI() {
}
function markButtonClicked(mark) {
if (stats.targetMark) document.getElementById(stats.selectedMark).className = stats.marks[stats.selectedMark].status;
if (stats.marks[mark].status == "enabled") {
document.getElementById(mark).className = "selected";
stats.targetMark = mark;
} else {
stats.targetMark = null;
if (mark != 'WING_MARK') {
document.getElementById('setMarks').showModal();
}
}
}
function setMarkClicked(mark) {
stats.marks[mark].status = 'enabled';
document.getElementById(mark).className = 'enabled';
}
function cancelMarkClicked(mark) {
marks[mark].status = 'disabled';
document.getElementById(mark).className = 'disabled';
marks['WING_MARK'].status = 'disabled';
document.getElementById('WING_MARK').className = 'disabled';
}
function stringToArrayBuffer(str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint8Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
function connectDisplay() {
if ('bluetooth' in navigator) {
console.log('Web Bluetooth API is supported');
} else {
console.log('Web Bluetooth API is not supported');
}
let device;
NUS_UUID = '6e400001-b5a3-f393-e0a9-e50e24dcca9e';
RX_UUID = '6e400002-b5a3-f393-e0a9-e50e24dcca9e';
TX_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e';
// Next, request a Bluetooth device
navigator.bluetooth.requestDevice({
filters:[{name:'FRENZY'}]
,optionalServices: [NUS_UUID]
}).then(selectedDevice => {
device = selectedDevice;
console.log('Device Name: ' + device.name);
console.log('Device Id: ' + device.id);
// Connect to the device
return device.gatt.connect();
}).then(server => {
// Get the Custom Service
return server.getPrimaryService(NUS_UUID);
}).then(service => {
// Get the Custom Characteristic
return service.getCharacteristic(RX_UUID);
}).then(characteristic => {
// Save the characteristic for later use
globalCharacteristic = characteristic;
console.log('Characteristic saved');
}).catch(error => {
console.log('Error: ' + error);
});
}
function writeToCharacteristic(data) {
const message = new TextEncoder().encode(JSON.stringify(data));
if (globalCharacteristic) {
globalCharacteristic.writeValue(message)
.then(_ => {
console.log('Data transmitted successfully');
})
.catch(error => {
console.log('Error: ' + error);
});
}
}
</script>
</html>