diff options
author | Alberto García Hierro <alberto@garciahierro.com> | 2018-06-20 17:21:40 +0300 |
---|---|---|
committer | Alberto García Hierro <alberto@garciahierro.com> | 2018-06-20 17:56:24 +0300 |
commit | 6da922919fb87023fc7bb47bdf81d356ee2a4c4c (patch) | |
tree | ae2d2a29b3d8717e7cc04de1ac715b29e25e5a6b | |
parent | ba45e316e3efa9c118582009584174bc884d6090 (diff) |
Add support for the new VTX settings API
When a controllable VTX is configured, a new section appears in
the configuration tab which allows the user to set the band, channel
power and "low power on disarm" option.
-rwxr-xr-x | _locales/en/messages.json | 37 | ||||
-rw-r--r-- | gulpfile.js | 1 | ||||
-rw-r--r-- | js/fc.js | 10 | ||||
-rw-r--r-- | js/msp/MSPCodes.js | 2 | ||||
-rw-r--r-- | js/msp/MSPHelper.js | 45 | ||||
-rw-r--r-- | js/vtx.js | 23 | ||||
-rw-r--r-- | tabs/configuration.html | 38 | ||||
-rw-r--r-- | tabs/configuration.js | 75 |
8 files changed, 229 insertions, 2 deletions
diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 0b0172dd..e6f393ca 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -804,7 +804,42 @@ "configurationButtonSave": { "message": "Save and Reboot" }, - + "configurationVTX": { + "message": "VTX" + }, + "configurationVTXBand": { + "message": "Band" + }, + "configurationNoBand": { + "message": "None" + }, + "configurationVTXNoBandHelp": { + "message": "VTX frequency has been set manually. Selecting a band will overwrite the configured frequency." + }, + "configurationVTXChannel": { + "message": "Channel" + }, + "configurationVTXPower": { + "message": "Power Level" + }, + "configurationVTXPowerHelp": { + "message": "VTX power level. The exact power in mw (or dBm) will depend on the specific hardware. Check your VTX manual." + }, + "configurationVTXLowerPowerDisarm": { + "message": "Use low power while the craft is disarmed" + }, + "configurationVTXLowerPowerDisarmHelp": { + "message": "Enabling this option will make the VTX use its lowest power while the craft is disarmed. Use 'Until first arm' to make it use the lowest power only until you arm for the first time." + }, + "configurationVTXLowPowerDisarmValue_0": { + "message": "Disabled" + }, + "configurationVTXLowPowerDisarmValue_1": { + "message": "Always" + }, + "configurationVTXLowPowerDisarmValue_2": { + "message": "Until first arm" + }, "portsHelp": { "message": "<strong>Note:</strong> not all combinations are valid. When the flight controller firmware detects this the serial port configuration will be reset." }, diff --git a/gulpfile.js b/gulpfile.js index dd5907e5..531e30e4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -97,6 +97,7 @@ sources.js = [ './js/tasks.js', './js/servoMixerRuleCollection.js', './js/motorMixerRuleCollection.js', + './js/vtx.js', './main.js', './tabs/*.js', './js/eventFrequencyAnalyzer.js', @@ -39,6 +39,7 @@ var CONFIG, RX_CONFIG, FAILSAFE_CONFIG, RXFAIL_CONFIG, + VTX_CONFIG, ADVANCED_CONFIG, INAV_PID_CONFIG, PID_ADVANCED, @@ -296,6 +297,15 @@ var FC = { capacity_unit: 0 }; + VTX_CONFIG = { + device_type: VTXDEV_UNKNOWN, + band: 0, + channel: 1, + power: 0, + pitmode: 0, + low_power_disarm: 0, + }; + ADVANCED_CONFIG = { gyroSyncDenominator: null, pidProcessDenom: null, diff --git a/js/msp/MSPCodes.js b/js/msp/MSPCodes.js index 9b5a3982..2e66ce8f 100644 --- a/js/msp/MSPCodes.js +++ b/js/msp/MSPCodes.js @@ -66,6 +66,8 @@ var MSPCodes = { MSP_SET_OSD_CONFIG: 85, MSP_OSD_CHAR_READ: 86, MSP_OSD_CHAR_WRITE: 87, + MSP_VTX_CONFIG: 88, + MSP_SET_VTX_CONFIG: 89, MSP_ADVANCED_CONFIG: 90, MSP_SET_ADVANCED_CONFIG: 91, MSP_FILTER_CONFIG: 92, diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 5fc95b12..3d091c2b 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -1052,7 +1052,18 @@ var mspHelper = (function (gui) { case MSPCodes.MSP_SET_TRANSPONDER_CONFIG: console.log("Transponder config saved"); break; - + case MSPCodes.MSP_VTX_CONFIG: + VTX_CONFIG.device_type = data.getUint8(offset++); + if (VTX_CONFIG.device_type != VTXDEV_UNKNOWN) { + VTX_CONFIG.band = data.getUint8(offset++); + VTX_CONFIG.channel = data.getUint8(offset++); + VTX_CONFIG.power = data.getUint8(offset++); + VTX_CONFIG.pitmode = data.getUint8(offset++); + // Ignore wether the VTX is ready for now + offset++; + VTX_CONFIG.low_power_disarm = data.getUint8(offset++); + } + break; case MSPCodes.MSP_ADVANCED_CONFIG: ADVANCED_CONFIG.gyroSyncDenominator = data.getUint8(offset); offset++; @@ -1069,6 +1080,10 @@ var mspHelper = (function (gui) { ADVANCED_CONFIG.gyroSync = data.getUint8(offset); break; + case MSPCodes.MSP_SET_VTX_CONFIG: + console.log("VTX config saved"); + break; + case MSPCodes.MSP_SET_ADVANCED_CONFIG: console.log("Advanced config saved"); break; @@ -1393,6 +1408,18 @@ var mspHelper = (function (gui) { buffer.push(lowByte(BF_CONFIG.currentoffset)); buffer.push(highByte(BF_CONFIG.currentoffset)); break; + case MSPCodes.MSP_SET_VTX_CONFIG: + if (VTX_CONFIG.band > 0) { + buffer.push16(((VTX_CONFIG.band - 1) * 8) + (VTX_CONFIG.channel - 1)); + } else { + // This tells the firmware to ignore this value. + buffer.push16(VTX_MAX_FREQUENCY_MHZ + 1); + } + buffer.push(VTX_CONFIG.power); + // Don't enable PIT mode + buffer.push(0); + buffer.push(VTX_CONFIG.low_power_disarm); + break; case MSPCodes.MSP_SET_PID: for (i = 0; i < PIDs.length; i++) { buffer.push(parseInt(PIDs[i][0])); @@ -2995,5 +3022,21 @@ var mspHelper = (function (gui) { } }; + self.loadVTXConfig = function (callback) { + if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) { + MSP.send_message(MSPCodes.MSP_VTX_CONFIG, false, false, callback); + } else { + callback(); + } + }; + + self.saveVTXConfig = function(callback) { + if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) { + MSP.send_message(MSPCodes.MSP_SET_VTX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_VTX_CONFIG), false, callback); + } else { + callback(); + } + } + return self; })(GUI); diff --git a/js/vtx.js b/js/vtx.js new file mode 100644 index 00000000..9fe89290 --- /dev/null +++ b/js/vtx.js @@ -0,0 +1,23 @@ +var VTXDEV_UNKNOWN = 0xFF; + +var VTX_BANDS = [ + {code: 1, name: 'Boscam A'}, + {code: 2, name: 'Boscam B'}, + {code: 3, name: 'Boscam E'}, + {code: 4, name: 'Fatshark'}, + {code: 5, name: 'Raceband'}, +]; + +var VTX_BAND_MIN = 1; +var VTX_BAND_MAX = 5; + +var VTX_CHANNEL_MIN = 1; +var VTX_CHANNEL_MAX = 8; + +var VTX_POWER_MIN = 0; +var VTX_POWER_MAX = 4; + +var VTX_LOW_POWER_DISARM_MIN = 0; +var VTX_LOW_POWER_DISARM_MAX = 2; + +var VTX_MAX_FREQUENCY_MHZ = 5999;
\ No newline at end of file diff --git a/tabs/configuration.html b/tabs/configuration.html index a9de427c..dc4ee416 100644 --- a/tabs/configuration.html +++ b/tabs/configuration.html @@ -232,6 +232,44 @@ </div> </div> + + <div class="config-section gui_box grey config-vtx"> + <div class="gui_box_titlebar"> + <div class="spacer_box_title" data-i18n="configurationVTX"></div> + </div> + <div class="spacer_box"> + <div class="note" id="vtx_no_band"> + <div class="note_spacer"> + <p data-i18n="configurationVTXNoBandHelp"></p> + </div> + </div> + + <div class="select vtx_band_wrapper"> + <select id="vtx_band"></select> + <label for="vtx_band"> + <span data-i18n="configurationVTXBand"></span> + </label> + </div> + + <div class="select vtx_channel_wrapper"> + <select id="vtx_channel"></select> + <label for="vtx_channel"> <span data-i18n="configurationVTXChannel"></span></label> + </div> + + <div class="select"> + <select id="vtx_power"></select> + <label for="vtx_power"><span data-i18n="configurationVTXPower"></span></label> + <div class="helpicon cf_tip" data-i18n_title="configurationVTXPowerHelp"></div> + </div> + + <div class="select"> + <select id="vtx_low_power_disarm"></select> + <label for="vtx_power"><span data-i18n="configurationVTXLowerPowerDisarm"></span></label> + <div class="helpicon cf_tip" data-i18n_title="configurationVTXLowerPowerDisarmHelp"></div> + </div> + </div> + </div> + </div> <!--Right column begins here--> diff --git a/tabs/configuration.js b/tabs/configuration.js index da31d89c..797b4bc0 100644 --- a/tabs/configuration.js +++ b/tabs/configuration.js @@ -34,6 +34,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) { mspHelper.loadAdvancedConfig, mspHelper.loadINAVPidConfig, mspHelper.loadSensorConfig, + mspHelper.loadVTXConfig, loadCraftName ]; @@ -60,6 +61,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) { mspHelper.saveAdvancedConfig, mspHelper.saveINAVPidConfig, mspHelper.saveSensorConfig, + mspHelper.saveVTXConfig, saveCraftName, ]; @@ -269,6 +271,79 @@ TABS.configuration.initialize = function (callback, scrollPosition) { gps_ubx_sbas_e.val(MISC.gps_ubx_sbas); + // VTX + var config_vtx = $('.config-vtx'); + if (VTX_CONFIG.device_type != VTXDEV_UNKNOWN) { + + var vtx_band = $('#vtx_band'); + vtx_band.empty(); + var vtx_no_band_note = $('#vtx_no_band'); + if (VTX_CONFIG.band < VTX_BAND_MIN || VTX_CONFIG.band > VTX_BAND_MAX) { + var noBandName = chrome.i18n.getMessage("configurationNoBand"); + $('<option value="0">' + noBandName + '</option>').appendTo(vtx_band); + vtx_no_band_note.show(); + } else { + vtx_no_band_note.hide(); + } + for (var ii = 0; ii < VTX_BANDS.length; ii++) { + var band_name = VTX_BANDS[ii].name; + var option = $('<option value="' + VTX_BANDS[ii].code + '">' + band_name + '</option>'); + if (VTX_BANDS[ii].code == VTX_CONFIG.band) { + option.prop('selected', true); + } + option.appendTo(vtx_band); + } + vtx_band.change(function () { + VTX_CONFIG.band = parseInt($(this).val()); + }); + + var vtx_channel = $('#vtx_channel'); + vtx_channel.empty(); + for (var ii = VTX_CHANNEL_MIN; ii <= VTX_CHANNEL_MAX; ii++) { + var option = $('<option value="' + ii + '">' + ii + '</option>'); + if (ii == VTX_CONFIG.channel) { + option.prop('selected', true); + } + option.appendTo(vtx_channel); + } + vtx_channel.change(function () { + VTX_CONFIG.channel = parseInt($(this).val()); + }); + + var vtx_power = $('#vtx_power'); + vtx_power.empty(); + for (var ii = VTX_POWER_MIN; ii <= VTX_POWER_MAX; ii++) { + var option = $('<option value="' + ii + '">' + ii + '</option>'); + if (ii == VTX_CONFIG.power) { + option.prop('selected', true); + } + option.appendTo(vtx_power); + } + vtx_power.change(function () { + VTX_CONFIG.power = parseInt($(this).val()); + }); + + var vtx_low_power_disarm = $('#vtx_low_power_disarm'); + vtx_low_power_disarm.empty(); + for (var ii = VTX_LOW_POWER_DISARM_MIN; ii <= VTX_LOW_POWER_DISARM_MAX; ii++) { + var name = chrome.i18n.getMessage("configurationVTXLowPowerDisarmValue_" + ii); + if (!name) { + name = ii; + } + var option = $('<option value="' + ii + '">' + name + '</option>'); + if (ii == VTX_CONFIG.low_power_disarm) { + option.prop('selected', true); + } + option.appendTo(vtx_low_power_disarm); + } + vtx_low_power_disarm.change(function () { + VTX_CONFIG.low_power_disarm = parseInt($(this).val()); + }); + + config_vtx.show(); + } else { + config_vtx.hide(); + } // generate serial RX var serialRxTypes = FC.getSerialRxTypes(); |