mirror of https://github.com/nealey/vail.git
Add CK button
This commit is contained in:
parent
308131f901
commit
0bd790e23a
|
@ -26,6 +26,7 @@
|
||||||
<nav class="mdl-navigation">
|
<nav class="mdl-navigation">
|
||||||
<a class="mdl-navigation__link" href="https://github.com/nealey/vail">Source Code</a>
|
<a class="mdl-navigation__link" href="https://github.com/nealey/vail">Source Code</a>
|
||||||
<a class="mdl-navigation__link" href="https://github.com/nealey/vail/issues/new">Bug Report</a>
|
<a class="mdl-navigation__link" href="https://github.com/nealey/vail/issues/new">Bug Report</a>
|
||||||
|
<a class="mdl-navigation__link" href="https://morse.withgoogle.com/learn/">Learn Morse</a>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
@ -37,6 +38,10 @@
|
||||||
<a class="mdl-navigation__link" href="?repeater=int">16-20 WPM</a>
|
<a class="mdl-navigation__link" href="?repeater=int">16-20 WPM</a>
|
||||||
<a class="mdl-navigation__link" href="?repeater=adv">21-99 WPM</a>
|
<a class="mdl-navigation__link" href="?repeater=adv">21-99 WPM</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
<hr>
|
||||||
|
<nav class="mdl-navigation">
|
||||||
|
<a class="mdl-navigation__link" href="https://morse.withgoogle.com/learn/">Learn Morse Code</a>
|
||||||
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<main class="mdl-layout__content">
|
<main class="mdl-layout__content">
|
||||||
|
@ -51,6 +56,7 @@
|
||||||
<div class="mdl-tabs__tab-bar">
|
<div class="mdl-tabs__tab-bar">
|
||||||
<a href="#straight" class="mdl-tabs__tab is-active">Straight Key</a>
|
<a href="#straight" class="mdl-tabs__tab is-active">Straight Key</a>
|
||||||
<a href="#iambic" class="mdl-tabs__tab">Iambic</a>
|
<a href="#iambic" class="mdl-tabs__tab">Iambic</a>
|
||||||
|
<a href="#tools" class="mdl-tabs__tab">Tools</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-tabs__panel is-active" id="straight">
|
<div class="mdl-tabs__panel is-active" id="straight">
|
||||||
<table class="center wide">
|
<table class="center wide">
|
||||||
|
@ -92,6 +98,20 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mdl-tabs__panel" id="tools">
|
||||||
|
<table class="center wide">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<button id="ck" class="key mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
|
||||||
|
CK
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Echo On</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -142,7 +162,7 @@
|
||||||
type="range"
|
type="range"
|
||||||
min="0"
|
min="0"
|
||||||
max="5000"
|
max="5000"
|
||||||
value="300">
|
value="400">
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Dit length (iambic):
|
Dit length (iambic):
|
||||||
|
@ -153,7 +173,7 @@
|
||||||
type="range"
|
type="range"
|
||||||
min="40"
|
min="40"
|
||||||
max="255"
|
max="255"
|
||||||
value="80">
|
value="100">
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -210,7 +230,6 @@
|
||||||
<li>Make this page less ugly</li>
|
<li>Make this page less ugly</li>
|
||||||
<li>Arduino program to let you hook up an iambic paddle over USB</li>
|
<li>Arduino program to let you hook up an iambic paddle over USB</li>
|
||||||
<li>Document the protocol</li>
|
<li>Document the protocol</li>
|
||||||
<li>Support multiple channels/frequencies</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,8 @@ class Buzzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
let acOffset = Date.now() - this.ac.currentTime*1000
|
let acOffset = Date.now() - this.ac.currentTime*1000
|
||||||
return (when - acOffset) / 1000
|
let acTime = (when - acOffset) / 1000
|
||||||
|
return acTime
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,8 +207,8 @@ class Vail {
|
||||||
let wsUrl = new URL(window.location)
|
let wsUrl = new URL(window.location)
|
||||||
wsUrl.protocol = "ws:"
|
wsUrl.protocol = "ws:"
|
||||||
wsUrl.pathname += "chat"
|
wsUrl.pathname += "chat"
|
||||||
window.socket = new WebSocket(wsUrl)
|
this.socket = new WebSocket(wsUrl)
|
||||||
window.socket.addEventListener("message", e => this.wsMessage(e))
|
this.socket.addEventListener("message", e => this.wsMessage(e))
|
||||||
|
|
||||||
// Listen to HTML buttons
|
// Listen to HTML buttons
|
||||||
for (let e of document.querySelectorAll("button.key")) {
|
for (let e of document.querySelectorAll("button.key")) {
|
||||||
|
@ -226,7 +227,7 @@ class Vail {
|
||||||
|
|
||||||
// Listen for slider values
|
// Listen for slider values
|
||||||
this.inputInit("#iambic-duration", e => this.iambic.SetInterval(e.target.value))
|
this.inputInit("#iambic-duration", e => this.iambic.SetInterval(e.target.value))
|
||||||
this.inputInit("#rx-delay", e => {this.rxDelay = e.target.value})
|
this.inputInit("#rx-delay", e => {this.rxDelay = Number(e.target.value)})
|
||||||
}
|
}
|
||||||
|
|
||||||
inputInit(selector, func) {
|
inputInit(selector, func) {
|
||||||
|
@ -268,7 +269,7 @@ class Vail {
|
||||||
|
|
||||||
updateReadings() {
|
updateReadings() {
|
||||||
let avgLag = this.lagTimes.reduce((a,b) => (a+b)) / this.lagTimes.length
|
let avgLag = this.lagTimes.reduce((a,b) => (a+b)) / this.lagTimes.length
|
||||||
let longestRx = this.rxDurations.reduce(Math.max)
|
let longestRx = this.rxDurations.reduce((a,b) => Math.max(a,b))
|
||||||
let suggestedDelay = (avgLag + longestRx) * 1.2
|
let suggestedDelay = (avgLag + longestRx) * 1.2
|
||||||
|
|
||||||
this.updateReading("#lag-value", avgLag.toFixed())
|
this.updateReading("#lag-value", avgLag.toFixed())
|
||||||
|
@ -278,7 +279,7 @@ class Vail {
|
||||||
|
|
||||||
addLagReading(duration) {
|
addLagReading(duration) {
|
||||||
this.lagTimes.push(duration)
|
this.lagTimes.push(duration)
|
||||||
if (this.lagTimes.length > 20) {
|
while (this.lagTimes.length > 20) {
|
||||||
this.lagTimes.shift()
|
this.lagTimes.shift()
|
||||||
}
|
}
|
||||||
this.updateReadings()
|
this.updateReadings()
|
||||||
|
@ -286,7 +287,7 @@ class Vail {
|
||||||
|
|
||||||
addRxDuration(duration) {
|
addRxDuration(duration) {
|
||||||
this.rxDurations.push(duration)
|
this.rxDurations.push(duration)
|
||||||
if (this.rxDurations.length > 20) {
|
while (this.rxDurations.length > 20) {
|
||||||
this.rxDurations.shift()
|
this.rxDurations.shift()
|
||||||
}
|
}
|
||||||
this.updateReadings()
|
this.updateReadings()
|
||||||
|
@ -295,29 +296,45 @@ class Vail {
|
||||||
wsSend(time, duration) {
|
wsSend(time, duration) {
|
||||||
let msg = [time, duration]
|
let msg = [time, duration]
|
||||||
let jmsg = JSON.stringify(msg)
|
let jmsg = JSON.stringify(msg)
|
||||||
window.socket.send(jmsg)
|
this.socket.send(jmsg)
|
||||||
this.sent.push(jmsg)
|
this.sent.push(jmsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
wsMessage(event) {
|
wsMessage(event) {
|
||||||
|
let now = Date.now()
|
||||||
let jmsg = event.data
|
let jmsg = event.data
|
||||||
let msg = JSON.parse(jmsg)
|
let msg = JSON.parse(jmsg)
|
||||||
let beginTxTime = msg[0]
|
let beginTxTime = msg[0]
|
||||||
let duration = msg[1]
|
let durations = msg.slice(1)
|
||||||
|
|
||||||
let sent = this.sent.filter(e => e != jmsg)
|
let sent = this.sent.filter(e => e != jmsg)
|
||||||
if (sent.length < this.sent.length) {
|
if (sent.length < this.sent.length) {
|
||||||
// We're getting our own message back, which tells us our lag.
|
// We're getting our own message back, which tells us our lag.
|
||||||
// We shouldn't emit a tone, though.
|
// We shouldn't emit a tone, though.
|
||||||
|
let totalDuration = durations.reduce((a,b) => a+b)
|
||||||
this.sent = sent
|
this.sent = sent
|
||||||
this.addLagReading(Date.now() - beginTxTime - duration)
|
this.addLagReading(now - beginTxTime - totalDuration)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Beep!
|
|
||||||
this.buzzer.BuzzDuration(false, beginTxTime+this.rxDelay, duration)
|
|
||||||
|
|
||||||
this.addRxDuration(duration)
|
let adjustedTxTime = beginTxTime+this.rxDelay
|
||||||
|
if (adjustedTxTime < now) {
|
||||||
|
this.buzzer.ErrorTone()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every other value is a silence duration
|
||||||
|
let tx = true
|
||||||
|
for (let duration of durations) {
|
||||||
|
duration = Number(duration)
|
||||||
|
if (tx) {
|
||||||
|
this.buzzer.BuzzDuration(false, adjustedTxTime, duration)
|
||||||
|
this.addRxDuration(duration)
|
||||||
|
}
|
||||||
|
adjustedTxTime = Number(adjustedTxTime) + duration
|
||||||
|
tx = !tx
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
key(event) {
|
key(event) {
|
||||||
|
@ -361,8 +378,27 @@ class Vail {
|
||||||
} else {
|
} else {
|
||||||
this.endTx()
|
this.endTx()
|
||||||
}
|
}
|
||||||
|
} else if (event.target.id == "ck") {
|
||||||
|
this.Test()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send "CK" to server, and don't squelch the repeat
|
||||||
|
*/
|
||||||
|
Test() {
|
||||||
|
let dit = Number(document.querySelector("#iambic-duration-value").value)
|
||||||
|
let dah = dit * 3
|
||||||
|
let s = dit
|
||||||
|
|
||||||
|
let msg = [
|
||||||
|
Date.now(),
|
||||||
|
dah, s, dit, s, dah, s, dit,
|
||||||
|
s * 3,
|
||||||
|
dah, s, dit, s, dah
|
||||||
|
]
|
||||||
|
this.socket.send(JSON.stringify(msg))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function vailInit() {
|
function vailInit() {
|
||||||
|
|
Loading…
Reference in New Issue