From 497d0aa674fb493fe9bf276a8299d30a8e1ceee6 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Tue, 4 Jun 2024 14:07:27 +0200 Subject: [PATCH] Store bindings --- js/defaults_dialog.js | 50 ++++++++++++++++++++++++------ js/defaults_dialog_entries.js | 12 +++++++- js/wizard_save_framework.js | 26 +++++++++++++--- js/wizard_ui_bindings.js | 57 +++++++++++++++++++++++++++++++++++ wizard/gps.html | 15 ++++++++- 5 files changed, 144 insertions(+), 16 deletions(-) diff --git a/js/defaults_dialog.js b/js/defaults_dialog.js index 06557eb7..77264594 100644 --- a/js/defaults_dialog.js +++ b/js/defaults_dialog.js @@ -72,6 +72,30 @@ 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 + }); + + privateScope.wizardSettings.push({ + name: "gpsBaud", + value: baud + }); + + privateScope.wizardSettings.push({ + name: "gpsProtocol", + value: protocol + }); + + // privateScope.wizardSettings.push({ + // }); + + // let gpsBit = FC.getFeatures().find( feature => feature.name === 'GPS' ).bit; } privateScope.wizard(selectedDefaultPreset, wizardStep + 1); @@ -88,13 +112,13 @@ var defaultsDialog = (function () { $container.hide(); wizardSaveFramework.persist(privateScope.wizardSettings, function () { - mspHelper.saveToEeprom(function () { - //noinspection JSUnresolvedVariable - GUI.log(i18n.getMessage('configurationEepromSaved')); - if (selectedDefaultPreset.reboot) { - privateScope.reboot(); - } - }); + // mspHelper.saveToEeprom(function () { + // //noinspection JSUnresolvedVariable + // GUI.log(i18n.getMessage('configurationEepromSaved')); + // if (selectedDefaultPreset.reboot) { + // privateScope.reboot(); + // } + // }); }); } else { const $content = $container.find('.defaults-dialog__wizard'); @@ -121,6 +145,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( @@ -346,9 +376,9 @@ var defaultsDialog = (function () { privateScope.onInitSettingReturned = function (promise) { - if (promise.value > 0) { - return; //Defaults were applied, we can just ignore - } + // if (promise.value > 0) { + // return; //Defaults were applied, we can just ignore + // } privateScope.render(); $container.show(); diff --git a/js/defaults_dialog_entries.js b/js/defaults_dialog_entries.js index 7bc3d0ee..fc8adad6 100644 --- a/js/defaults_dialog_entries.js +++ b/js/defaults_dialog_entries.js @@ -1,13 +1,23 @@ 'use strict'; var defaultsDialogData = [ + { + "title": 'Wizard', + "id": 63, + "notRecommended": false, + "reboot": false, + "mixerToApply": 3, + "wizardPages": ['receiver', 'gps'], + "settings": [ + ] + }, { "title": 'Mini Quad with 3" propellers', "id": 6, "notRecommended": false, "reboot": true, "mixerToApply": 3, - "wizardPages": ['receiver'], + "wizardPages": ['receiver', 'gps'], "settings": [ { key: "model_preview_type", diff --git a/js/wizard_save_framework.js b/js/wizard_save_framework.js index 04dd8f59..e4d27d32 100644 --- a/js/wizard_save_framework.js +++ b/js/wizard_save_framework.js @@ -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': @@ -22,6 +19,27 @@ var wizardSaveFramework = (function () { case 'receiverProtocol': mspHelper.setSetting('serialrx_provider', config.value, callback); break; + case 'gpsPort': + console.log(config); + + let gpsBit = FC.getFeatures().find( feature => feature.name === 'GPS' ).bit; + + if (config.value == '-1') { + features.unset(gpsBit); + + console.log('Unset GPS'); + + } else { + features.set(gpsBit); + console.log('Set GPS'); + } + break; + case 'gpsBaud': + console.log(config); + break; + case 'gpsProtocol': + console.log(config); + break; default: callback(); break; diff --git a/js/wizard_ui_bindings.js b/js/wizard_ui_bindings.js index 8125ba3d..1feb1dbe 100644 --- a/js/wizard_ui_bindings.js +++ b/js/wizard_ui_bindings.js @@ -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(''); + for (let i = 0; i < availablePorts.length; i++) { + let port = availablePorts[i]; + $port.append(''); + } + + serialPortHelper.getBauds('SENSOR').forEach(function (baud) { + $baud.append(''); + }); + + let gpsProtocols = FC.getGpsProtocols(); + for (let i = 0; i < gpsProtocols.length; i++) { + $protocol.append(''); + } + + 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 () { diff --git a/wizard/gps.html b/wizard/gps.html index 1177218c..0ad656df 100644 --- a/wizard/gps.html +++ b/wizard/gps.html @@ -1 +1,14 @@ -

GPS wizard

\ No newline at end of file +

GPS wizard

+

+ 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 None. +

+
+ +
+ + \ No newline at end of file