fully-automatic mode panel generation
This commit is contained in:
		| @@ -166,48 +166,7 @@ | ||||
|                     <select id="openwebrx-sdr-profiles-listbox" onchange="sdr_profile_changed();"> | ||||
|                     </select> | ||||
|                 </div> | ||||
|                 <div class="openwebrx-panel-line openwebrx-panel-flex-line"> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-nfm" | ||||
|                          onclick="demodulator_analog_replace('nfm');">FM</div> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-am" | ||||
|                          onclick="demodulator_analog_replace('am');">AM</div> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-lsb" | ||||
|                          onclick="demodulator_analog_replace('lsb');">LSB</div> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-usb" | ||||
|                          onclick="demodulator_analog_replace('usb');">USB</div> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-cw" | ||||
|                          onclick="demodulator_analog_replace('cw');">CW</div> | ||||
|                 </div> | ||||
|                 <div class="openwebrx-panel-line openwebrx-panel-flex-line"> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-dmr" | ||||
|                          style="display:none;" data-feature="digital_voice_digiham" | ||||
|                          onclick="demodulator_analog_replace('dmr');">DMR</div> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-dstar" | ||||
|                          style="display:none;" data-feature="digital_voice_dsd" | ||||
|                          onclick="demodulator_analog_replace('dstar');">DStar</div> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-nxdn" | ||||
|                          style="display:none;" data-feature="digital_voice_dsd" | ||||
|                          onclick="demodulator_analog_replace('nxdn');">NXDN</div> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-ysf" | ||||
|                          style="display:none;" data-feature="digital_voice_digiham" | ||||
|                          onclick="demodulator_analog_replace('ysf');">YSF</div> | ||||
|                 </div> | ||||
|                 <div class="openwebrx-panel-line openwebrx-panel-flex-line"> | ||||
|                     <div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-dig" onclick="demodulator_digital_replace_last();">DIG</div> | ||||
|                     <select id="openwebrx-secondary-demod-listbox" onchange="secondary_demod_listbox_changed();"> | ||||
|                         <option value="none"></option> | ||||
|                         <option value="bpsk31">BPSK31</option> | ||||
|                         <option value="bpsk63">BPSK63</option> | ||||
|                         <option value="ft8" data-feature="wsjt-x">FT8</option> | ||||
|                         <option value="wspr" data-feature="wsjt-x">WSPR</option> | ||||
|                         <option value="jt65" data-feature="wsjt-x">JT65</option> | ||||
|                         <option value="jt9" data-feature="wsjt-x">JT9</option> | ||||
|                         <option value="ft4" data-feature="wsjt-x">FT4</option> | ||||
|                         <option value="js8" data-feature="js8call">JS8Call</option> | ||||
|                         <option value="packet" data-feature="packet">Packet</option> | ||||
|                         <option value="pocsag" data-feature="pocsag">Pocsag</option> | ||||
|                     </select> | ||||
|                 </div> | ||||
|                 <div class="openwebrx-modes openwebrx-panel-line"></div> | ||||
|                 <div class="openwebrx-panel-line"> | ||||
|                     <div title="Mute on/off" id="openwebrx-mute-off" class="openwebrx-button" onclick="toggleMute();"><img src="static/gfx/openwebrx-speaker.png" class="openwebrx-sliderbtn-img" id="openwebrx-mute-img"></div> | ||||
|                     <input title="Volume" id="openwebrx-panel-volume" class="openwebrx-panel-slider" type="range" min="0" max="150" value="50" step="1" onchange="updateVolume()" oninput="updateVolume()"> | ||||
|   | ||||
| @@ -3,19 +3,64 @@ var Modes = { | ||||
|     features: {}, | ||||
|     setModes:function(json){ | ||||
|         this.modes = json.map(function(m){ return new Mode(m); }); | ||||
|         this.updateModePanel(); | ||||
|     }, | ||||
|     setFeatures:function(features){ | ||||
|         this.features = features; | ||||
|         this.updateModePanel(); | ||||
|     }, | ||||
|     findByModulation:function(modulation){ | ||||
|         matches = this.modes.filter(function(m) { return m.modulation === modulation; }); | ||||
|         if (matches.length) return matches[0] | ||||
|     }, | ||||
|     updateModePanel:function() { | ||||
|         var available = this.modes.filter(function(m){ return m.isAvailable(); }); | ||||
|         var normalModes = available.filter(function(m){ return !m.digimode; }); | ||||
|         var digiModes = available.filter(function(m){ return m.digimode; }); | ||||
|  | ||||
|         var index = 0; | ||||
|         var arrayLength = normalModes.length; | ||||
|         var chunks = []; | ||||
|  | ||||
|  | ||||
|         for (index = 0; index < arrayLength; index += 5) { | ||||
|             chunks.push(normalModes.slice(index, index + 5)); | ||||
|         } | ||||
|  | ||||
|         var html = [] | ||||
|  | ||||
|         html.push.apply(html, chunks.map(function(chunk){ | ||||
|             return $( | ||||
|                 '<div class="openwebrx-panel-line openwebrx-panel-flex-line">' + | ||||
|                     chunk.map(function(m){ | ||||
|                         return '<div class="openwebrx-button openwebrx-demodulator-button"' + | ||||
|                                'id="openwebrx-button-' + m.modulation + '"' + | ||||
|                                'onclick="demodulator_analog_replace(\'' + m.modulation + '\');">' + | ||||
|                                m.name + '</div>'; | ||||
|                     }).join('') + | ||||
|                 '</div>'); | ||||
|         })); | ||||
|  | ||||
|         html.push($( | ||||
|             '<div class="openwebrx-panel-line openwebrx-panel-flex-line">' + | ||||
|                 '<div class="openwebrx-button openwebrx-demodulator-button" id="openwebrx-button-dig" onclick="demodulator_digital_replace_last();">DIG</div>' + | ||||
|                 '<select id="openwebrx-secondary-demod-listbox" onchange="secondary_demod_listbox_changed();">' + | ||||
|                     '<option value="none"></option>' + | ||||
|                     digiModes.map(function(m){ | ||||
|                         return '<option value="' + m.modulation + '">' + m.name + '</option>'; | ||||
|                     }).join('') + | ||||
|                 '</select>' + | ||||
|             '</div>' | ||||
|         )); | ||||
|  | ||||
|         $("#openwebrx-panel-receiver").find(".openwebrx-modes").html(html); | ||||
|     } | ||||
| } | ||||
|  | ||||
| var Mode = function(json){ | ||||
|     this.modulation = json.modulation; | ||||
|     this.name = json.name; | ||||
|     this.digimode = json.digimode; | ||||
|     this.requirements = json.requirements; | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -1123,6 +1123,7 @@ function on_ws_recv(evt) { | ||||
|                         break; | ||||
|                     case "features": | ||||
|                         var features = json['value']; | ||||
|                         Modes.setFeatures(features); | ||||
|                         for (var feature in features) { | ||||
|                             if (features.hasOwnProperty(feature)) { | ||||
|                                 $('[data-feature="' + feature + '"]')[features[feature] ? "show" : "hide"](); | ||||
| @@ -1179,7 +1180,6 @@ function on_ws_recv(evt) { | ||||
|                         break; | ||||
|                     case 'modes': | ||||
|                         Modes.setModes(json['value']); | ||||
|                         console.info(Modes); | ||||
|                         break; | ||||
|                     default: | ||||
|                         console.warn('received message of unknown type: ' + json['type']); | ||||
|   | ||||
| @@ -353,6 +353,7 @@ class OpenWebRxReceiverClient(Client): | ||||
|         self.send({"type": "modes", "value": [{ | ||||
|             "modulation": m.modulation, | ||||
|             "name": m.name, | ||||
|             "digimode": m.digimode, | ||||
|             "requirements": m.requirements | ||||
|         } for m in modes]}) | ||||
|  | ||||
|   | ||||
| @@ -3,9 +3,10 @@ from functools import reduce | ||||
|  | ||||
|  | ||||
| class Mode(object): | ||||
|     def __init__(self, modulation, name, requirements=None, service=False): | ||||
|     def __init__(self, modulation, name, requirements=None, service=False, digimode=False): | ||||
|         self.modulation = modulation | ||||
|         self.name = name | ||||
|         self.digimode = digimode | ||||
|         self.requirements = requirements if requirements is not None else [] | ||||
|         self.service = service | ||||
|  | ||||
| @@ -21,13 +22,24 @@ class Mode(object): | ||||
|  | ||||
| class Modes(object): | ||||
|     mappings = [ | ||||
|         Mode("ft8", "FT8", ["wsjt-x"], True), | ||||
|         Mode("ft4", "FT4", ["wsjt-x"], True), | ||||
|         Mode("jt65", "JT65", ["wsjt-x"], True), | ||||
|         Mode("jt9", "JT9", ["wsjt-x"], True), | ||||
|         Mode("wspr", "WSPR", ["wsjt-x"], True), | ||||
|         Mode("packet", "Packet", ["packet"], True), | ||||
|         Mode("js8", "JS8Call", ["js8call"], True), | ||||
|         Mode("nfm", "FM"), | ||||
|         Mode("am", "AM"), | ||||
|         Mode("lsb", "LSB"), | ||||
|         Mode("usb", "USB"), | ||||
|         Mode("cw", "CW"), | ||||
|         Mode("dmr", "DMR", requirements=["digital_voice_digiham"]), | ||||
|         Mode("dstar", "DStar", requirements=["digital_voice_dsd"]), | ||||
|         Mode("nxdn", "NXDN", requirements=["digital_voice_dsd"]), | ||||
|         Mode("ysf", "YSF", requirements=["digital_voice_digiham"]), | ||||
|         Mode("bpsk31", "BPSK31", digimode=True), | ||||
|         Mode("bpsk63", "BPSK63", digimode=True), | ||||
|         Mode("ft8", "FT8", requirements=["wsjt-x"], service=True, digimode=True), | ||||
|         Mode("ft4", "FT4", requirements=["wsjt-x"], service=True, digimode=True), | ||||
|         Mode("jt65", "JT65", requirements=["wsjt-x"], service=True, digimode=True), | ||||
|         Mode("jt9", "JT9", requirements=["wsjt-x"], service=True, digimode=True), | ||||
|         Mode("wspr", "WSPR", requirements=["wsjt-x"], service=True, digimode=True), | ||||
|         Mode("packet", "Packet", ["packet"], service=True, digimode=True), | ||||
|         Mode("js8", "JS8Call", requirements=["js8call"], service=True, digimode=True), | ||||
|     ] | ||||
|  | ||||
|     @staticmethod | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jakob Ketterl
					Jakob Ketterl