mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-26 09:45:28 +03:00
Change lexical scope receiver and failsafe
This commit is contained in:
parent
317f937fd5
commit
1a3dc52f58
3 changed files with 180 additions and 197 deletions
|
@ -1,54 +1,51 @@
|
|||
"use strict";
|
||||
|
||||
let css_dark = [
|
||||
'/css/dark-theme.css'
|
||||
];
|
||||
const css_dark = [
|
||||
'/css/dark-theme.css',
|
||||
];
|
||||
|
||||
|
||||
var
|
||||
CHANNEL_MIN_VALUE = 1000,
|
||||
CHANNEL_MID_VALUE = 1500,
|
||||
CHANNEL_MAX_VALUE = 2000,
|
||||
const CHANNEL_MIN_VALUE = 1000;
|
||||
const CHANNEL_MID_VALUE = 1500;
|
||||
const CHANNEL_MAX_VALUE = 2000;
|
||||
|
||||
// What's the index of each channel in the MSP channel list?
|
||||
channelMSPIndexes = {
|
||||
Roll: 0,
|
||||
Pitch: 1,
|
||||
Throttle: 2,
|
||||
Yaw: 3,
|
||||
Aux1: 4,
|
||||
Aux2: 5,
|
||||
Aux3: 6,
|
||||
Aux4: 7,
|
||||
},
|
||||
const channelMSPIndexes = {
|
||||
Roll: 0,
|
||||
Pitch: 1,
|
||||
Throttle: 2,
|
||||
Yaw: 3,
|
||||
Aux1: 4,
|
||||
Aux2: 5,
|
||||
Aux3: 6,
|
||||
Aux4: 7,
|
||||
};
|
||||
|
||||
// Set reasonable initial stick positions (Mode 2)
|
||||
stickValues = {
|
||||
Throttle: CHANNEL_MIN_VALUE,
|
||||
Pitch: CHANNEL_MID_VALUE,
|
||||
Roll: CHANNEL_MID_VALUE,
|
||||
Yaw: CHANNEL_MID_VALUE,
|
||||
Aux1: CHANNEL_MIN_VALUE,
|
||||
Aux2: CHANNEL_MIN_VALUE,
|
||||
Aux3: CHANNEL_MIN_VALUE,
|
||||
Aux4: CHANNEL_MIN_VALUE
|
||||
},
|
||||
const stickValues = {
|
||||
Throttle: CHANNEL_MIN_VALUE,
|
||||
Pitch: CHANNEL_MID_VALUE,
|
||||
Roll: CHANNEL_MID_VALUE,
|
||||
Yaw: CHANNEL_MID_VALUE,
|
||||
Aux1: CHANNEL_MIN_VALUE,
|
||||
Aux2: CHANNEL_MIN_VALUE,
|
||||
Aux3: CHANNEL_MIN_VALUE,
|
||||
Aux4: CHANNEL_MIN_VALUE,
|
||||
};
|
||||
|
||||
// First the vertical axis, then the horizontal:
|
||||
gimbals = [
|
||||
["Throttle", "Yaw"],
|
||||
["Pitch", "Roll"],
|
||||
],
|
||||
const gimbals = [
|
||||
["Throttle", "Yaw"],
|
||||
["Pitch", "Roll"],
|
||||
];
|
||||
|
||||
gimbalElems,
|
||||
sliderElems,
|
||||
|
||||
enableTX = false;
|
||||
let gimbalElems;
|
||||
let sliderElems;
|
||||
let enableTX = false;
|
||||
|
||||
// This is a hack to get the i18n var of the parent, but the localizePage not works
|
||||
const i18n = opener.i18n;
|
||||
|
||||
let watchers = {
|
||||
const watchers = {
|
||||
darkTheme: (val) => {
|
||||
if (val) {
|
||||
applyDarkTheme();
|
||||
|
@ -60,7 +57,7 @@ let watchers = {
|
|||
|
||||
$(document).ready(function () {
|
||||
$('[i18n]:not(.i18n-replaced)').each(function() {
|
||||
var element = $(this);
|
||||
const element = $(this);
|
||||
|
||||
element.html(i18n.getMessage(element.attr('i18n')));
|
||||
element.addClass('i18n-replaced');
|
||||
|
@ -70,14 +67,13 @@ $(document).ready(function () {
|
|||
});
|
||||
|
||||
function transmitChannels() {
|
||||
var
|
||||
channelValues = [0, 0, 0, 0, 0, 0, 0, 0];
|
||||
const channelValues = [0, 0, 0, 0, 0, 0, 0, 0];
|
||||
|
||||
if (!enableTX) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var stickName in stickValues) {
|
||||
for (const stickName in stickValues) {
|
||||
channelValues[channelMSPIndexes[stickName]] = stickValues[stickName];
|
||||
}
|
||||
|
||||
|
@ -99,14 +95,12 @@ function channelValueToStickPortion(channel) {
|
|||
}
|
||||
|
||||
function updateControlPositions() {
|
||||
for (var stickName in stickValues) {
|
||||
var
|
||||
stickValue = stickValues[stickName];
|
||||
for (const stickName in stickValues) {
|
||||
const stickValue = stickValues[stickName];
|
||||
|
||||
// Look for the gimbal which corresponds to this stick name
|
||||
for (var gimbalIndex in gimbals) {
|
||||
var
|
||||
gimbal = gimbals[gimbalIndex],
|
||||
for (const gimbalIndex in gimbals) {
|
||||
const gimbal = gimbals[gimbalIndex],
|
||||
gimbalElem = gimbalElems.get(gimbalIndex),
|
||||
gimbalSize = $(gimbalElem).width(),
|
||||
stickElem = $(".control-stick", gimbalElem);
|
||||
|
@ -123,8 +117,7 @@ function updateControlPositions() {
|
|||
}
|
||||
|
||||
function handleGimbalMouseDrag(e) {
|
||||
var
|
||||
gimbal = $(gimbalElems.get(e.data.gimbalIndex)),
|
||||
const gimbal = $(gimbalElems.get(e.data.gimbalIndex)),
|
||||
gimbalOffset = gimbal.offset(),
|
||||
gimbalSize = gimbal.width();
|
||||
|
||||
|
@ -135,31 +128,29 @@ function handleGimbalMouseDrag(e) {
|
|||
}
|
||||
|
||||
function localizeAxisNames() {
|
||||
for (var gimbalIndex in gimbals) {
|
||||
var
|
||||
gimbal = gimbalElems.get(gimbalIndex);
|
||||
for (const gimbalIndex in gimbals) {
|
||||
const gimbal = gimbalElems.get(gimbalIndex);
|
||||
|
||||
$(".gimbal-label-vert", gimbal).text(i18n.getMessage("controlAxis" + gimbals[gimbalIndex][0]));
|
||||
$(".gimbal-label-horz", gimbal).text(i18n.getMessage("controlAxis" + gimbals[gimbalIndex][1]));
|
||||
}
|
||||
|
||||
for (var sliderIndex = 0; sliderIndex < 4; sliderIndex++) {
|
||||
for (let sliderIndex = 0; sliderIndex < 4; sliderIndex++) {
|
||||
$(".slider-label", sliderElems.get(sliderIndex)).text(i18n.getMessage("controlAxisAux" + (sliderIndex + 1)));
|
||||
}
|
||||
}
|
||||
|
||||
function applyDarkTheme() {
|
||||
css_dark.forEach((el) => $('link[href="' + el + '"]').prop('disabled', false));
|
||||
};
|
||||
}
|
||||
|
||||
function applyNormalTheme() {
|
||||
css_dark.forEach((el) => $('link[href="' + el + '"]').prop('disabled', true));
|
||||
};
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$(".button-enable .btn").click(function() {
|
||||
var
|
||||
shrinkHeight = $(".warning").height();
|
||||
const shrinkHeight = $(".warning").height();
|
||||
|
||||
$(".warning").slideUp("short", function() {
|
||||
chrome.app.window.current().innerBounds.minHeight -= shrinkHeight;
|
||||
|
@ -184,8 +175,7 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$(".slider", sliderElems).each(function(sliderIndex) {
|
||||
var
|
||||
initialValue = stickValues["Aux" + (sliderIndex + 1)];
|
||||
const initialValue = stickValues[`Aux${sliderIndex + 1}`];
|
||||
|
||||
$(this)
|
||||
.noUiSlider({
|
||||
|
@ -197,7 +187,7 @@ $(document).ready(function() {
|
|||
}).on('slide change set', function(e, value) {
|
||||
value = Math.round(parseFloat(value));
|
||||
|
||||
stickValues["Aux" + (sliderIndex + 1)] = value;
|
||||
stickValues[`Aux${(sliderIndex + 1)}`] = value;
|
||||
|
||||
$(".tooltip", this).text(value);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue