From c27d9563239e6fd49734503c7bf744d6875dede8 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sat, 2 Nov 2019 15:24:56 +0100 Subject: [PATCH 1/3] Dummy dialog --- _locales/en/messages.json | 6 + gulpfile.js | 4 +- js/defaults_dialog.js | 79 +++++++ js/serial_backend.js | 1 + main.html | 434 ++++++++++++++++++++---------------- src/css/defaults_dialog.css | 45 ++++ 6 files changed, 377 insertions(+), 192 deletions(-) create mode 100644 js/defaults_dialog.js create mode 100644 src/css/defaults_dialog.css diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 992af658..4b8c1bde 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -3224,5 +3224,11 @@ }, "vtxDisclaimer": { "message": "Use only bands, channels and power levels that are legal in a place you fly! Always refer to VTX user manual and local regulations!" + }, + "defaultsDialogTitle": { + "message": "Default values" + }, + "defaultsDialogInfo": { + "message": "INAV Configurator would like to know which kind of UAV you are configuring. Based on this information it will modify some default values to unlock the best flying performance. " } } diff --git a/gulpfile.js b/gulpfile.js index e1f3fc30..4df300a5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -50,7 +50,8 @@ sources.css = [ './js/libraries/switchery/switchery.css', './js/libraries/jbox/jBox.css', './node_modules/openlayers/dist/ol.css', - './src/css/logic.css' + './src/css/logic.css', + './src/css/defaults_dialog.css' ]; sources.js = [ @@ -113,6 +114,7 @@ sources.js = [ './tabs/advanced_tuning.js', './js/peripherals.js', './js/appUpdater.js', + './js/defaults_dialog.js', './node_modules/openlayers/dist/ol.js' ]; diff --git a/js/defaults_dialog.js b/js/defaults_dialog.js new file mode 100644 index 00000000..61f5ca88 --- /dev/null +++ b/js/defaults_dialog.js @@ -0,0 +1,79 @@ +'use strict'; + +var helper = helper || {}; + +helper.defaultsDialog = (function() { + + let publicScope = {}, + privateScope = {}; + + let $container; + + let data = [{ + "title": 'Mini Quad with 3"-7" propellers', + "id": 2, + "settings": { + "gyro_lpf": "256HZ", + "looptime": 500 + } + }, + { + "title": 'Airplane', + "id": 3 + }, + { + "title": 'Custom UAV - INAV legacy defaults', + "id": 1 + } + ] + + publicScope.init = function() { + mspHelper.getSetting("applied_defaults").then(privateScope.onInitSettingReturned); + $container = $("#defaults-wrapper"); + }; + + privateScope.onPresetClick = function(event) { + let preset = data[$(event.currentTarget).data("index")]; + if (preset) { + + let promises = {}; + Object.keys(presets.settings).forEach(function(key, ii) { + let value = presets.settings[key]; + promises[key] = mspHelper.setSetting(name, value); + }); + + console.log(promises); + // Promise.props(promises).then(function() { + // saveChainer.execute(); + // }); + + } + }; + + privateScope.render = function() { + let $place = $container.find('.defaults-dialog__options'); + for (let i in data) { + if (data.hasOwnProperty(i)) { + let preset = data[i]; + let $element = $("
\ + \ +
") + + $element.find("a").html(preset.title); + $element.data("index", i).click(privateScope.onPresetClick) + $element.appendTo($place); + } + } + } + + privateScope.onInitSettingReturned = function(promise) { + if (promise.value > 0) { + return; //Defaults were applied, we can just ignore + } + + privateScope.render(); + $container.show(); + } + + return publicScope; +})(); \ No newline at end of file diff --git a/js/serial_backend.js b/js/serial_backend.js index 7061992c..ee8530d5 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -336,6 +336,7 @@ function onConnect() { }, 100); helper.interval.add('global_data_refresh', helper.periodicStatusUpdater.run, helper.periodicStatusUpdater.getUpdateInterval(serial.bitrate), false); + helper.defaultsDialog.init(); } function onClosed(result) { diff --git a/main.html b/main.html index cc1445d4..b749fcf6 100755 --- a/main.html +++ b/main.html @@ -1,56 +1,57 @@ + - - + + + -
- -
-