Skip to content

Commit

Permalink
Merge pull request #2112 from iNavFlight/wizard-gps-step
Browse files Browse the repository at this point in the history
Wizard GPS step
  • Loading branch information
DzikuVx authored Jun 17, 2024
2 parents 80cf875 + f6df2c0 commit e17965d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 11 deletions.
23 changes: 23 additions & 0 deletions js/defaults_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ var defaultsDialog = (function () {
name: "receiverProtocol",
value: $container.find('#wizard-receiver-protocol option:selected').text()
});
} else if (stepName == "gps") {
let port = $container.find('#wizard-gps-port').val();
let baud = $container.find('#wizard-gps-baud').val();
let protocol = $container.find('#wizard-gps-protocol option:selected').text();

privateScope.wizardSettings.push({
name: "gpsPort",
value: {
port: port,
baud: baud
}
});

privateScope.wizardSettings.push({
name: "gpsProtocol",
value: protocol
});
}

privateScope.wizard(selectedDefaultPreset, wizardStep + 1);
Expand Down Expand Up @@ -121,6 +138,12 @@ var defaultsDialog = (function () {
* Bindings executed when the receiver wizard tab is loaded
*/
wizardUiBindings.receiver($content);
} else if (stepName == "gps") {
/**
* Bindings executed when the GPS wizard tab is loaded
*
*/
wizardUiBindings.gps($content);
}

Settings.configureInputs().then(
Expand Down
12 changes: 6 additions & 6 deletions js/defaults_dialog_entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var defaultsDialogData = [
"notRecommended": false,
"reboot": true,
"mixerToApply": 3,
"wizardPages": ['receiver'],
"wizardPages": ['receiver', 'gps'],
"settings": [
{
key: "model_preview_type",
Expand Down Expand Up @@ -129,7 +129,7 @@ var defaultsDialogData = [
"notRecommended": false,
"reboot": true,
"mixerToApply": 3,
"wizardPages": ['receiver'],
"wizardPages": ['receiver', 'gps'],
"settings": [
{
key: "model_preview_type",
Expand Down Expand Up @@ -270,7 +270,7 @@ var defaultsDialogData = [
"notRecommended": false,
"reboot": true,
"mixerToApply": 3,
"wizardPages": ['receiver'],
"wizardPages": ['receiver', 'gps'],
"settings": [
{
key: "model_preview_type",
Expand Down Expand Up @@ -392,7 +392,7 @@ var defaultsDialogData = [
"id": 3,
"reboot": true,
"mixerToApply": 14,
"wizardPages": ['receiver'],
"wizardPages": ['receiver', 'gps'],
"settings": [
{
key: "model_preview_type",
Expand Down Expand Up @@ -598,7 +598,7 @@ var defaultsDialogData = [
"id": 4,
"reboot": true,
"mixerToApply": 8,
"wizardPages": ['receiver'],
"wizardPages": ['receiver', 'gps'],
"settings": [
{
key: "model_preview_type",
Expand Down Expand Up @@ -804,7 +804,7 @@ var defaultsDialogData = [
"notRecommended": false,
"reboot": true,
"mixerToApply": 31,
"wizardPages": ['receiver'],
"wizardPages": ['receiver', 'gps'],
"settings": [
{
key: "model_preview_type",
Expand Down
23 changes: 19 additions & 4 deletions js/wizard_save_framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
const mspHelper = require('./msp/MSPHelper');
const serialPortHelper = require('./serialPortHelper');
const FC = require('./fc');
const features = require('./feature_framework');

var wizardSaveFramework = (function () {

let self = {};

self.saveSetting = function (config, callback) {
/*
serialrx_provider to 2
serialrx_provider to 6
*/

switch (config.name) {
case 'receiverPort':
Expand All @@ -22,6 +19,24 @@ var wizardSaveFramework = (function () {
case 'receiverProtocol':
mspHelper.setSetting('serialrx_provider', config.value, callback);
break;
case 'gpsPort':

let gpsBit = FC.getFeatures().find( feature => feature.name === 'GPS' ).bit;

if (config.value.port == '-1') {
features.unset(gpsBit);
} else {
features.set(gpsBit);
}

serialPortHelper.set(config.value.port, 'GPS', config.value.baud);
mspHelper.saveSerialPorts(function () {
features.execute(callback);
});
break;
case 'gpsProtocol':
mspHelper.setSetting('gps_provider', config.value, callback);
break;
default:
callback();
break;
Expand Down
57 changes: 57 additions & 0 deletions js/wizard_ui_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,68 @@

const mspHelper = require('./msp/MSPHelper');
const serialPortHelper = require('./serialPortHelper');
const FC = require('./fc');

const wizardUiBindings = (function () {

let self = {};

self.gps = function ($context) {
mspHelper.loadFeatures(mspHelper.loadSerialPorts(function () {

let $port = $('#wizard-gps-port');
let $baud = $('#wizard-gps-baud');
let $protocol = $('#wizard-gps-protocol');

let ports = serialPortHelper.getPortIdentifiersForFunction('GPS');

let currentPort = null;

if (ports.length == 1) {
currentPort = ports[0];
}

let availablePorts = serialPortHelper.getPortList();
$port.append('<option value="-1">None</option>');
for (let i = 0; i < availablePorts.length; i++) {
let port = availablePorts[i];
$port.append('<option value="' + port.identifier + '">' + port.displayName + '</option>');
}

serialPortHelper.getBauds('SENSOR').forEach(function (baud) {
$baud.append('<option value="' + baud + '">' + baud + '</option>');
});

let gpsProtocols = FC.getGpsProtocols();
for (let i = 0; i < gpsProtocols.length; i++) {
$protocol.append('<option value="' + i + '">' + gpsProtocols[i] + '</option>');
}

if (currentPort !== null) {
$port.val(currentPort);
} else {
$port.val(-1);
}

$port.on('change', function () {
let port = $(this).val();

let portConfig = serialPortHelper.getPortByIdentifier(currentPort);
$baud.val(portConfig.sensors_baudrate);
if (port == -1) {
$('#wizard-gps-baud-container').hide();
$('#wizard-gps-protocol-container').hide();
$baud.val(serialPortHelper.getRuleByName('GPS').defaultBaud);
} else {
$('#wizard-gps-baud-container').show();
$('#wizard-gps-protocol-container').show();
}
}).trigger('change');

}));

};

self.receiver = function ($content) {

mspHelper.loadSerialPorts(function () {
Expand Down
15 changes: 14 additions & 1 deletion wizard/gps.html
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
<h2>GPS wizard</h2>
<h2>GPS wizard</h2>
<p>
Configure GPS and port. If you unsure about serial port or protocol, click `Skip` to go to the next page.
You can change those settings later with the configurator UI. If no GPS installed, choose <b>None</b>.
</p>
<div>
<label for="wizard-gps-port">GPS Serial Port</label><select id="wizard-gps-port"></select>
</div>
<div style="display: none;" id="wizard-gps-baud-container">
<label for="wizard-gps-baud">GPS Baud Rate</label><select id="wizard-gps-baud"></select>
</div>
<div style="display: none;" id="wizard-gps-protocol-container">
<label for="wizard-gps-protocol">GPS Protocol</label><select id="wizard-gps-protocol"></select>
</div>

0 comments on commit e17965d

Please sign in to comment.