mirror of https://github.com/nealey/vail.git
Add keys for vband compatibility
This commit is contained in:
parent
fc213369c1
commit
ad596546bb
|
@ -8,7 +8,7 @@ const DIT = 1
|
||||||
const DAH = 3
|
const DAH = 3
|
||||||
|
|
||||||
// iOS kludge
|
// iOS kludge
|
||||||
if (! window.AudioContext) {
|
if (!window.AudioContext) {
|
||||||
window.AudioContext = window.webkitAudioContext
|
window.AudioContext = window.webkitAudioContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class Iambic {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not pulsing yet? Start right away!
|
// Not pulsing yet? Start right away!
|
||||||
if (! this.interval) {
|
if (!this.interval) {
|
||||||
this.interval = setInterval(e => this.pulse(), this.intervalDuration)
|
this.interval = setInterval(e => this.pulse(), this.intervalDuration)
|
||||||
this.pulse()
|
this.pulse()
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ class Buzzer {
|
||||||
// in order to avoid "pops" (square wave overtones)
|
// in order to avoid "pops" (square wave overtones)
|
||||||
// that happen with instant changes in gain.
|
// that happen with instant changes in gain.
|
||||||
|
|
||||||
constructor(txGain=0.6) {
|
constructor(txGain = 0.6) {
|
||||||
this.txGain = txGain
|
this.txGain = txGain
|
||||||
|
|
||||||
this.ac = new AudioContext()
|
this.ac = new AudioContext()
|
||||||
|
@ -149,7 +149,7 @@ class Buzzer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create(frequency, type="sine") {
|
create(frequency, type = "sine") {
|
||||||
let gain = this.ac.createGain()
|
let gain = this.ac.createGain()
|
||||||
gain.connect(this.ac.destination)
|
gain.connect(this.ac.destination)
|
||||||
gain.gain.value = 0
|
gain.gain.value = 0
|
||||||
|
@ -186,7 +186,7 @@ class Buzzer {
|
||||||
gain.connect(this.ac.destination)
|
gain.connect(this.ac.destination)
|
||||||
|
|
||||||
return gain
|
return gain
|
||||||
}
|
}
|
||||||
|
|
||||||
gain(high) {
|
gain(high) {
|
||||||
if (high) {
|
if (high) {
|
||||||
|
@ -203,11 +203,11 @@ class Buzzer {
|
||||||
* @return {number} AudioContext offset time
|
* @return {number} AudioContext offset time
|
||||||
*/
|
*/
|
||||||
acTime(when) {
|
acTime(when) {
|
||||||
if (! when) {
|
if (!when) {
|
||||||
return this.ac.currentTime
|
return this.ac.currentTime
|
||||||
}
|
}
|
||||||
|
|
||||||
let acOffset = Date.now() - this.ac.currentTime*1000
|
let acOffset = Date.now() - this.ac.currentTime * 1000
|
||||||
let acTime = (when - acOffset) / 1000
|
let acTime = (when - acOffset) / 1000
|
||||||
return acTime
|
return acTime
|
||||||
}
|
}
|
||||||
|
@ -235,8 +235,8 @@ class Buzzer {
|
||||||
* @param {boolean} tx Transmit or receive tone
|
* @param {boolean} tx Transmit or receive tone
|
||||||
* @param {number} when Time to begin, in ms (null=now)
|
* @param {number} when Time to begin, in ms (null=now)
|
||||||
*/
|
*/
|
||||||
Buzz(tx, when=null) {
|
Buzz(tx, when = null) {
|
||||||
if (! tx) {
|
if (!tx) {
|
||||||
let recv = document.querySelector("#recv")
|
let recv = document.querySelector("#recv")
|
||||||
let ms = when - Date.now()
|
let ms = when - Date.now()
|
||||||
setTimeout(e => {
|
setTimeout(e => {
|
||||||
|
@ -258,8 +258,8 @@ class Buzzer {
|
||||||
* @param {boolean} tx Transmit or receive tone
|
* @param {boolean} tx Transmit or receive tone
|
||||||
* @param {number} when Time to end, in ms (null=now)
|
* @param {number} when Time to end, in ms (null=now)
|
||||||
*/
|
*/
|
||||||
Silence(tx, when=null) {
|
Silence(tx, when = null) {
|
||||||
if (! tx) {
|
if (!tx) {
|
||||||
let recv = document.querySelector("#recv")
|
let recv = document.querySelector("#recv")
|
||||||
let ms = when - Date.now()
|
let ms = when - Date.now()
|
||||||
setTimeout(e => {
|
setTimeout(e => {
|
||||||
|
@ -282,7 +282,7 @@ class Buzzer {
|
||||||
*/
|
*/
|
||||||
BuzzDuration(high, when, duration) {
|
BuzzDuration(high, when, duration) {
|
||||||
this.Buzz(high, when)
|
this.Buzz(high, when)
|
||||||
this.Silence(high, when+duration)
|
this.Silence(high, when + duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ class Vail {
|
||||||
|
|
||||||
// Listen to HTML buttons
|
// Listen to HTML buttons
|
||||||
for (let e of document.querySelectorAll("button.key")) {
|
for (let e of document.querySelectorAll("button.key")) {
|
||||||
e.addEventListener("contextmenu", e => {e.preventDefault(); return false})
|
e.addEventListener("contextmenu", e => { e.preventDefault(); return false })
|
||||||
e.addEventListener("touchstart", e => this.keyButton(e))
|
e.addEventListener("touchstart", e => this.keyButton(e))
|
||||||
e.addEventListener("touchend", e => this.keyButton(e))
|
e.addEventListener("touchend", e => this.keyButton(e))
|
||||||
e.addEventListener("mousedown", e => this.keyButton(e))
|
e.addEventListener("mousedown", e => this.keyButton(e))
|
||||||
|
@ -320,7 +320,7 @@ class Vail {
|
||||||
|
|
||||||
// Listen for slider values
|
// Listen for slider values
|
||||||
this.inputInit("#iambic-duration", e => this.iambic.SetIntervalDuration(e.target.value))
|
this.inputInit("#iambic-duration", e => this.iambic.SetIntervalDuration(e.target.value))
|
||||||
this.inputInit("#rx-delay", e => {this.rxDelay = Number(e.target.value)})
|
this.inputInit("#rx-delay", e => { this.rxDelay = Number(e.target.value) })
|
||||||
|
|
||||||
// Show what repeater we're on
|
// Show what repeater we're on
|
||||||
let repeater = (new URL(location)).searchParams.get("repeater") || "General Chaos"
|
let repeater = (new URL(location)).searchParams.get("repeater") || "General Chaos"
|
||||||
|
@ -434,8 +434,8 @@ 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((a,b) => Math.max(a,b))
|
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())
|
||||||
|
@ -474,7 +474,7 @@ class Vail {
|
||||||
try {
|
try {
|
||||||
msg = JSON.parse(jmsg)
|
msg = JSON.parse(jmsg)
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch (err) {
|
||||||
console.log(err, msg)
|
console.log(err, msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -489,7 +489,7 @@ class Vail {
|
||||||
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)
|
let totalDuration = durations.reduce((a, b) => a + b)
|
||||||
this.sent = sent
|
this.sent = sent
|
||||||
this.addLagReading(now - beginTxTime - totalDuration)
|
this.addLagReading(now - beginTxTime - totalDuration)
|
||||||
return
|
return
|
||||||
|
@ -511,7 +511,7 @@ class Vail {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add rxDelay
|
// Add rxDelay
|
||||||
let adjustedTxTime = beginTxTime+this.rxDelay
|
let adjustedTxTime = beginTxTime + this.rxDelay
|
||||||
if (adjustedTxTime < now) {
|
if (adjustedTxTime < now) {
|
||||||
console.log("adjustedTxTime: ", adjustedTxTime, " now: ", now)
|
console.log("adjustedTxTime: ", adjustedTxTime, " now: ", now)
|
||||||
this.error("Packet requested playback " + (now - adjustedTxTime) + "ms in the past. Increase receive delay!")
|
this.error("Packet requested playback " + (now - adjustedTxTime) + "ms in the past. Increase receive delay!")
|
||||||
|
@ -555,11 +555,19 @@ class Vail {
|
||||||
|
|
||||||
let begin = event.type.endsWith("down")
|
let begin = event.type.endsWith("down")
|
||||||
|
|
||||||
if ((event.code == "KeyX") || (event.code == "Period")) {
|
if ((event.code == "KeyX") ||
|
||||||
|
(event.code == "Period") ||
|
||||||
|
(event.code == "ControlLeft") ||
|
||||||
|
(event.code == "BracketLeft") ||
|
||||||
|
(event.key == "[")) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
this.iambicDit(begin)
|
this.iambicDit(begin)
|
||||||
}
|
}
|
||||||
if ((event.code == "KeyZ") || (event.code == "Slash")) {
|
if ((event.code == "KeyZ") ||
|
||||||
|
(event.code == "Slash") ||
|
||||||
|
(event.code == "ControlRight") ||
|
||||||
|
(event.code == "BracketRight") ||
|
||||||
|
(event.key == "]")) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
this.iambicDah(begin)
|
this.iambicDah(begin)
|
||||||
}
|
}
|
||||||
|
@ -596,7 +604,7 @@ class Vail {
|
||||||
// Polling could be computationally expensive,
|
// Polling could be computationally expensive,
|
||||||
// especially on devices with a power budget, like phones.
|
// especially on devices with a power budget, like phones.
|
||||||
// To be considerate, we only start polling if a gamepad appears.
|
// To be considerate, we only start polling if a gamepad appears.
|
||||||
if (! this.gamepadButtons) {
|
if (!this.gamepadButtons) {
|
||||||
this.gamepadButtons = {}
|
this.gamepadButtons = {}
|
||||||
this.gamepadPoll(event.timeStamp)
|
this.gamepadPoll(event.timeStamp)
|
||||||
}
|
}
|
||||||
|
@ -654,9 +662,9 @@ class Vail {
|
||||||
|
|
||||||
maximize(e) {
|
maximize(e) {
|
||||||
let element = e.target
|
let element = e.target
|
||||||
while (! element.classList.contains("mdl-card")) {
|
while (!element.classList.contains("mdl-card")) {
|
||||||
element = element.parentElement
|
element = element.parentElement
|
||||||
if (! element) {
|
if (!element) {
|
||||||
console.log("Maximize button: couldn't find parent card")
|
console.log("Maximize button: couldn't find parent card")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue