mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 21:05:30 +03:00
parent
704970e291
commit
483dec9103
34 changed files with 559 additions and 546 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -31,3 +31,4 @@ nbproject/
|
|||
# Eclipse
|
||||
.project
|
||||
.settings/
|
||||
test-results-junit/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
import GUI from './gui.js';
|
||||
|
||||
/**
|
||||
* Encapsulates the Clipboard logic, depending on web or nw
|
||||
|
@ -99,3 +99,5 @@ if (GUI.isNWJS()){
|
|||
} else {
|
||||
Clipboard._configureClipboardAsOther();
|
||||
}
|
||||
|
||||
export default Clipboard;
|
||||
|
|
151
src/js/gui.js
151
src/js/gui.js
|
@ -1,6 +1,3 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
window.TABS = {}; // filled by individual tab js file
|
||||
|
||||
const GUI_MODES = {
|
||||
|
@ -9,7 +6,8 @@ const GUI_MODES = {
|
|||
Other: "Other",
|
||||
};
|
||||
|
||||
const GuiControl = function () {
|
||||
class GuiControl {
|
||||
constructor() {
|
||||
this.auto_connect = false;
|
||||
this.connecting_to = false;
|
||||
this.connected_to = false;
|
||||
|
@ -71,19 +69,13 @@ const GuiControl = function () {
|
|||
this.Mode = GUI_MODES.Other;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function GUI_checkOperatingSystem() {
|
||||
return navigator?.userAgentData?.platform || 'Android';
|
||||
}
|
||||
|
||||
// Timer managing methods
|
||||
|
||||
// name = string
|
||||
// code = function reference (code to be executed)
|
||||
// interval = time interval in miliseconds
|
||||
// first = true/false if code should be ran initially before next timer interval hits
|
||||
GuiControl.prototype.interval_add = function (name, code, interval, first) {
|
||||
interval_add(name, code, interval, first) {
|
||||
const data = { 'name': name, 'timer': null, 'code': code, 'interval': interval, 'fired': 0, 'paused': false };
|
||||
|
||||
if (first === true) {
|
||||
|
@ -101,14 +93,13 @@ GuiControl.prototype.interval_add = function (name, code, interval, first) {
|
|||
this.interval_array.push(data); // push to primary interval array
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
}
|
||||
// name = string
|
||||
// code = function reference (code to be executed)
|
||||
// interval = time interval in miliseconds
|
||||
// first = true/false if code should be ran initially before next timer interval hits
|
||||
// condition = function reference with true/false result, a condition to be checked before every interval code execution
|
||||
GuiControl.prototype.interval_add_condition = function (name, code, interval, first, condition) {
|
||||
interval_add_condition(name, code, interval, first, condition) {
|
||||
this.interval_add(name, () => {
|
||||
if (condition()) {
|
||||
code();
|
||||
|
@ -116,10 +107,9 @@ GuiControl.prototype.interval_add_condition = function (name, code, interval, fi
|
|||
this.interval_remove(name);
|
||||
}
|
||||
}, interval, first);
|
||||
};
|
||||
|
||||
}
|
||||
// name = string
|
||||
GuiControl.prototype.interval_remove = function (name) {
|
||||
interval_remove(name) {
|
||||
for (let i = 0; i < this.interval_array.length; i++) {
|
||||
if (this.interval_array[i].name === name) {
|
||||
clearInterval(this.interval_array[i].timer); // stop timer
|
||||
|
@ -131,10 +121,9 @@ GuiControl.prototype.interval_remove = function (name) {
|
|||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
}
|
||||
// name = string
|
||||
GuiControl.prototype.interval_pause = function (name) {
|
||||
interval_pause(name) {
|
||||
for (let i = 0; i < this.interval_array.length; i++) {
|
||||
if (this.interval_array[i].name === name) {
|
||||
clearInterval(this.interval_array[i].timer);
|
||||
|
@ -145,10 +134,9 @@ GuiControl.prototype.interval_pause = function (name) {
|
|||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
}
|
||||
// name = string
|
||||
GuiControl.prototype.interval_resume = function (name) {
|
||||
interval_resume(name) {
|
||||
|
||||
function executeCode(obj) {
|
||||
obj.code(); // execute code
|
||||
|
@ -168,11 +156,10 @@ GuiControl.prototype.interval_resume = function (name) {
|
|||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
}
|
||||
// input = array of timers thats meant to be kept, or nothing
|
||||
// return = returns timers killed in last call
|
||||
GuiControl.prototype.interval_kill_all = function (keepArray) {
|
||||
interval_kill_all(keepArray) {
|
||||
const self = this;
|
||||
let timersKilled = 0;
|
||||
|
||||
|
@ -196,14 +183,14 @@ GuiControl.prototype.interval_kill_all = function (keepArray) {
|
|||
}
|
||||
|
||||
return timersKilled;
|
||||
};
|
||||
|
||||
}
|
||||
// name = string
|
||||
// code = function reference (code to be executed)
|
||||
// timeout = timeout in miliseconds
|
||||
GuiControl.prototype.timeout_add = function (name, code, timeout) {
|
||||
timeout_add(name, code, timeout) {
|
||||
const self = this;
|
||||
const data = {'name': name,
|
||||
const data = {
|
||||
'name': name,
|
||||
'timer': null,
|
||||
'timeout': timeout,
|
||||
};
|
||||
|
@ -212,6 +199,7 @@ GuiControl.prototype.timeout_add = function (name, code, timeout) {
|
|||
data.timer = setTimeout(function () {
|
||||
code(); // execute code
|
||||
|
||||
|
||||
// remove object from array
|
||||
const index = self.timeout_array.indexOf(data);
|
||||
if (index > -1) {
|
||||
|
@ -222,10 +210,9 @@ GuiControl.prototype.timeout_add = function (name, code, timeout) {
|
|||
this.timeout_array.push(data); // push to primary timeout array
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
}
|
||||
// name = string
|
||||
GuiControl.prototype.timeout_remove = function (name) {
|
||||
timeout_remove(name) {
|
||||
for (let i = 0; i < this.timeout_array.length; i++) {
|
||||
if (this.timeout_array[i].name === name) {
|
||||
clearTimeout(this.timeout_array[i].timer); // stop timer
|
||||
|
@ -237,11 +224,10 @@ GuiControl.prototype.timeout_remove = function (name) {
|
|||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
}
|
||||
// no input parameters
|
||||
// return = returns timers killed in last call
|
||||
GuiControl.prototype.timeout_kill_all = function () {
|
||||
timeout_kill_all() {
|
||||
let timersKilled = 0;
|
||||
|
||||
for (let i = 0; i < this.timeout_array.length; i++) {
|
||||
|
@ -253,10 +239,9 @@ GuiControl.prototype.timeout_kill_all = function () {
|
|||
this.timeout_array = []; // drop objects
|
||||
|
||||
return timersKilled;
|
||||
};
|
||||
|
||||
}
|
||||
// message = string
|
||||
GuiControl.prototype.log = function (message) {
|
||||
log(message) {
|
||||
const commandLog = $('div#log');
|
||||
const d = new Date();
|
||||
const year = d.getFullYear();
|
||||
|
@ -270,12 +255,11 @@ GuiControl.prototype.log = function (message) {
|
|||
const formattedDate = `${year}-${month}-${date} @${time}`;
|
||||
$('div.wrapper', commandLog).append(`<p>${formattedDate} -- ${message}</p>`);
|
||||
commandLog.scrollTop($('div.wrapper', commandLog).height());
|
||||
};
|
||||
|
||||
}
|
||||
// Method is called every time a valid tab change event is received
|
||||
// callback = code to run when cleanup is finished
|
||||
// default switch doesn't require callback to be set
|
||||
GuiControl.prototype.tab_switch_cleanup = function (callback) {
|
||||
tab_switch_cleanup(callback) {
|
||||
MSP.callbacks_cleanup(); // we don't care about any old data that might or might not arrive
|
||||
this.interval_kill_all(); // all intervals (mostly data pulling) needs to be removed on tab switch
|
||||
|
||||
|
@ -284,9 +268,8 @@ GuiControl.prototype.tab_switch_cleanup = function (callback) {
|
|||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
GuiControl.prototype.switchery = function() {
|
||||
}
|
||||
switchery() {
|
||||
|
||||
const COLOR_ACCENT = 'var(--accent)';
|
||||
const COLOR_SWITCHERY_SECOND = 'var(--switcherysecond)';
|
||||
|
@ -325,9 +308,8 @@ GuiControl.prototype.switchery = function() {
|
|||
});
|
||||
$(elem).removeClass('togglemedium');
|
||||
});
|
||||
};
|
||||
|
||||
GuiControl.prototype.content_ready = function (callback) {
|
||||
}
|
||||
content_ready(callback) {
|
||||
|
||||
this.switchery();
|
||||
|
||||
|
@ -374,28 +356,23 @@ GuiControl.prototype.content_ready = function (callback) {
|
|||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
GuiControl.prototype.selectDefaultTabWhenConnected = function() {
|
||||
}
|
||||
selectDefaultTabWhenConnected() {
|
||||
const result = ConfigStorage.get(['rememberLastTab', 'lastTab']);
|
||||
const tab = result.rememberLastTab && result.lastTab ? result.lastTab : 'tab_setup';
|
||||
|
||||
$(`#tabs ul.mode-connected .${tab} a`).trigger('click');
|
||||
};
|
||||
|
||||
GuiControl.prototype.isNWJS = function () {
|
||||
}
|
||||
isNWJS() {
|
||||
return this.Mode === GUI_MODES.NWJS;
|
||||
};
|
||||
|
||||
GuiControl.prototype.isCordova = function () {
|
||||
}
|
||||
isCordova() {
|
||||
return this.Mode === GUI_MODES.Cordova;
|
||||
};
|
||||
GuiControl.prototype.isOther = function () {
|
||||
}
|
||||
isOther() {
|
||||
return this.Mode === GUI_MODES.Other;
|
||||
};
|
||||
|
||||
|
||||
GuiControl.prototype.showYesNoDialog = function(yesNoDialogSettings) {
|
||||
}
|
||||
showYesNoDialog(yesNoDialogSettings) {
|
||||
// yesNoDialogSettings:
|
||||
// title, text, buttonYesText, buttonNoText, buttonYesCallback, buttonNoCallback
|
||||
const dialog = $(".dialogYesNo");
|
||||
|
@ -423,9 +400,8 @@ GuiControl.prototype.showYesNoDialog = function(yesNoDialogSettings) {
|
|||
});
|
||||
|
||||
dialog[0].showModal();
|
||||
};
|
||||
|
||||
GuiControl.prototype.showWaitDialog = function(waitDialogSettings) {
|
||||
}
|
||||
showWaitDialog(waitDialogSettings) {
|
||||
// waitDialogSettings:
|
||||
// title, buttonCancelCallback
|
||||
const dialog = $(".dialogWait")[0];
|
||||
|
@ -444,9 +420,8 @@ GuiControl.prototype.showWaitDialog = function(waitDialogSettings) {
|
|||
|
||||
dialog.showModal();
|
||||
return dialog;
|
||||
};
|
||||
|
||||
GuiControl.prototype.showInformationDialog = function(informationDialogSettings) {
|
||||
}
|
||||
showInformationDialog(informationDialogSettings) {
|
||||
// informationDialogSettings:
|
||||
// title, text, buttonConfirmText
|
||||
return new Promise(resolve => {
|
||||
|
@ -468,9 +443,8 @@ GuiControl.prototype.showInformationDialog = function(informationDialogSettings)
|
|||
|
||||
dialog[0].showModal();
|
||||
});
|
||||
};
|
||||
|
||||
GuiControl.prototype.saveToTextFileDialog = function(textToSave, suggestedFileName, extension) {
|
||||
}
|
||||
saveToTextFileDialog(textToSave, suggestedFileName, extension) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const accepts = [{ description: `${extension.toUpperCase()} files`, extensions: [extension] }];
|
||||
|
||||
|
@ -483,9 +457,8 @@ GuiControl.prototype.saveToTextFileDialog = function(textToSave, suggestedFileNa
|
|||
entry => this._saveToTextFileDialogFileSelected(entry, textToSave, resolve, reject),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
GuiControl.prototype._saveToTextFileDialogFileSelected = function(entry, textToSave, resolve, reject) {
|
||||
}
|
||||
_saveToTextFileDialogFileSelected(entry, textToSave, resolve, reject) {
|
||||
checkChromeRuntimeError();
|
||||
|
||||
if (!entry) {
|
||||
|
@ -515,9 +488,8 @@ GuiControl.prototype._saveToTextFileDialogFileSelected = function(entry, textToS
|
|||
reject();
|
||||
console.error('Failed to get file writer');
|
||||
});
|
||||
};
|
||||
|
||||
GuiControl.prototype.readTextFileDialog = function(extension) {
|
||||
}
|
||||
readTextFileDialog(extension) {
|
||||
const accepts = [{ description: `${extension.toUpperCase()} files`, extensions: [extension] }];
|
||||
|
||||
return new Promise(resolve => {
|
||||
|
@ -541,22 +513,29 @@ GuiControl.prototype.readTextFileDialog = function(extension) {
|
|||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
GuiControl.prototype.escapeHtml = function(unsafe) {
|
||||
}
|
||||
escapeHtml(unsafe) {
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
};
|
||||
|
||||
GuiControl.prototype.addLinksTargetBlank = function(element) {
|
||||
}
|
||||
addLinksTargetBlank(element) {
|
||||
element.find('a').each(function () {
|
||||
$(this).attr('target', '_blank');
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function GUI_checkOperatingSystem() {
|
||||
return navigator?.userAgentData?.platform || 'Android';
|
||||
}
|
||||
|
||||
const GUI = new GuiControl();
|
||||
|
||||
// initialize object into GUI variable
|
||||
window.GUI = new GuiControl();
|
||||
window.GUI = GUI;
|
||||
|
||||
export default GUI;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import i18next from 'i18next';
|
||||
import i18nextXHRBackend from 'i18next-xhr-backend';
|
||||
import GUI from './gui.js';
|
||||
|
||||
const i18n = {};
|
||||
/*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import '../components/init.js';
|
||||
import { i18n } from './localization.js';
|
||||
import GUI from './gui.js';
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const adjustments = {};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const auxiliary = {};
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { i18n } from "../localization";
|
||||
import Clipboard from "../Clipboard";
|
||||
import GUI from '../gui';
|
||||
|
||||
const cli = {
|
||||
lineDelayMs: 15,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import semver from 'semver';
|
||||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const configuration = {
|
||||
// intended
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const failsafe = {};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const firmware_flasher = {
|
||||
targets: null,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const gps = {};
|
||||
gps.initialize = function (callback) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import GUI from '../gui';
|
||||
|
||||
const help = {};
|
||||
help.initialize = function (callback) {
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import GUI from '../gui';
|
||||
|
||||
const landing = {};
|
||||
landing.initialize = function (callback) {
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const led_strip = {
|
||||
wireMode: false,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { millitime } from '../utils/common.js';
|
||||
import GUI from '../gui';
|
||||
|
||||
const logging = {};
|
||||
logging.initialize = function (callback) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const motors = {
|
||||
previousDshotBidir: null,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
let sdcardTimer;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const options = {};
|
||||
options.initialize = function (callback) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const FONT = {};
|
||||
const SYM = {};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { i18n } from "../localization";
|
||||
import { colorTables, getColorForPercentage } from '../utils/css.js';
|
||||
import GUI from '../gui';
|
||||
|
||||
const pid_tuning = {
|
||||
RATE_PROFILE_MASK: 128,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import semver from 'semver';
|
||||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const ports = {
|
||||
// intentional
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const power = {
|
||||
supported: false,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const MD5 = require('md5.js');
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const sensors = {};
|
||||
sensors.initialize = function (callback) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const servos = {};
|
||||
servos.initialize = function (callback) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const setup = {
|
||||
yaw_fix: 0.0,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const setup_osd = {
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from '../localization';
|
||||
import GUI from '../gui';
|
||||
|
||||
const staticTab = {};
|
||||
staticTab.initialize = function (staticTabName, callback) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { i18n } from "../localization";
|
||||
import GUI from '../gui';
|
||||
|
||||
const transponder = {
|
||||
available: false,
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { i18n } from "../localization";
|
||||
import Clipboard from "../Clipboard";
|
||||
import GUI from '../gui';
|
||||
|
||||
const vtx = {
|
||||
supported: false,
|
||||
|
|
|
@ -90,7 +90,6 @@
|
|||
<script type="text/javascript" src="./js/port_handler.js"></script>
|
||||
<script type="text/javascript" src="./js/port_usage.js"></script>
|
||||
<script type="text/javascript" src="./js/serial.js"></script>
|
||||
<script type="text/javascript" src="./js/gui.js"></script>
|
||||
<script type="text/javascript" src="./js/mdns_discovery.js"></script>
|
||||
<script type="text/javascript" src="./js/huffman.js"></script>
|
||||
<script type="text/javascript" src="./js/default_huffman_tree.js"></script>
|
||||
|
@ -113,7 +112,6 @@
|
|||
<script type="text/javascript" src="./js/ConfigInserter.js"></script>
|
||||
<script type="text/javascript" src="./js/GitHubApi.js"></script>
|
||||
<script type="module" src="./js/main.js"></script>
|
||||
<script type="text/javascript" src="./js/Clipboard.js"></script>
|
||||
<!-- TODO: might be removed when everythign is in modules -->
|
||||
<script type="text/javascript" src="./tabs/presets/CliEngine.js"></script>
|
||||
<script type="text/javascript" src="./tabs/presets/PickedPreset.js"></script>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
import GUI from '../../js/gui';
|
||||
|
||||
import { favoritePresets } from './FavoritePresets';
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports = function(config) {
|
|||
'./src/js/serial.js',
|
||||
'./src/js/data_storage.js',
|
||||
{ pattern: './src/js/localization.js', type: 'module', watched: false },
|
||||
'./src/js/gui.js',
|
||||
{ pattern: './src/js/gui.js', type: 'module', watched: false },
|
||||
'./src/js/CliAutoComplete.js',
|
||||
{ pattern: './src/js/tabs/cli.js', type: 'module', watched: false },
|
||||
'./src/js/phones_ui.js',
|
||||
|
@ -41,6 +41,7 @@ module.exports = function(config) {
|
|||
preprocessors: {
|
||||
'./src/js/localization.js': ['rollup'],
|
||||
'./src/js/tabs/cli.js': ['rollup'],
|
||||
'./src/js/gui.js': ['rollup'],
|
||||
},
|
||||
rollupPreprocessor: {
|
||||
plugins: [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue