-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4798d79
commit 345e5a9
Showing
9 changed files
with
744 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Mayara - Marine Yacht Radar Client Control</title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link type="text/css" rel="stylesheet" href="style.css" /> | ||
<script type="module" src="control.js"></script> | ||
<script type="module" src="viewer.js"></script> | ||
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/7.4.0/dist/protobuf.min.js"></script> | ||
</head> | ||
<body> | ||
<div class="myr_container"> | ||
<div id="myr_controller" class="myr_controller myr_controller_left"> | ||
<div id="myr_title">Radar Controls</div> | ||
<div id="myr_error" class="myr_error" style="visibility: hidden;"></div> | ||
<div id="myr_controls" class="myr_control"></div> | ||
</div> | ||
<div class="myr_ppi"> | ||
<canvas id="myr_canvas" width="600" height="600"></canvas> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
|
||
const prefix = 'myrv_'; | ||
|
||
window.onload = function () { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const id = urlParams.get('id'); | ||
|
||
loadRadars(id); | ||
} | ||
|
||
function loadRadars(id) { | ||
fetch('/v1/api/radars') | ||
.then(res => res.json()) | ||
.then(out => radarsLoaded(id, out)) | ||
.catch(err => restart(id)); | ||
} | ||
|
||
function restart(id) { | ||
setTimeout(loadRadars(id), 15000); | ||
} | ||
function radarsLoaded(id, d) { | ||
myrv_radar = d[id]; | ||
|
||
if (myrv_radar === undefined || myrv_radar.controls === undefined) { | ||
restart(id); | ||
return; | ||
} | ||
myr_webSocket = new WebSocket(myr_radar.controlUrl); | ||
|
||
myr_webSocket.onopen = (e) => { | ||
console.log("websocket open: " + JSON.stringify(e)); | ||
} | ||
myr_webSocket.onclose = (e) => { | ||
console.log("websocket close: " + e); | ||
setControl({ id: '0', value: '0' }); | ||
restart(id); | ||
} | ||
myr_webSocket.onmessage = (e) => { | ||
let v = JSON.parse(e.data); | ||
setControl(v); | ||
myr_no_response_timeout.setTimeout(); | ||
} | ||
} | ||
|
||
function setControl(v) { | ||
let i = get_element(v.id); | ||
let control = myr_controls[v.id]; | ||
if (i && control) { | ||
i.value = v.value; | ||
console.log("<- " + control.name + " = " + v.value); | ||
let n = i.parentNode.querySelector('.myr_numeric'); | ||
if (n) n.innerHTML = v.value; | ||
let d = i.parentNode.querySelector('.myr_description'); | ||
if (d) { | ||
let description = (control.descriptions) ? control.descriptions[v.value] : undefined; | ||
if (!description) description = v.value; | ||
d.innerHTML = description; | ||
} | ||
if (v.error) { | ||
myr_error_message.raise(v.error); | ||
} | ||
} | ||
} | ||
|
||
function buildControls() { | ||
let c = get_element('title'); | ||
c.innerHTML = ""; | ||
van.add(c, div(myr_radar.name + " Controls")); | ||
|
||
c = get_element('controls'); | ||
c.innerHTML = ""; | ||
for (const [k, v] of Object.entries(myr_controls)) { | ||
van.add(c, (v['isStringValue']) | ||
? StringValue(k, v.name) | ||
: ('validValues' in v) | ||
? SelectValue(k, v.name, v['validValues'], v['descriptions']) | ||
: ('maxValue' in v && v.maxValue <= 100) | ||
? RangeValue(k, v.name, v.minValue, v.maxValue, 0, 'descriptions' in v) | ||
: NumericValue(k, v.name)); | ||
if (v['isReadOnly']) { | ||
get_element(k).setAttribute('readonly', 'true'); | ||
} else if (v['isStringValue']) { | ||
van.add(get_element(k).parentNode, SetButton()); | ||
} | ||
} | ||
} | ||
|
||
function do_change(e) { | ||
let v = e.target; | ||
let id = strip_prefix(v.id); | ||
console.log("change " + e + " " + id + "=" + v.value); | ||
let cv = JSON.stringify({ id: id, value: v.value }); | ||
myr_webSocket.send(cv); | ||
console.log(myr_controls[id].name + "-> " + cv); | ||
} | ||
|
||
function do_button(e) { | ||
let v = e.target.previousElementSibling; | ||
let id = strip_prefix(v.id); | ||
console.log("set_button " + e + " " + id + "=" + v.value); | ||
let cv = JSON.stringify({ id: id, value: v.value }); | ||
myr_webSocket.send(cv); | ||
console.log(myr_controls[id].name + "-> " + cv); | ||
} | ||
|
||
function do_input(e) { | ||
let v = e.target; | ||
console.log("input " + e + " " + v.id + "=" + v.value); | ||
} | ||
|
||
function get_element(id) { | ||
let did = prefix + id; | ||
let r = document.getElementById(did); | ||
return r; | ||
} | ||
|
||
function strip_prefix(id) { | ||
if (id.startsWith(prefix)) { | ||
return id.substr(prefix.length); | ||
} | ||
return id; | ||
} |