mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-24 00:35:26 +03:00
Merge pull request #2182 from chmelevskij/chore/add-vue
This commit is contained in:
commit
7fcc9efc72
27 changed files with 1511 additions and 283 deletions
138
src/js/fc.js
138
src/js/fc.js
|
@ -1,5 +1,61 @@
|
|||
'use strict';
|
||||
|
||||
const INITIAL_CONFIG = {
|
||||
apiVersion: "0.0.0",
|
||||
flightControllerIdentifier: '',
|
||||
flightControllerVersion: '',
|
||||
version: 0,
|
||||
buildInfo: '',
|
||||
multiType: 0,
|
||||
msp_version: 0, // not specified using semantic versioning
|
||||
capability: 0,
|
||||
cycleTime: 0,
|
||||
i2cError: 0,
|
||||
activeSensors: 0,
|
||||
mode: 0,
|
||||
profile: 0,
|
||||
uid: [0, 0, 0],
|
||||
accelerometerTrims: [0, 0],
|
||||
name: '',
|
||||
displayName: 'JOE PILOT',
|
||||
numProfiles: 3,
|
||||
rateProfile: 0,
|
||||
boardType: 0,
|
||||
armingDisableCount: 0,
|
||||
armingDisableFlags: 0,
|
||||
armingDisabled: false,
|
||||
runawayTakeoffPreventionDisabled: false,
|
||||
boardIdentifier: "",
|
||||
boardVersion: 0,
|
||||
targetCapabilities: 0,
|
||||
targetName: "",
|
||||
boardName: "",
|
||||
manufacturerId: "",
|
||||
signature: [],
|
||||
mcuTypeId: 255,
|
||||
configurationState: 0,
|
||||
sampleRateHz: 0,
|
||||
configurationProblems: 0,
|
||||
hardwareName: '',
|
||||
};
|
||||
|
||||
const INITIAL_ANALOG = {
|
||||
voltage: 0,
|
||||
mAhdrawn: 0,
|
||||
rssi: 0,
|
||||
amperage: 0,
|
||||
last_received_timestamp: Date.now(), // FIXME this code lies, it's never been received at this point
|
||||
};
|
||||
|
||||
const INITIAL_BATTERY_CONFIG = {
|
||||
vbatmincellvoltage: 0,
|
||||
vbatmaxcellvoltage: 0,
|
||||
vbatwarningcellvoltage: 0,
|
||||
capacity: 0,
|
||||
voltageMeterSource: 0,
|
||||
currentMeterSource: 0,
|
||||
};
|
||||
|
||||
const FC = {
|
||||
|
||||
// define all the global variables that are uses to hold FC state
|
||||
|
@ -7,17 +63,43 @@ const FC = {
|
|||
ADJUSTMENT_RANGES: null,
|
||||
ADVANCED_TUNING: null,
|
||||
ADVANCED_TUNING_ACTIVE: null,
|
||||
ANALOG: null,
|
||||
ANALOG: {...INITIAL_CONFIG},
|
||||
ARMING_CONFIG: null,
|
||||
AUX_CONFIG: null,
|
||||
AUX_CONFIG_IDS: null,
|
||||
BATTERY_CONFIG: null,
|
||||
BATTERY_CONFIG: {...INITIAL_BATTERY_CONFIG},
|
||||
BATTERY_STATE: null,
|
||||
BEEPER_CONFIG: null,
|
||||
BF_CONFIG: null, // Remove when we officialy retire BF 3.1
|
||||
BLACKBOX: null,
|
||||
BOARD_ALIGNMENT_CONFIG: null,
|
||||
CONFIG: null,
|
||||
// Shallow copy of original config and added getter
|
||||
// getter allows this to be used with simple dot notation
|
||||
// and bridges the vue and rest of the code
|
||||
CONFIG: {
|
||||
...INITIAL_CONFIG,
|
||||
get hardwareName() {
|
||||
let name;
|
||||
if (this.targetName) {
|
||||
name = this.targetName;
|
||||
} else {
|
||||
name = this.boardIdentifier;
|
||||
}
|
||||
|
||||
if (this.boardName && this.boardName !== name) {
|
||||
name = `${this.boardName}(${name})`;
|
||||
}
|
||||
|
||||
if (this.manufacturerId) {
|
||||
name = `${this.manufacturerId}/${name}`;
|
||||
}
|
||||
|
||||
return name;
|
||||
},
|
||||
set hardwareName(name) {
|
||||
// NOOP, can't really be set. Maybe implement some logic?
|
||||
},
|
||||
},
|
||||
COPY_PROFILE: null,
|
||||
CURRENT_METERS: null,
|
||||
CURRENT_METER_CONFIGS: null,
|
||||
|
@ -72,43 +154,11 @@ const FC = {
|
|||
VTX_CONFIG: null,
|
||||
|
||||
resetState () {
|
||||
this.CONFIG = {
|
||||
apiVersion: "0.0.0",
|
||||
flightControllerIdentifier: '',
|
||||
flightControllerVersion: '',
|
||||
version: 0,
|
||||
buildInfo: '',
|
||||
multiType: 0,
|
||||
msp_version: 0, // not specified using semantic versioning
|
||||
capability: 0,
|
||||
cycleTime: 0,
|
||||
i2cError: 0,
|
||||
activeSensors: 0,
|
||||
mode: 0,
|
||||
profile: 0,
|
||||
uid: [0, 0, 0],
|
||||
accelerometerTrims: [0, 0],
|
||||
name: '',
|
||||
displayName: 'JOE PILOT',
|
||||
numProfiles: 3,
|
||||
rateProfile: 0,
|
||||
boardType: 0,
|
||||
armingDisableCount: 0,
|
||||
armingDisableFlags: 0,
|
||||
armingDisabled: false,
|
||||
runawayTakeoffPreventionDisabled: false,
|
||||
boardIdentifier: "",
|
||||
boardVersion: 0,
|
||||
targetCapabilities: 0,
|
||||
targetName: "",
|
||||
boardName: "",
|
||||
manufacturerId: "",
|
||||
signature: [],
|
||||
mcuTypeId: 255,
|
||||
configurationState: 0,
|
||||
sampleRateHz: 0,
|
||||
configurationProblems: 0,
|
||||
};
|
||||
// Using `Object.assign` instead of reassigning to
|
||||
// trigger the updates on the Vue side
|
||||
Object.assign(this.CONFIG, INITIAL_CONFIG);
|
||||
Object.assign(this.ANALOG, INITIAL_CONFIG);
|
||||
Object.assign(this.BATTERY_CONFIG, INITIAL_BATTERY_CONFIG);
|
||||
|
||||
this.BF_CONFIG = {
|
||||
currentscale: 0,
|
||||
|
@ -249,13 +299,6 @@ const FC = {
|
|||
cno: [],
|
||||
};
|
||||
|
||||
this.ANALOG = {
|
||||
voltage: 0,
|
||||
mAhdrawn: 0,
|
||||
rssi: 0,
|
||||
amperage: 0,
|
||||
last_received_timestamp: Date.now(), // FIXME this code lies, it's never been received at this point
|
||||
};
|
||||
|
||||
this.VOLTAGE_METERS = [];
|
||||
this.VOLTAGE_METER_CONFIGS = [];
|
||||
|
@ -671,6 +714,7 @@ const FC = {
|
|||
return name;
|
||||
},
|
||||
|
||||
|
||||
MCU_TYPES: {
|
||||
0: "SIMULATOR",
|
||||
1: "F103",
|
||||
|
|
|
@ -39,7 +39,6 @@ i18n.init = function(cb) {
|
|||
i18n.addResources({"detectedLanguage": detectedLanguage });
|
||||
i18next.on('languageChanged', function () {
|
||||
i18n.localizePage(true);
|
||||
updateStatusBarVersion();
|
||||
});
|
||||
}
|
||||
if (cb !== undefined) {
|
||||
|
|
|
@ -188,9 +188,9 @@ function startProcess() {
|
|||
}
|
||||
|
||||
$('.connect_b a.connect').removeClass('disabled');
|
||||
$('#logo .version, #tab_logoversion .version').text(CONFIGURATOR.version);
|
||||
updateStatusBarVersion();
|
||||
updateTopBarVersion();
|
||||
// with Vue reactive system we don't need to call these,
|
||||
// our view is reactive to model changes
|
||||
// updateTopBarVersion();
|
||||
|
||||
if (!GUI.isOther() && GUI.operating_system !== 'ChromeOS') {
|
||||
checkForConfiguratorUpdates();
|
||||
|
@ -580,10 +580,6 @@ function notifyOutdatedVersion(releaseData) {
|
|||
});
|
||||
}
|
||||
|
||||
function update_packet_error(caller) {
|
||||
$('span.packet-error').html(caller.packet_error);
|
||||
}
|
||||
|
||||
function microtime() {
|
||||
return new Date().getTime() / 1000;
|
||||
}
|
||||
|
@ -704,62 +700,6 @@ function generateFilename(prefix, suffix) {
|
|||
return `${filename}.${suffix}`;
|
||||
}
|
||||
|
||||
function getTargetVersion(hardwareId) {
|
||||
let versionText = '';
|
||||
|
||||
if (hardwareId) {
|
||||
versionText = `${i18n.getMessage('versionLabelTarget')}: ${hardwareId}`;
|
||||
}
|
||||
|
||||
return versionText;
|
||||
}
|
||||
|
||||
function getFirmwareVersion(firmwareVersion, firmwareId) {
|
||||
let versionText = '';
|
||||
|
||||
if (firmwareVersion) {
|
||||
versionText = `${i18n.getMessage('versionLabelFirmware')}: ${firmwareId} ${firmwareVersion}`;
|
||||
}
|
||||
|
||||
return versionText;
|
||||
}
|
||||
|
||||
function getConfiguratorVersion() {
|
||||
return `${i18n.getMessage('versionLabelConfigurator')}: ${CONFIGURATOR.version}`;
|
||||
}
|
||||
|
||||
function updateTopBarVersion(firmwareVersion, firmwareId, hardwareId) {
|
||||
|
||||
const configuratorVersion = getConfiguratorVersion();
|
||||
const firmwareVersionAndId = getFirmwareVersion(firmwareVersion, firmwareId);
|
||||
const targetVersion = getTargetVersion(hardwareId);
|
||||
|
||||
const versionText = `${configuratorVersion}<br />${firmwareVersionAndId}<br />${targetVersion}`;
|
||||
|
||||
$('#logo .logo_text, #tab_logoversion .version').html(versionText);
|
||||
}
|
||||
|
||||
function updateStatusBarVersion(firmwareVersion, firmwareId, hardwareId) {
|
||||
let versionText = '';
|
||||
|
||||
versionText = versionText + getFirmwareVersion(firmwareVersion, firmwareId);
|
||||
|
||||
if (versionText !== '') {
|
||||
versionText = `${versionText}, `;
|
||||
}
|
||||
|
||||
const targetVersion = getTargetVersion(hardwareId);
|
||||
versionText = versionText + targetVersion;
|
||||
|
||||
if (targetVersion !== '') {
|
||||
versionText = `${versionText}, `;
|
||||
}
|
||||
|
||||
versionText = `${versionText}${getConfiguratorVersion()} (${CONFIGURATOR.gitChangesetId})`;
|
||||
|
||||
$('#status-bar .version').text(versionText);
|
||||
}
|
||||
|
||||
function showErrorDialog(message) {
|
||||
const dialog = $('.dialogError')[0];
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ MSPConnectorImpl.prototype.connect = function (port, baud, onConnectCallback, on
|
|||
|
||||
serial.onReceive.addListener(read_serial);
|
||||
|
||||
MSP.listen(update_packet_error);
|
||||
mspHelper = new MspHelper();
|
||||
MSP.listen(mspHelper.process_data.bind(mspHelper));
|
||||
|
||||
|
|
|
@ -83,8 +83,6 @@ MspHelper.prototype.process_data = function(dataHandler) {
|
|||
TABS.pid_tuning.checkUpdateProfile(false);
|
||||
|
||||
sensor_status(FC.CONFIG.activeSensors);
|
||||
$('span.i2c-error').text(FC.CONFIG.i2cError);
|
||||
$('span.cycle-time').text(FC.CONFIG.cycleTime);
|
||||
break;
|
||||
case MSPCodes.MSP_STATUS_EX:
|
||||
FC.CONFIG.cycleTime = data.readU16();
|
||||
|
@ -113,9 +111,6 @@ MspHelper.prototype.process_data = function(dataHandler) {
|
|||
}
|
||||
|
||||
sensor_status(FC.CONFIG.activeSensors);
|
||||
$('span.i2c-error').text(FC.CONFIG.i2cError);
|
||||
$('span.cycle-time').text(FC.CONFIG.cycleTime);
|
||||
$('span.cpu-load').text(i18n.getMessage('statusbar_cpu_load', [FC.CONFIG.cpuload]));
|
||||
break;
|
||||
|
||||
case MSPCodes.MSP_RAW_IMU:
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
var PortUsage = {
|
||||
previous_received: 0,
|
||||
previous_sent: 0,
|
||||
port_usage_down: 0,
|
||||
port_usage_up: 0,
|
||||
|
||||
initialize: function() {
|
||||
var self = this;
|
||||
|
@ -18,17 +20,19 @@ var PortUsage = {
|
|||
|
||||
this.previous_received = serial.bytesReceived;
|
||||
this.previous_sent = serial.bytesSent;
|
||||
this.port_usage_down = port_usage_down;
|
||||
this.port_usage_up = port_usage_up;
|
||||
|
||||
// update UI
|
||||
$('span.port_usage_down').text(i18n.getMessage('statusbar_usage_download', [port_usage_down]));
|
||||
$('span.port_usage_up').text(i18n.getMessage('statusbar_usage_upload', [port_usage_up]));
|
||||
} else {
|
||||
$('span.port_usage_down').text(i18n.getMessage('statusbar_usage_download', [0]));
|
||||
$('span.port_usage_up').text(i18n.getMessage('statusbar_usage_upload', [0]));
|
||||
this.port_usage_down = 0;
|
||||
this.port_usage_up = 0;
|
||||
}
|
||||
},
|
||||
reset: function() {
|
||||
this.previous_received = 0;
|
||||
this.previous_sent = 0;
|
||||
|
||||
this.port_usage_down = 0;
|
||||
this.port_usage_up = 0;
|
||||
}
|
||||
};
|
|
@ -169,18 +169,14 @@ function finishClose(finishedCallback) {
|
|||
|
||||
MSP.disconnect_cleanup();
|
||||
PortUsage.reset();
|
||||
// To trigger the UI updates by Vue reset the state.
|
||||
FC.resetState();
|
||||
|
||||
GUI.connected_to = false;
|
||||
GUI.allowedTabs = GUI.defaultAllowedTabsWhenDisconnected.slice();
|
||||
// close problems dialog
|
||||
$('#dialogReportProblems-closebtn').click();
|
||||
|
||||
// Reset various UI elements
|
||||
$('span.i2c-error').text(0);
|
||||
$('span.cycle-time').text(0);
|
||||
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0"))
|
||||
$('span.cpu-load').text('');
|
||||
|
||||
// unlock port select & baud
|
||||
$('div#port-picker #port').prop('disabled', false);
|
||||
if (!GUI.auto_connect) $('div#port-picker #baud').prop('disabled', false);
|
||||
|
@ -228,7 +224,6 @@ function onOpen(openInfo) {
|
|||
setConnectionTimeout();
|
||||
|
||||
FC.resetState();
|
||||
MSP.listen(update_packet_error);
|
||||
mspHelper = new MspHelper();
|
||||
MSP.listen(mspHelper.process_data.bind(mspHelper));
|
||||
|
||||
|
@ -247,8 +242,6 @@ function onOpen(openInfo) {
|
|||
analytics.setFlightControllerData(analytics.DATA.FIRMWARE_VERSION, FC.CONFIG.flightControllerVersion);
|
||||
|
||||
GUI.log(i18n.getMessage('fcInfoReceived', [FC.CONFIG.flightControllerIdentifier, FC.CONFIG.flightControllerVersion]));
|
||||
updateStatusBarVersion(FC.CONFIG.flightControllerVersion, FC.CONFIG.flightControllerIdentifier);
|
||||
updateTopBarVersion(FC.CONFIG.flightControllerVersion, FC.CONFIG.flightControllerIdentifier);
|
||||
|
||||
MSP.send_message(MSPCodes.MSP_BUILD_INFO, false, false, function () {
|
||||
|
||||
|
@ -318,8 +311,6 @@ function processBoardInfo() {
|
|||
analytics.setFlightControllerData(analytics.DATA.MCU_TYPE, FC.getMcuType());
|
||||
|
||||
GUI.log(i18n.getMessage('boardInfoReceived', [FC.getHardwareName(), FC.CONFIG.boardVersion]));
|
||||
updateStatusBarVersion(FC.CONFIG.flightControllerVersion, FC.CONFIG.flightControllerIdentifier, FC.getHardwareName());
|
||||
updateTopBarVersion(FC.CONFIG.flightControllerVersion, FC.CONFIG.flightControllerIdentifier, FC.getHardwareName());
|
||||
|
||||
if (bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.SUPPORTS_CUSTOM_DEFAULTS) && bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_CUSTOM_DEFAULTS) && FC.CONFIG.configurationState === FC.CONFIGURATION_STATES.DEFAULTS_BARE) {
|
||||
var dialog = $('#dialogResetToCustomDefaults')[0];
|
||||
|
@ -538,9 +529,6 @@ function onClosed(result) {
|
|||
$('#tabs ul.mode-connected-cli').hide();
|
||||
$('#tabs ul.mode-disconnected').show();
|
||||
|
||||
updateStatusBarVersion();
|
||||
updateTopBarVersion();
|
||||
|
||||
var sensor_state = $('#sensor-status');
|
||||
sensor_state.hide();
|
||||
|
||||
|
@ -725,9 +713,6 @@ function update_live_status() {
|
|||
$(".battery-status").addClass('state-ok').removeClass('state-warning').removeClass('state-empty');
|
||||
}
|
||||
}
|
||||
|
||||
let cellsText = (FC.ANALOG.voltage > NO_BATTERY_VOLTAGE_MAXIMUM)? nbCells + 'S' : 'USB';
|
||||
$(".battery-legend").text(FC.ANALOG.voltage.toFixed(2) + "V (" + cellsText + ")");
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue