-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
131 lines (115 loc) · 4.23 KB
/
config.js
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
import { DEFAULT, RunMode } from "./defaults.js"
export class Config {
static store_key = "_WebMorseKey";
constructor(callback) {
this._my_call = document.querySelector("#my_call")
this._volume = document.querySelector("#volume")
this._wpm = document.querySelector("#wpm")
this._pitch = document.querySelector("#pitch")
this._time = document.querySelector("#time")
this._qsk = document.querySelector("#qsk")
this._bandwidth = document.querySelector("#bandwidth")
this._rit = document.querySelector("#rit")
this._runmode = document.querySelector("#mode")
this._activity = document.querySelector("#activity")
// condx
this._qrn = document.querySelector("#qrn")
this._qrm = document.querySelector("#qrm")
this._qsb = document.querySelector("#qsb")
this._flutter = document.querySelector("#flutter")
this._lids = document.querySelector("#lids")
this._callback = callback
this.all = document.querySelectorAll(".watch").forEach(
(d) =>
d.addEventListener("input", (e) => {
this.update()
}),
)
this._config = {
my_call: "DJ1TF",
volume: 0.75,
wpm: 30,
pitch: 500,
rx_bandwidth: 300,
time: 10,
qsk: false,
rit: 0,
runmode: RunMode.Single,
activity: 2,
// condx
qrn: false,
qrm: false,
qsb: false,
flutter: false,
lids: false,
}
this.load()
}
update() {
this.read_dom()
this.updatePileupFields()
this.store()
this._callback(this._config)
}
updateRIT(x) {
let rit = Number(this._rit.value)
this._rit.value = String(rit + x)
this.update()
}
store() {
localStorage.setItem(Config.store_key, JSON.stringify(this._config))
}
load() {
let config_str = localStorage.getItem(Config.store_key)
if (config_str) {
let conf = JSON.parse(config_str)
if (conf) this._config = Object.assign({}, this._config, conf)
}
}
updatePileupFields() {
document.querySelectorAll(".pileup_only").forEach(
(e) => {
if (this._config.runmode === RunMode.Pileup) {
e.classList.remove("pileup_hidden")
} else e.classList.add("pileup_hidden")
},
)
}
update_dom() {
this._my_call.value = this._config.my_call
this._volume.value = this._config.volume
this._wpm.value = this._config.wpm
this._pitch.value = this._config.pitch
this._time.value = this._config.time
this._qsk.checked = this._config.qsk
this._bandwidth.value = this._config.rx_bandwidth
this._rit.value = this._config.rit
this._runmode.value = String(this._config.runmode)
this._activity.value = String(this._config.activity)
// condx
this._qrn.checked = this._config.qrn
this._qrm.checked = this._config.qrm
this._qsb.checked = this._config.qsb
this._flutter.checked = this._config.flutter
this._lids.checked = this._config.lids
this.updatePileupFields()
}
read_dom() {
this._config.my_call = this._my_call.value.toUpperCase()
this._config.volume = this._volume.value
this._config.wpm = this._wpm.value
this._config.pitch = this._pitch.value
this._config.time = this._time.value
this._config.qsk = this._qsk.checked
this._config.rx_bandwidth = this._bandwidth.value
this._config.rit = this._rit.value
this._config.runmode = parseInt(this._runmode.value)
this._config.activity = parseInt(this._activity.value)
this._config.qrn = this._qrn.checked
this._config.qrm = this._qrm.checked
this._config.qsb = this._qsb.checked
this._config.flutter = this._flutter.checked
this._config.lids = this._lids.checked
if(!this._config.activity) this._config.activity = 2
}
}