diff --git a/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js b/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js index 6b350254d2f..e5d5067b0af 100644 --- a/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js +++ b/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js @@ -5,6 +5,7 @@ import { reinitializeConnection } from "../../js/serial_backend"; import MSP from "../../js/msp"; import MSPCodes from "../../js/msp/MSPCodes"; import FC from "../../js/fc"; +import { gui_log } from "../../js/gui_log"; export default class MotorOutputReorderComponent { @@ -97,7 +98,7 @@ export default class MotorOutputReorderComponent function reboot() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); GUI.tab_switch_cleanup(() => MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(TABS.motors))); } diff --git a/src/js/Beepers.js b/src/js/Beepers.js index 466b8914d50..7dc2efce486 100644 --- a/src/js/Beepers.js +++ b/src/js/Beepers.js @@ -1,4 +1,4 @@ -import { bit_check, bit_clear, bit_set } from './serial_backend'; +import { bit_check, bit_clear, bit_set } from './bit'; class Beepers { constructor(config, supportedConditions) { diff --git a/src/js/BuildApi.js b/src/js/BuildApi.js index 911afc582dd..577c9fde314 100644 --- a/src/js/BuildApi.js +++ b/src/js/BuildApi.js @@ -1,4 +1,4 @@ -import GUI from "./gui"; +import { gui_log } from './gui_log'; import { i18n } from "./localization"; import { get as getStorage, set as setStorage } from "./SessionStorage"; @@ -21,7 +21,7 @@ export default class BuildApi { const cachedCallback = () => { if (cachedData) { - GUI.log(i18n.getMessage('buildServerUsingCached', [url])); + gui_log(i18n.getMessage('buildServerUsingCached', [url])); } onSuccess(cachedData); @@ -36,7 +36,7 @@ export default class BuildApi { setStorage(object); onSuccess(info); }).fail(xhr => { - GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); + gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); if (onFailure !== undefined) { onFailure(); } else { @@ -70,10 +70,10 @@ export default class BuildApi { const url = `${this._url}${path}`; $.get(url, function (data) { - GUI.log(i18n.getMessage('buildServerSuccess', [path])); + gui_log(i18n.getMessage('buildServerSuccess', [path])); onSuccess(data); }).fail(xhr => { - GUI.log(i18n.getMessage('buildServerFailure', [path, `HTTP ${xhr.status}`])); + gui_log(i18n.getMessage('buildServerFailure', [path, `HTTP ${xhr.status}`])); if (onFailure !== undefined) { onFailure(); } @@ -86,7 +86,7 @@ export default class BuildApi { $.get(url, function (data) { onSuccess(data); }).fail(xhr => { - GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); + gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); if (onFailure !== undefined) { onFailure(); } @@ -107,7 +107,7 @@ export default class BuildApi { onSuccess(response); }, }).fail(xhr => { - GUI.log(i18n.getMessage('buildServerFailure', [`HTTP ${xhr.status}`])); + gui_log(i18n.getMessage('buildServerFailure', [`HTTP ${xhr.status}`])); if (onFailure !== undefined) { onFailure(); } @@ -128,7 +128,7 @@ export default class BuildApi { onSuccess(response); }, }).fail(xhr => { - GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); + gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); if (onFailure !== undefined) { onFailure(); } @@ -139,10 +139,10 @@ export default class BuildApi { const url = `${this._url}/api/builds/${key}/status`; $.get(url, function (data) { - GUI.log(i18n.getMessage('buildServerSuccess', [url])); + gui_log(i18n.getMessage('buildServerSuccess', [url])); onSuccess(data); }).fail(xhr => { - GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); + gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`])); if (onFailure !== undefined) { onFailure(); } diff --git a/src/js/CliAutoComplete.js b/src/js/CliAutoComplete.js index ac8816efd2f..8bf15419964 100644 --- a/src/js/CliAutoComplete.js +++ b/src/js/CliAutoComplete.js @@ -1,5 +1,6 @@ import GUI from './gui'; import CONFIGURATOR from './data_storage'; +import FC from './fc'; /** * Encapsulates the AutoComplete logic diff --git a/src/js/Features.js b/src/js/Features.js index 16c5632ab03..91c5a93aaee 100644 --- a/src/js/Features.js +++ b/src/js/Features.js @@ -1,4 +1,4 @@ -import { bit_check, bit_set, bit_clear } from "./serial_backend"; +import { bit_check, bit_set, bit_clear } from "./bit"; import { API_VERSION_1_44 } from './data_storage'; const Features = function (config) { diff --git a/src/js/LogoManager.js b/src/js/LogoManager.js index 88a4e252fe2..664c06646a8 100644 --- a/src/js/LogoManager.js +++ b/src/js/LogoManager.js @@ -1,4 +1,4 @@ -import GUI from "./gui"; +import { gui_log } from "./gui_log"; import { i18n } from "./localization"; /** @@ -131,7 +131,7 @@ LogoManager.init = function (font, logoStartIndex) { const constraint = this.constraints.imageSize; if (img.width !== constraint.expectedWidth || img.height !== constraint.expectedHeight) { - GUI.log(i18n.getMessage("osdSetupCustomLogoImageSizeError", { + gui_log(i18n.getMessage("osdSetupCustomLogoImageSizeError", { width: img.width, height: img.height, })); @@ -157,7 +157,7 @@ LogoManager.init = function (font, logoStartIndex) { const rgbPixel = ctx.getImageData(x, y, 1, 1).data.slice(0, 3), colorKey = rgbPixel.join("-"); if (!this.constants.MCM_COLORMAP[colorKey]) { - GUI.log(i18n.getMessage("osdSetupCustomLogoColorMapError", { + gui_log(i18n.getMessage("osdSetupCustomLogoColorMapError", { valueR: rgbPixel[0], valueG: rgbPixel[1], valueB: rgbPixel[2], diff --git a/src/js/VirtualFC.js b/src/js/VirtualFC.js index 41a21739ebd..21a43152f56 100644 --- a/src/js/VirtualFC.js +++ b/src/js/VirtualFC.js @@ -1,4 +1,5 @@ import Features from "./Features"; +import { i18n } from "./localization"; import Beepers from "./Beepers"; import FC from "./fc"; import CONFIGURATOR from "./data_storage"; diff --git a/src/js/backup_restore.js b/src/js/backup_restore.js index e12a983288f..c849dbdd2a1 100644 --- a/src/js/backup_restore.js +++ b/src/js/backup_restore.js @@ -1,4 +1,6 @@ -import { sensor_status, update_dataflash_global, reinitializeConnection } from "./serial_backend"; +import { reinitializeConnection } from "./serial_backend"; +import { update_dataflash_global } from "./update_dataflash_global"; +import { sensor_status } from "./sensor_helpers.js"; import GUI from "./gui"; import Features from "./Features"; import { i18n } from "./localization"; @@ -8,6 +10,7 @@ import { mspHelper } from "./msp/MSPHelper"; import MSP from "./msp"; import MSPCodes from "./msp/MSPCodes"; import CONFIGURATOR, { API_VERSION_1_41, API_VERSION_1_45 } from "./data_storage"; +import { gui_log } from './gui_log'; // code below is highly experimental, although it runs fine on latest firmware // the data inside nested objects needs to be verified if deep copy works properly @@ -308,7 +311,7 @@ export function configuration_restore(callback) { // validate if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.BACKUP_FILE_VERSION_MIN_SUPPORTED)) { if (!compareVersions(configuration.generatedBy, "1.14.0") && !migrate(configuration)) { - GUI.log(i18n.getMessage('backupFileUnmigratable')); + gui_log(i18n.getMessage('backupFileUnmigratable')); return; } if (configuration.FEATURE_CONFIG.features._featureMask) { @@ -321,7 +324,7 @@ export function configuration_restore(callback) { configuration_upload(configuration, callback); } else { - GUI.log(i18n.getMessage('backupFileIncompatible')); + gui_log(i18n.getMessage('backupFileIncompatible')); } } }; @@ -341,7 +344,7 @@ export function configuration_restore(callback) { function migrate(configuration) { let appliedMigrationsCount = 0; let migratedVersion = configuration.generatedBy; - GUI.log(i18n.getMessage('configMigrationFrom', [migratedVersion])); + gui_log(i18n.getMessage('configMigrationFrom', [migratedVersion])); if (!compareVersions(migratedVersion, '0.59.1')) { @@ -350,7 +353,7 @@ export function configuration_restore(callback) { configuration.MISC.rssi_aux_channel = undefined; migratedVersion = '0.59.1'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -362,7 +365,7 @@ export function configuration_restore(callback) { } migratedVersion = '0.60.1'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -377,7 +380,7 @@ export function configuration_restore(callback) { } migratedVersion = '0.61.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -407,7 +410,7 @@ export function configuration_restore(callback) { } migratedVersion = '0.63.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -463,7 +466,7 @@ export function configuration_restore(callback) { ports: ports, }; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -483,7 +486,7 @@ export function configuration_restore(callback) { }; } - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -523,7 +526,7 @@ export function configuration_restore(callback) { migratedVersion = '0.66.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -541,7 +544,7 @@ export function configuration_restore(callback) { configuration.profiles[profileIndex].PID.controller = newPidControllerIndex; } - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -558,7 +561,7 @@ export function configuration_restore(callback) { }; } - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -625,7 +628,7 @@ export function configuration_restore(callback) { } } - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -636,7 +639,7 @@ export function configuration_restore(callback) { } migratedVersion = '1.2.0'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -652,12 +655,12 @@ export function configuration_restore(callback) { migratedVersion = '1.3.1'; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } if (appliedMigrationsCount > 0) { - GUI.log(i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount])); + gui_log(i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount])); } return true; } @@ -882,7 +885,7 @@ export function configuration_restore(callback) { } function reboot() { - GUI.log(i18n.getMessage('eeprom_saved_ok')); + gui_log(i18n.getMessage('eeprom_saved_ok')); GUI.tab_switch_cleanup(function() { MSP.Promise(MSPCodes.MSP_SET_REBOOT) diff --git a/src/js/bit.js b/src/js/bit.js new file mode 100644 index 00000000000..b447147a8a0 --- /dev/null +++ b/src/js/bit.js @@ -0,0 +1,11 @@ +export function bit_check(num, bit) { + return (num >> bit) % 2 != 0; +} + +export function bit_set(num, bit) { + return num | (1 << bit); +} + +export function bit_clear(num, bit) { + return num & ~(1 << bit); +} diff --git a/src/js/fc.js b/src/js/fc.js index 7c29a4680e2..96ab2ba4078 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -1,4 +1,4 @@ -import { bit_check } from "./serial_backend"; +import { bit_check } from "./bit"; import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from './data_storage'; const INITIAL_CONFIG = { @@ -162,7 +162,6 @@ const FC = { VTX_DEVICE_STATUS: null, resetState () { - console.log('resetting state'); // Using `Object.assign` instead of reassigning to // trigger the updates on the Vue side Object.assign(this.CONFIG, INITIAL_CONFIG); @@ -904,6 +903,4 @@ const FC = { }, }; -// temp binding to global scope -window.FC = FC; export default FC; diff --git a/src/js/gui.js b/src/js/gui.js index 62439989b11..e72eb5566d7 100644 --- a/src/js/gui.js +++ b/src/js/gui.js @@ -243,22 +243,7 @@ class GuiControl { return timersKilled; } - // message = string - log(message) { - const commandLog = $('div#log'); - const d = new Date(); - const year = d.getFullYear(); - const month = (d.getMonth() < 9) ? `0${d.getMonth() + 1}` : (d.getMonth() + 1); - const date = (d.getDate() < 10) ? `0${d.getDate()}` : d.getDate(); - const hours = (d.getHours() < 10) ? `0${d.getHours()}` : d.getHours(); - const minutes = (d.getMinutes() < 10) ? `0${d.getMinutes()}` : d.getMinutes(); - const seconds = (d.getSeconds() < 10) ? `0${d.getSeconds()}` : d.getSeconds(); - const time = `${hours}:${minutes}:${seconds}`; - - const formattedDate = `${year}-${month}-${date} @${time}`; - $('div.wrapper', commandLog).append(`

${formattedDate} -- ${message}

`); - 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 diff --git a/src/js/gui_log.js b/src/js/gui_log.js new file mode 100644 index 00000000000..f45874aa866 --- /dev/null +++ b/src/js/gui_log.js @@ -0,0 +1,21 @@ +/** + * log to GUI + * @param {string} message message to log to GUI + */ +export function gui_log(message) { + const commandLog = $("div#log"); + const d = new Date(); + const year = d.getFullYear(); + const month = d.getMonth() < 9 ? `0${d.getMonth() + 1}` : d.getMonth() + 1; + const date = d.getDate() < 10 ? `0${d.getDate()}` : d.getDate(); + const hours = d.getHours() < 10 ? `0${d.getHours()}` : d.getHours(); + const minutes = d.getMinutes() < 10 ? `0${d.getMinutes()}` : d.getMinutes(); + const seconds = d.getSeconds() < 10 ? `0${d.getSeconds()}` : d.getSeconds(); + const time = `${hours}:${minutes}:${seconds}`; + + const formattedDate = `${year}-${month}-${date} @${time}`; + $("div.wrapper", commandLog).append( + `

${formattedDate} -- ${message}

`, + ); + commandLog.scrollTop($("div.wrapper", commandLog).height()); +} diff --git a/src/js/localization.js b/src/js/localization.js index 1086960de18..9afefdad332 100644 --- a/src/js/localization.js +++ b/src/js/localization.js @@ -1,6 +1,6 @@ import i18next from 'i18next'; import i18nextXHRBackend from 'i18next-xhr-backend'; -import GUI from './gui.js'; +import { gui_log } from './gui_log.js'; import { get as getConfig, set as setConfig } from './ConfigStorage.js'; const i18n = {}; @@ -84,7 +84,7 @@ i18n.changeLanguage = function(languageSelected) { setConfig({'userLanguageSelect': languageSelected}); i18next.changeLanguage(getValidLocale(languageSelected)); i18n.selectedLanguage = languageSelected; - GUI.log(i18n.getMessage('language_changed')); + gui_log(i18n.getMessage('language_changed')); }; i18n.getMessage = function(messageID, parameters) { diff --git a/src/js/main.js b/src/js/main.js index 23bfcfb9e69..5ecfec0592f 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -1,7 +1,5 @@ import '../components/init.js'; -// Currently fc is everywhere, so we need to import it here -// till all is in modules -import './fc.js'; +import { gui_log } from './gui_log.js'; // same, msp seems to be everywhere used from global scope import './msp/MSPHelper.js'; import { i18n } from './localization.js'; @@ -222,8 +220,8 @@ function startProcess() { // translate to user-selected language i18n.localizePage(); - GUI.log(i18n.getMessage('infoVersionOs', { operatingSystem: GUI.operating_system })); - GUI.log(i18n.getMessage('infoVersionConfigurator', { configuratorVersion: CONFIGURATOR.getDisplayVersion() })); + gui_log(i18n.getMessage('infoVersionOs', { operatingSystem: GUI.operating_system })); + gui_log(i18n.getMessage('infoVersionConfigurator', { configuratorVersion: CONFIGURATOR.getDisplayVersion() })); if (GUI.isNWJS()) { const nwWindow = GUI.nwGui.Window.get(); @@ -298,12 +296,12 @@ function startProcess() { const tabName = $(self).text(); if (tabRequiresConnection && !CONFIGURATOR.connectionValid) { - GUI.log(i18n.getMessage('tabSwitchConnectionRequired')); + gui_log(i18n.getMessage('tabSwitchConnectionRequired')); return; } if (GUI.connect_lock) { // tab switching disabled while operation is in progress - GUI.log(i18n.getMessage('tabSwitchWaitForOperation')); + gui_log(i18n.getMessage('tabSwitchWaitForOperation')); return; } @@ -315,7 +313,7 @@ function startProcess() { } $('div.open_firmware_flasher a.flash').click(); } else if (GUI.allowedTabs.indexOf(tab) < 0) { - GUI.log(i18n.getMessage('tabSwitchUpgradeRequired', [tabName])); + gui_log(i18n.getMessage('tabSwitchUpgradeRequired', [tabName])); return; } @@ -697,7 +695,7 @@ function notifyOutdatedVersion(releaseData) { if (semver.lt(CONFIGURATOR.version, CONFIGURATOR.latestVersion)) { const message = i18n.getMessage('configuratorUpdateNotice', [CONFIGURATOR.latestVersion, CONFIGURATOR.latestVersionReleaseUrl]); - GUI.log(message); + gui_log(message); const dialog = $('.dialogConfiguratorUpdate')[0]; diff --git a/src/js/msp.js b/src/js/msp.js index 63ab796cde2..28d4e3e0f79 100644 --- a/src/js/msp.js +++ b/src/js/msp.js @@ -410,7 +410,7 @@ const MSP = { }, }; -MSP.SDCARD_STATE_NOT_PRESENT = 0; //TODO, move these to better place +MSP.SDCARD_STATE_NOT_PRESENT = 0; MSP.SDCARD_STATE_FATAL = 1; MSP.SDCARD_STATE_CARD_INIT = 2; MSP.SDCARD_STATE_FS_INIT = 3; diff --git a/src/js/msp/MSPConnector.js b/src/js/msp/MSPConnector.js index 1c162416da5..3f90e98a81c 100644 --- a/src/js/msp/MSPConnector.js +++ b/src/js/msp/MSPConnector.js @@ -7,6 +7,7 @@ import FC from "../fc"; import MSPCodes from "./MSPCodes"; import CONFIGURATOR from "../data_storage"; import serial from "../serial"; +import { gui_log } from "../gui_log"; const MSPConnectorImpl = function () { this.baud = undefined; @@ -44,7 +45,7 @@ MSPConnectorImpl.prototype.connect = function (port, baud, onConnectCallback, on // disconnect after 10 seconds with error if we don't get IDENT data GUI.timeout_add('msp_connector', function () { if (!CONFIGURATOR.connectionValid) { - GUI.log(i18n.getMessage('noConfigurationReceived')); + gui_log(i18n.getMessage('noConfigurationReceived')); disconnectAndCleanup(); } @@ -64,7 +65,7 @@ MSPConnectorImpl.prototype.connect = function (port, baud, onConnectCallback, on self.onConnectCallback(); }); } else { - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); self.onFailureCallback(); } }); diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index d3a9c048329..d1e4236ddc1 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -1,7 +1,8 @@ -// NOTE: this is a circular dependency, needs investigating -import { bit_check, sensor_status, bit_set, update_dataflash_global } from "../serial_backend"; +import { update_dataflash_global } from "../update_dataflash_global"; +import { sensor_status } from "../sensor_helpers"; +import { bit_check, bit_set } from "../bit"; import { i18n } from "../localization"; -import GUI from "../gui"; +import { gui_log } from "../gui_log"; import FC from "../fc"; import semver from 'semver'; import vtxDeviceStatusFactory from "../utils/VtxDeviceStatus/VtxDeviceStatusFactory"; @@ -2616,14 +2617,14 @@ MspHelper.prototype.setArmingEnabled = function(doEnable, disableRunawayTakeoffP MSP.send_message(MSPCodes.MSP_ARMING_DISABLE, mspHelper.crunch(MSPCodes.MSP_ARMING_DISABLE), false, function () { if (doEnable) { - GUI.log(i18n.getMessage('armingEnabled')); + gui_log(i18n.getMessage('armingEnabled')); if (disableRunawayTakeoffPrevention) { - GUI.log(i18n.getMessage('runawayTakeoffPreventionDisabled')); + gui_log(i18n.getMessage('runawayTakeoffPreventionDisabled')); } else { - GUI.log(i18n.getMessage('runawayTakeoffPreventionEnabled')); + gui_log(i18n.getMessage('runawayTakeoffPreventionEnabled')); } } else { - GUI.log(i18n.getMessage('armingDisabled')); + gui_log(i18n.getMessage('armingDisabled')); } if (onCompleteCallback) { diff --git a/src/js/peripherals.js b/src/js/peripherals.js index 2acc1111ea0..daa97c95e1b 100644 --- a/src/js/peripherals.js +++ b/src/js/peripherals.js @@ -1,4 +1,5 @@ import { i18n } from "./localization"; +import FC from "./fc"; // return true if user has choose a special peripheral function isPeripheralSelected(peripheralName) { diff --git a/src/js/protocols/stm32.js b/src/js/protocols/stm32.js index 224a3839149..25deeb4c83e 100644 --- a/src/js/protocols/stm32.js +++ b/src/js/protocols/stm32.js @@ -10,7 +10,8 @@ import GUI from "../gui"; import { i18n } from "../localization"; import MSP from "../msp"; import FC from "../fc"; -import { bit_check } from "../serial_backend"; +import { bit_check } from "../bit"; +import { gui_log } from "../gui_log"; import MSPCodes from "../msp/MSPCodes"; import PortUsage from "../port_usage"; import PortHandler from "../port_handler"; @@ -95,7 +96,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) self.initialize(); } else { - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); } }); } else { @@ -116,7 +117,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) self.initialize(); } else { GUI.connect_lock = false; - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); } }); } @@ -137,7 +138,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) if (failedAttempts > 100) { clearInterval(dfuWaitInterval); console.log(`failed to get DFU connection, gave up after 10 seconds`); - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); GUI.connect_lock = false; } } @@ -154,7 +155,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) serial.connect(self.port, {bitrate: self.options.reboot_baud}, function (openInfo) { if (!openInfo) { GUI.connect_lock = false; - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); return; } @@ -174,7 +175,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) const onConnectHandler = function () { - GUI.log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion])); + gui_log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion])); if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42)) { self.msp_connector.disconnect(function (disconnectionResult) { @@ -188,11 +189,11 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback) MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, () => { if (bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_FLASH_BOOTLOADER)) { // Board has flash bootloader - GUI.log(i18n.getMessage('deviceRebooting_flashBootloader')); + gui_log(i18n.getMessage('deviceRebooting_flashBootloader')); console.log('flash bootloader detected'); rebootMode = 4; // MSP_REBOOT_BOOTLOADER_FLASH } else { - GUI.log(i18n.getMessage('deviceRebooting_romBootloader')); + gui_log(i18n.getMessage('deviceRebooting_romBootloader')); console.log('no flash bootloader detected'); rebootMode = 1; // MSP_REBOOT_BOOTLOADER_ROM; } diff --git a/src/js/protocols/stm32usbdfu.js b/src/js/protocols/stm32usbdfu.js index 4c8eb093a59..68eaef129f2 100644 --- a/src/js/protocols/stm32usbdfu.js +++ b/src/js/protocols/stm32usbdfu.js @@ -12,6 +12,7 @@ */ import GUI from "../gui"; import { i18n } from "../localization"; +import { gui_log } from "../gui_log"; // Task for the brave ones. There are quite a few shadow variables which clash when // const or let are used. So need to run thorough tests when chaning `var` @@ -101,7 +102,7 @@ STM32DFU_protocol.prototype.connect = function (device, hex, options, callback) self.openDevice(result[0]); } else { console.log('USB DFU not found'); - GUI.log(i18n.getMessage('stm32UsbDfuNotFound')); + gui_log(i18n.getMessage('stm32UsbDfuNotFound')); } }); }; @@ -112,16 +113,16 @@ STM32DFU_protocol.prototype.openDevice = function (device) { chrome.usb.openDevice(device, function (handle) { if (checkChromeRuntimeError()) { console.log('Failed to open USB device!'); - GUI.log(i18n.getMessage('usbDeviceOpenFail')); + gui_log(i18n.getMessage('usbDeviceOpenFail')); if (GUI.operating_system === 'Linux') { - GUI.log(i18n.getMessage('usbDeviceUdevNotice')); + gui_log(i18n.getMessage('usbDeviceUdevNotice')); } return; } self.handle = handle; - GUI.log(i18n.getMessage('usbDeviceOpened', handle.handle.toString())); + gui_log(i18n.getMessage('usbDeviceOpened', handle.handle.toString())); console.log(`Device opened with Handle ID: ${handle.handle}`); self.claimInterface(0); }); @@ -133,9 +134,9 @@ STM32DFU_protocol.prototype.closeDevice = function () { chrome.usb.closeDevice(self.handle, function closed() { if (checkChromeRuntimeError()) { console.log('Failed to close USB device!'); - GUI.log(i18n.getMessage('usbDeviceCloseFail')); + gui_log(i18n.getMessage('usbDeviceCloseFail')); } else { - GUI.log(i18n.getMessage('usbDeviceClosed')); + gui_log(i18n.getMessage('usbDeviceClosed')); console.log(`Device closed with Handle ID: ${self.handle.handle}`); } @@ -635,7 +636,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { } if (typeof nextAction !== "undefined") { - GUI.log(i18n.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString())); + gui_log(i18n.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString())); // verify all addresses in the hex are writable. @@ -649,7 +650,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { } if (unusableBlocks.length > 0) { - GUI.log(i18n.getMessage('dfu_hex_address_errors')); + gui_log(i18n.getMessage('dfu_hex_address_errors')); TABS.firmware_flasher.flashingMessage(i18n.getMessage('dfu_hex_address_errors'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID); self.leave(); } else { @@ -674,7 +675,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { var unprotect = function() { console.log('Initiate read unprotect'); let messageReadProtected = i18n.getMessage('stm32ReadProtected'); - GUI.log(messageReadProtected); + gui_log(messageReadProtected); TABS.firmware_flasher.flashingMessage(messageReadProtected, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION); self.controlTransfer('out', self.request.DNLOAD, 0, 0, 0, [0x92], function () { // 0x92 initiates read unprotect @@ -696,10 +697,10 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data, error) { // should stall/disconnect if (error) { // we encounter an error, but this is expected. should be a stall. console.log('Unprotect memory command ran successfully. Unplug flight controller. Connect again in DFU mode and try flashing again.'); - GUI.log(i18n.getMessage('stm32UnprotectSuccessful')); + gui_log(i18n.getMessage('stm32UnprotectSuccessful')); let messageUnprotectUnplug = i18n.getMessage('stm32UnprotectUnplug'); - GUI.log(messageUnprotectUnplug); + gui_log(messageUnprotectUnplug); TABS.firmware_flasher.flashingMessage(messageUnprotectUnplug, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION) .flashProgress(0); @@ -707,7 +708,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { } else { // unprotecting the flight controller did not work. It did not reboot. console.log('Failed to execute unprotect memory command'); - GUI.log(i18n.getMessage('stm32UnprotectFailed')); + gui_log(i18n.getMessage('stm32UnprotectFailed')); TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32UnprotectFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID); console.log(data); self.cleanup(); @@ -717,7 +718,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { } else { console.log('Failed to initiate unprotect memory command'); let messageUnprotectInitFailed = i18n.getMessage('stm32UnprotectInitFailed'); - GUI.log(messageUnprotectInitFailed); + gui_log(messageUnprotectInitFailed); TABS.firmware_flasher.flashingMessage(messageUnprotectInitFailed, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID); self.cleanup(); } @@ -737,7 +738,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { if (data[4] === self.state.dfuUPLOAD_IDLE && ob_data.length === self.chipInfo.option_bytes.total_size) { console.log('Option bytes read successfully'); console.log('Chip does not appear read protected'); - GUI.log(i18n.getMessage('stm32NotReadProtected')); + gui_log(i18n.getMessage('stm32NotReadProtected')); // it is pretty safe to continue to erase flash self.clearStatus(function() { self.upload_procedure(2); @@ -786,14 +787,14 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { // if address load fails with this specific error though, it is very likely bc of read protection if (loadAddressResponse[4] === self.state.dfuERROR && loadAddressResponse[0] === self.status.errVENDOR) { // read protected - GUI.log(i18n.getMessage('stm32AddressLoadFailed')); + gui_log(i18n.getMessage('stm32AddressLoadFailed')); self.clearStatus(unprotect); return; } else if (loadAddressResponse[4] === self.state.dfuDNLOAD_IDLE) { console.log('Address load for option bytes sector succeeded.'); self.clearStatus(tryReadOB); } else { - GUI.log(i18n.getMessage('stm32AddressLoadUnknown')); + gui_log(i18n.getMessage('stm32AddressLoadUnknown')); self.cleanup(); } }; @@ -853,7 +854,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) { if (page === erase_pages.length) { console.log("Erase: complete"); - GUI.log(i18n.getMessage('dfu_erased_kilobytes', (total_erased / 1024).toString())); + gui_log(i18n.getMessage('dfu_erased_kilobytes', (total_erased / 1024).toString())); self.upload_procedure(4); } else { erase_page(); diff --git a/src/js/release_checker.js b/src/js/release_checker.js index d9818597947..14529dfd483 100644 --- a/src/js/release_checker.js +++ b/src/js/release_checker.js @@ -1,4 +1,4 @@ -import GUI from "./gui"; +import { gui_log } from "./gui_log"; import { i18n } from "./localization"; import { get as getStorage, set as setStorage } from "./SessionStorage"; @@ -20,7 +20,7 @@ ReleaseChecker.prototype.loadReleaseData = function (processFunction) { if (!cacheReleaseData || !cachedReleaseLastUpdate || releaseDataTimestamp - cachedReleaseLastUpdate > 3600 * 1000) { $.get(self._releaseUrl, function (releaseData) { - GUI.log(i18n.getMessage('releaseCheckLoaded',[self._releaseName])); + gui_log(i18n.getMessage('releaseCheckLoaded',[self._releaseName])); const data = {}; data[self._releaseDataTag] = releaseData; @@ -33,13 +33,13 @@ ReleaseChecker.prototype.loadReleaseData = function (processFunction) { if (data['responseJSON']) { message = data['responseJSON'].message; } - GUI.log(i18n.getMessage('releaseCheckFailed',[self._releaseName,message])); + gui_log(i18n.getMessage('releaseCheckFailed',[self._releaseName,message])); self._processReleaseData(cacheReleaseData, processFunction); }); } else { if (cacheReleaseData) { - GUI.log(i18n.getMessage('releaseCheckCached',[self._releaseName])); + gui_log(i18n.getMessage('releaseCheckCached',[self._releaseName])); } self._processReleaseData(cacheReleaseData, processFunction); @@ -51,7 +51,7 @@ ReleaseChecker.prototype._processReleaseData = function (releaseData, processFun if (releaseData) { processFunction(releaseData); } else { - GUI.log(i18n.getMessage('releaseCheckNoInfo',[self._releaseName])); + gui_log(i18n.getMessage('releaseCheckNoInfo',[self._releaseName])); processFunction(); } diff --git a/src/js/sensor_helpers.js b/src/js/sensor_helpers.js new file mode 100644 index 00000000000..3da219e3555 --- /dev/null +++ b/src/js/sensor_helpers.js @@ -0,0 +1,88 @@ +import FC from './fc'; +import { bit_check } from './bit'; + +export function have_sensor(sensors_detected, sensor_code) { + switch(sensor_code) { + case 'acc': + return bit_check(sensors_detected, 0); + case 'baro': + return bit_check(sensors_detected, 1); + case 'mag': + return bit_check(sensors_detected, 2); + case 'gps': + return bit_check(sensors_detected, 3); + case 'sonar': + return bit_check(sensors_detected, 4); + case 'gyro': + return bit_check(sensors_detected, 5); + } + return false; +} + +export function sensor_status(sensors_detected) { + // initialize variable (if it wasn't) + if (!sensor_status.previous_sensors_detected) { + sensor_status.previous_sensors_detected = -1; // Otherwise first iteration will not be run if sensors_detected == 0 + } + + // update UI (if necessary) + if (sensor_status.previous_sensors_detected == sensors_detected) { + return; + } + + // set current value + sensor_status.previous_sensors_detected = sensors_detected; + + const eSensorStatus = $("div#sensor-status"); + + if (have_sensor(sensors_detected, "acc")) { + $(".accel", eSensorStatus).addClass("on"); + $(".accicon", eSensorStatus).addClass("active"); + } else { + $(".accel", eSensorStatus).removeClass("on"); + $(".accicon", eSensorStatus).removeClass("active"); + } + + if ( + (FC.CONFIG.boardType == 0 || FC.CONFIG.boardType == 2) && + have_sensor(sensors_detected, "gyro") + ) { + $(".gyro", eSensorStatus).addClass("on"); + $(".gyroicon", eSensorStatus).addClass("active"); + } else { + $(".gyro", eSensorStatus).removeClass("on"); + $(".gyroicon", eSensorStatus).removeClass("active"); + } + + if (have_sensor(sensors_detected, "baro")) { + $(".baro", eSensorStatus).addClass("on"); + $(".baroicon", eSensorStatus).addClass("active"); + } else { + $(".baro", eSensorStatus).removeClass("on"); + $(".baroicon", eSensorStatus).removeClass("active"); + } + + if (have_sensor(sensors_detected, "mag")) { + $(".mag", eSensorStatus).addClass("on"); + $(".magicon", eSensorStatus).addClass("active"); + } else { + $(".mag", eSensorStatus).removeClass("on"); + $(".magicon", eSensorStatus).removeClass("active"); + } + + if (have_sensor(sensors_detected, "gps")) { + $(".gps", eSensorStatus).addClass("on"); + $(".gpsicon", eSensorStatus).addClass("active"); + } else { + $(".gps", eSensorStatus).removeClass("on"); + $(".gpsicon", eSensorStatus).removeClass("active"); + } + + if (have_sensor(sensors_detected, "sonar")) { + $(".sonar", eSensorStatus).addClass("on"); + $(".sonaricon", eSensorStatus).addClass("active"); + } else { + $(".sonar", eSensorStatus).removeClass("on"); + $(".sonaricon", eSensorStatus).removeClass("active"); + } +} diff --git a/src/js/serial.js b/src/js/serial.js index ddc99769a0c..9c2f65788c2 100644 --- a/src/js/serial.js +++ b/src/js/serial.js @@ -2,6 +2,7 @@ import GUI from "./gui"; import { i18n } from "./localization"; import FC from "./fc"; import CONFIGURATOR from "./data_storage"; +import { gui_log } from "./gui_log"; const serial = { connected: false, @@ -67,7 +68,7 @@ const serial = { self.failed = 0; } else { console.log(`${self.connectionType}: connection did not recover from last onReceiveError, disconnecting`); - GUI.log(i18n.getMessage('serialUnrecoverable')); + gui_log(i18n.getMessage('serialUnrecoverable')); self.errorHandler(getInfo.error, 'receive'); } } else { @@ -88,7 +89,7 @@ const serial = { if (_info.paused) { // assume unrecoverable, disconnect console.log(`${self.connectionType}: connection did not recover from ${self.error} condition, disconnecting`); - GUI.log(i18n.getMessage('serialUnrecoverable')); + gui_log(i18n.getMessage('serialUnrecoverable')); self.errorHandler(_info.error, 'receive'); } else { @@ -107,7 +108,7 @@ const serial = { case 'frame_error': case 'parity_error': - GUI.log(i18n.getMessage(`serialError${inflection.camelize(info.error)}`)); + gui_log(i18n.getMessage(`serialError${inflection.camelize(info.error)}`)); self.errorHandler(info.error, 'receive'); break; case 'break': // This seems to be the error that is thrown under NW.js in Windows when the device reboots after typing 'exit' in CLI diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index f6d72b27d22..d2dd7fcee91 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -14,6 +14,10 @@ import CONFIGURATOR, { API_VERSION_1_45 } from "./data_storage"; import serial from "./serial"; import MdnsDiscovery from "./mdns_discovery"; import UI_PHONES from "./phones_ui"; +import { bit_check } from './bit.js'; +import { sensor_status, have_sensor } from "./sensor_helpers"; +import { update_dataflash_global } from "./update_dataflash_global"; +import { gui_log } from "./gui_log"; let mspHelper; let connectionTimestamp; @@ -219,7 +223,7 @@ function setConnectionTimeout() { // disconnect after 10 seconds with error if we don't get IDENT data GUI.timeout_add('connecting', function () { if (!CONFIGURATOR.connectionValid) { - GUI.log(i18n.getMessage('noConfigurationReceived')); + gui_log(i18n.getMessage('noConfigurationReceived')); $('div.connect_controls a.connect').click(); // disconnect } @@ -235,7 +239,7 @@ function onOpen(openInfo) { // reset connecting_to GUI.connecting_to = false; - GUI.log(i18n.getMessage('serialPortOpened', serial.connectionType === 'serial' ? [serial.connectionId] : [openInfo.socketId])); + gui_log(i18n.getMessage('serialPortOpened', serial.connectionType === 'serial' ? [serial.connectionId] : [openInfo.socketId])); // save selected port with chrome.storage if the port differs let result = ConfigStorage.get('last_used_port'); @@ -266,7 +270,7 @@ function onOpen(openInfo) { MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () { tracking.setFlightControllerData(tracking.DATA.API_VERSION, FC.CONFIG.apiVersion); - GUI.log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion])); + gui_log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion])); if (semver.gte(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_ACCEPTED)) { @@ -276,11 +280,11 @@ function onOpen(openInfo) { MSP.send_message(MSPCodes.MSP_FC_VERSION, false, false, function () { tracking.setFlightControllerData(tracking.DATA.FIRMWARE_VERSION, FC.CONFIG.flightControllerVersion); - GUI.log(i18n.getMessage('fcInfoReceived', [FC.CONFIG.flightControllerIdentifier, FC.CONFIG.flightControllerVersion])); + gui_log(i18n.getMessage('fcInfoReceived', [FC.CONFIG.flightControllerIdentifier, FC.CONFIG.flightControllerVersion])); MSP.send_message(MSPCodes.MSP_BUILD_INFO, false, false, function () { - GUI.log(i18n.getMessage('buildInfoReceived', [FC.CONFIG.buildInfo])); + gui_log(i18n.getMessage('buildInfoReceived', [FC.CONFIG.buildInfo])); MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, processBoardInfo); }); @@ -321,7 +325,7 @@ function onOpen(openInfo) { tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'SerialPortFailed'); console.log('Failed to open serial port'); - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); abortConnect(); } @@ -362,7 +366,7 @@ function processBoardInfo() { tracking.setFlightControllerData(tracking.DATA.MANUFACTURER_ID, FC.CONFIG.manufacturerId); tracking.setFlightControllerData(tracking.DATA.MCU_TYPE, FC.getMcuType()); - GUI.log(i18n.getMessage('boardInfoReceived', [FC.getHardwareName(), FC.CONFIG.boardVersion])); + gui_log(i18n.getMessage('boardInfoReceived', [FC.getHardwareName(), FC.CONFIG.boardVersion])); 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) { const dialog = $('#dialogResetToCustomDefaults')[0]; @@ -458,7 +462,7 @@ function processUid() { tracking.setFlightControllerData(tracking.DATA.MCU_ID, objectHash.sha1(deviceIdentifier)); tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Connected'); connectionTimestamp = Date.now(); - GUI.log(i18n.getMessage('uniqueDeviceIdReceived', [deviceIdentifier])); + gui_log(i18n.getMessage('uniqueDeviceIdReceived', [deviceIdentifier])); processCraftName(); }); @@ -471,7 +475,7 @@ async function processCraftName() { await MSP.promise(MSPCodes.MSP_NAME); } - GUI.log(i18n.getMessage('craftNameReceived', semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? [FC.CONFIG.craftName] : [FC.CONFIG.name])); + gui_log(i18n.getMessage('craftNameReceived', semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? [FC.CONFIG.craftName] : [FC.CONFIG.name])); if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)); @@ -572,9 +576,9 @@ function onConnect() { function onClosed(result) { if (result) { // All went as expected - GUI.log(i18n.getMessage('serialPortClosedOk')); + gui_log(i18n.getMessage('serialPortClosedOk')); } else { // Something went wrong - GUI.log(i18n.getMessage('serialPortClosedFail')); + gui_log(i18n.getMessage('serialPortClosedFail')); } $('#tabs ul.mode-connected').hide(); @@ -614,90 +618,6 @@ export function read_serial(info) { } } -export function sensor_status(sensors_detected) { - // initialize variable (if it wasn't) - if (!sensor_status.previous_sensors_detected) { - sensor_status.previous_sensors_detected = -1; // Otherwise first iteration will not be run if sensors_detected == 0 - } - - // update UI (if necessary) - if (sensor_status.previous_sensors_detected == sensors_detected) { - return; - } - - // set current value - sensor_status.previous_sensors_detected = sensors_detected; - - const eSensorStatus = $('div#sensor-status'); - - if (have_sensor(sensors_detected, 'acc')) { - $('.accel', eSensorStatus).addClass('on'); - $('.accicon', eSensorStatus).addClass('active'); - - } else { - $('.accel', eSensorStatus).removeClass('on'); - $('.accicon', eSensorStatus).removeClass('active'); - } - - if ((FC.CONFIG.boardType == 0 || FC.CONFIG.boardType == 2) && have_sensor(sensors_detected, 'gyro')) { - $('.gyro', eSensorStatus).addClass('on'); - $('.gyroicon', eSensorStatus).addClass('active'); - } else { - $('.gyro', eSensorStatus).removeClass('on'); - $('.gyroicon', eSensorStatus).removeClass('active'); - } - - if (have_sensor(sensors_detected, 'baro')) { - $('.baro', eSensorStatus).addClass('on'); - $('.baroicon', eSensorStatus).addClass('active'); - } else { - $('.baro', eSensorStatus).removeClass('on'); - $('.baroicon', eSensorStatus).removeClass('active'); - } - - if (have_sensor(sensors_detected, 'mag')) { - $('.mag', eSensorStatus).addClass('on'); - $('.magicon', eSensorStatus).addClass('active'); - } else { - $('.mag', eSensorStatus).removeClass('on'); - $('.magicon', eSensorStatus).removeClass('active'); - } - - if (have_sensor(sensors_detected, 'gps')) { - $('.gps', eSensorStatus).addClass('on'); - $('.gpsicon', eSensorStatus).addClass('active'); - } else { - $('.gps', eSensorStatus).removeClass('on'); - $('.gpsicon', eSensorStatus).removeClass('active'); - } - - if (have_sensor(sensors_detected, 'sonar')) { - $('.sonar', eSensorStatus).addClass('on'); - $('.sonaricon', eSensorStatus).addClass('active'); - } else { - $('.sonar', eSensorStatus).removeClass('on'); - $('.sonaricon', eSensorStatus).removeClass('active'); - } -} - -export function have_sensor(sensors_detected, sensor_code) { - switch(sensor_code) { - case 'acc': - return bit_check(sensors_detected, 0); - case 'baro': - return bit_check(sensors_detected, 1); - case 'mag': - return bit_check(sensors_detected, 2); - case 'gps': - return bit_check(sensors_detected, 3); - case 'sonar': - return bit_check(sensors_detected, 4); - case 'gyro': - return bit_check(sensors_detected, 5); - } - return false; -} - function startLiveDataRefreshTimer() { // live data refresh GUI.timeout_add('data_refresh', update_live_status, 100); @@ -761,61 +681,6 @@ async function update_live_status() { } } -export function bit_check(num, bit) { - return ((num >> bit) % 2 != 0); -} - -export function bit_set(num, bit) { - return num | 1 << bit; -} - -export function bit_clear(num, bit) { - return num & ~(1 << bit); -} - -export function update_dataflash_global() { - function formatFilesize(bytes) { - if (bytes < 1024) { - return `${bytes}B`; - } - const kilobytes = bytes / 1024; - - if (kilobytes < 1024) { - return `${Math.round(kilobytes)}kB`; - } - - const megabytes = kilobytes / 1024; - - return `${megabytes.toFixed(1)}MB`; - } - - const supportsDataflash = FC.DATAFLASH.totalSize > 0; - - if (supportsDataflash){ - $(".noflash_global").css({ - display: 'none', - }); - - $(".dataflash-contents_global").css({ - display: 'block', - }); - - $(".dataflash-free_global").css({ - width: `${100-(FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize) / FC.DATAFLASH.totalSize * 100}%`, - display: 'block', - }); - $(".dataflash-free_global div").text(`Dataflash: free ${formatFilesize(FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize)}`); - } else { - $(".noflash_global").css({ - display: 'block', - }); - - $(".dataflash-contents_global").css({ - display: 'none', - }); - } -} - export function reinitializeConnection(callback) { // Close connection gracefully if it still exists. @@ -829,7 +694,7 @@ export function reinitializeConnection(callback) { } } - GUI.log(i18n.getMessage('deviceRebooting')); + gui_log(i18n.getMessage('deviceRebooting')); let attempts = 0; const reconnect = setInterval(waitforSerial, 100); @@ -839,7 +704,7 @@ export function reinitializeConnection(callback) { console.log(`Serial connection available after ${attempts / 10} seconds`); clearInterval(reconnect); getStatus(); - GUI.log(i18n.getMessage('deviceReady')); + gui_log(i18n.getMessage('deviceReady')); if (callback === typeof('function')) { callback(); } @@ -848,7 +713,7 @@ export function reinitializeConnection(callback) { if (attempts > 100) { clearInterval(reconnect); console.log(`failed to get serial connection, gave up after 10 seconds`); - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); } } } diff --git a/src/js/tabs/adjustments.js b/src/js/tabs/adjustments.js index 9fe89c7e525..b3318e9865c 100644 --- a/src/js/tabs/adjustments.js +++ b/src/js/tabs/adjustments.js @@ -5,6 +5,7 @@ import MSP from '../msp'; import FC from '../fc'; import MSPCodes from '../msp/MSPCodes'; import { API_VERSION_1_42 } from '../data_storage'; +import { gui_log } from '../gui_log'; const adjustments = {}; @@ -236,7 +237,7 @@ adjustments.initialize = function (callback) { function save_to_eeprom() { MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { - GUI.log(i18n.getMessage('adjustmentsEepromSaved')); + gui_log(i18n.getMessage('adjustmentsEepromSaved')); }); } diff --git a/src/js/tabs/auxiliary.js b/src/js/tabs/auxiliary.js index 5bef0338a07..6d25c9d178a 100644 --- a/src/js/tabs/auxiliary.js +++ b/src/js/tabs/auxiliary.js @@ -1,12 +1,13 @@ import { i18n } from '../localization'; import GUI from '../gui'; import { get as getConfig, set as setConfig } from '../ConfigStorage'; -import { bit_check } from '../serial_backend'; +import { bit_check } from '../bit'; import { mspHelper } from '../msp/MSPHelper'; import FC from '../FC'; import MSP from '../msp'; import MSPCodes from '../msp/MSPCodes'; import adjustBoxNameIfPeripheralWithModeID from '../peripherals'; +import { gui_log } from '../gui_log'; const auxiliary = {}; @@ -396,7 +397,7 @@ auxiliary.initialize = function (callback) { function save_to_eeprom() { MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { - GUI.log(i18n.getMessage('auxiliaryEepromSaved')); + gui_log(i18n.getMessage('auxiliaryEepromSaved')); }); } }); @@ -565,7 +566,6 @@ auxiliary.cleanup = function (callback) { if (callback) callback(); }; -window.TABS.auxiliary = auxiliary; export { auxiliary, }; diff --git a/src/js/tabs/cli.js b/src/js/tabs/cli.js index bf569620c23..928925accb7 100644 --- a/src/js/tabs/cli.js +++ b/src/js/tabs/cli.js @@ -8,6 +8,7 @@ import CONFIGURATOR from "../data_storage"; import serial from "../serial"; import CliAutoComplete from "../CliAutoComplete"; import UI_PHONES from "../phones_ui"; +import { gui_log } from "../gui_log"; const cli = { lineDelayMs: 15, @@ -507,7 +508,7 @@ cli.read = function (readInfo) { if (this.cliBuffer === 'Rebooting') { CONFIGURATOR.cliActive = false; CONFIGURATOR.cliValid = false; - GUI.log(i18n.getMessage('cliReboot')); + gui_log(i18n.getMessage('cliReboot')); reinitializeConnection(); } @@ -516,7 +517,7 @@ cli.read = function (readInfo) { this.lastArrival = new Date().getTime(); if (!CONFIGURATOR.cliValid && validateText.indexOf('CLI') !== -1) { - GUI.log(i18n.getMessage('cliEnter')); + gui_log(i18n.getMessage('cliEnter')); CONFIGURATOR.cliValid = true; // begin output history with the prompt (last line of welcome message) // this is to match the content of the history with what the user sees on this tab diff --git a/src/js/tabs/configuration.js b/src/js/tabs/configuration.js index 15d3afbfaf0..d1335653c51 100644 --- a/src/js/tabs/configuration.js +++ b/src/js/tabs/configuration.js @@ -8,6 +8,7 @@ import FC from '../fc'; import MSP from '../msp'; import MSPCodes from '../msp/MSPCodes'; import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_45 } from '../data_storage'; +import { gui_log } from '../gui_log'; const configuration = { analyticsChanges: {}, @@ -553,7 +554,7 @@ configuration.initialize = function (callback) { } function reboot() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); GUI.tab_switch_cleanup(function() { MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection); diff --git a/src/js/tabs/failsafe.js b/src/js/tabs/failsafe.js index 7bbb9f2ad71..891817b764c 100644 --- a/src/js/tabs/failsafe.js +++ b/src/js/tabs/failsafe.js @@ -7,6 +7,7 @@ import FC from "../fc"; import MSPCodes from "../msp/MSPCodes"; import adjustBoxNameIfPeripheralWithModeID from "../peripherals"; import { API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from "../data_storage"; +import { gui_log } from "../gui_log"; const failsafe = {}; @@ -370,7 +371,7 @@ failsafe.initialize = function (callback) { } function reboot() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); GUI.tab_switch_cleanup(function() { MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection); diff --git a/src/js/tabs/firmware_flasher.js b/src/js/tabs/firmware_flasher.js index cd2f0b7386b..e199015c046 100644 --- a/src/js/tabs/firmware_flasher.js +++ b/src/js/tabs/firmware_flasher.js @@ -14,6 +14,7 @@ import PortHandler from '../port_handler'; import CONFIGURATOR, { API_VERSION_1_39 } from '../data_storage'; import serial from '../serial'; import STM32DFU from '../protocols/stm32usbdfu'; +import { gui_log } from '../gui_log'; const firmware_flasher = { targets: null, @@ -459,7 +460,7 @@ firmware_flasher.initialize = function (callback) { if (!inComment && input.charCodeAt(i) > 255) { self.flashingMessage(i18n.getMessage('firmwareFlasherConfigCorrupted'), self.FLASH_MESSAGE_TYPES.INVALID); - GUI.log(i18n.getMessage('firmwareFlasherConfigCorruptedLogMessage')); + gui_log(i18n.getMessage('firmwareFlasherConfigCorruptedLogMessage')); return null; } @@ -504,7 +505,7 @@ firmware_flasher.initialize = function (callback) { STM32.connect(port, baud, firmware, options); } else { console.log('Please select valid serial port'); - GUI.log(i18n.getMessage('firmwareFlasherNoValidPort')); + gui_log(i18n.getMessage('firmwareFlasherNoValidPort')); } } else { tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, 'Flashing', self.fileName || null); @@ -542,10 +543,10 @@ firmware_flasher.initialize = function (callback) { if (board !== target) { boardSelect.val(board).trigger('change'); } - GUI.log(i18n.getMessage(targetAvailable ? 'firmwareFlasherBoardVerificationSuccess' : 'firmwareFlasherBoardVerficationTargetNotAvailable', + gui_log(i18n.getMessage(targetAvailable ? 'firmwareFlasherBoardVerificationSuccess' : 'firmwareFlasherBoardVerficationTargetNotAvailable', { boardName: board })); } else { - GUI.log(i18n.getMessage('firmwareFlasherBoardVerificationFail')); + gui_log(i18n.getMessage('firmwareFlasherBoardVerificationFail')); } onClose(); } @@ -575,7 +576,7 @@ firmware_flasher.initialize = function (callback) { MSP.listen(mspHelper.process_data.bind(mspHelper)); getBoard(); } else { - GUI.log(i18n.getMessage('serialPortOpenFail')); + gui_log(i18n.getMessage('serialPortOpenFail')); } } @@ -588,7 +589,7 @@ firmware_flasher.initialize = function (callback) { baud = parseInt($('#flash_manual_baud_rate').val()); } - GUI.log(i18n.getMessage('firmwareFlasherDetectBoardQuery')); + gui_log(i18n.getMessage('firmwareFlasherDetectBoardQuery')); const isLoaded = self.targets ? Object.keys(self.targets).length > 0 : false; @@ -603,7 +604,7 @@ firmware_flasher.initialize = function (callback) { console.log('Releases not loaded yet'); } } else { - GUI.log(i18n.getMessage('firmwareFlasherNoValidPort')); + gui_log(i18n.getMessage('firmwareFlasherNoValidPort')); } } } @@ -799,7 +800,7 @@ firmware_flasher.initialize = function (callback) { tracking.setFirmwareData(tracking.DATA.FIRMWARE_SOURCE, 'http'); if ($('select[name="firmware_version"]').val() === "0") { - GUI.log(i18n.getMessage('firmwareFlasherNoFirmwareSelected')); + gui_log(i18n.getMessage('firmwareFlasherNoFirmwareSelected')); return; } @@ -1098,7 +1099,7 @@ firmware_flasher.initialize = function (callback) { }); } else { console.log('You don\'t have write permissions for this file, sorry.'); - GUI.log(i18n.getMessage('firmwareFlasherWritePermissions')); + gui_log(i18n.getMessage('firmwareFlasherWritePermissions')); } }); }); @@ -1114,7 +1115,7 @@ firmware_flasher.initialize = function (callback) { const port = resultPort[0]; if (!GUI.connect_lock) { - GUI.log(i18n.getMessage('firmwareFlasherFlashTrigger', [port])); + gui_log(i18n.getMessage('firmwareFlasherFlashTrigger', [port])); console.log(`Detected: ${port} - triggering flash on connect`); // Trigger regular Flashing sequence @@ -1122,7 +1123,7 @@ firmware_flasher.initialize = function (callback) { $('a.flash_firmware').click(); }, 100); // timeout so bus have time to initialize after being detected by the system } else { - GUI.log(i18n.getMessage('firmwareFlasherPreviousDevice', [port])); + gui_log(i18n.getMessage('firmwareFlasherPreviousDevice', [port])); } // Since current port_detected request was consumed, create new one diff --git a/src/js/tabs/gps.js b/src/js/tabs/gps.js index ad1ed87aec3..d2771945194 100644 --- a/src/js/tabs/gps.js +++ b/src/js/tabs/gps.js @@ -1,6 +1,6 @@ import { i18n } from "../localization"; import GUI from '../gui'; -import { have_sensor } from "../serial_backend"; +import { have_sensor } from "../sensor_helpers"; import FC from '../fc'; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; diff --git a/src/js/tabs/led_strip.js b/src/js/tabs/led_strip.js index 772fc8df9c6..a0d41e348e8 100644 --- a/src/js/tabs/led_strip.js +++ b/src/js/tabs/led_strip.js @@ -4,6 +4,7 @@ import { mspHelper } from "../msp/MSPHelper"; import FC from "../fc"; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; +import { gui_log } from "../gui_log"; const led_strip = { wireMode: false, @@ -581,7 +582,7 @@ led_strip.initialize = function (callback, scrollPosition) { function save_to_eeprom() { MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function() { - GUI.log(i18n.getMessage('ledStripEepromSaved')); + gui_log(i18n.getMessage('ledStripEepromSaved')); }); } }); diff --git a/src/js/tabs/logging.js b/src/js/tabs/logging.js index 5f43c764ce4..571e312b58a 100644 --- a/src/js/tabs/logging.js +++ b/src/js/tabs/logging.js @@ -6,6 +6,7 @@ import FC from '../fc.js'; import MSP from '../msp.js'; import MSPCodes from '../msp/MSPCodes.js'; import CONFIGURATOR from '../data_storage.js'; +import { gui_log } from '../gui_log.js'; const logging = {}; logging.initialize = function (callback) { @@ -89,7 +90,7 @@ logging.initialize = function (callback) { $(this).text(i18n.getMessage('loggingStop')); $(this).data("clicks", clicks !== true); } else { - GUI.log(i18n.getMessage('loggingErrorOneProperty')); + gui_log(i18n.getMessage('loggingErrorOneProperty')); } } else { GUI.interval_kill_all(); @@ -99,10 +100,10 @@ logging.initialize = function (callback) { $(this).data("clicks", !clicks); } } else { - GUI.log(i18n.getMessage('loggingErrorLogFile')); + gui_log(i18n.getMessage('loggingErrorLogFile')); } } else { - GUI.log(i18n.getMessage('loggingErrorNotConnected')); + gui_log(i18n.getMessage('loggingErrorNotConnected')); } }); @@ -300,7 +301,7 @@ logging.initialize = function (callback) { if (retaining) { chrome.fileSystem.getDisplayPath(fileEntry, function (path) { - GUI.log(i18n.getMessage('loggingAutomaticallyRetained', [path])); + gui_log(i18n.getMessage('loggingAutomaticallyRetained', [path])); }); } diff --git a/src/js/tabs/motors.js b/src/js/tabs/motors.js index 105de868a2f..5ab4ec76c1a 100644 --- a/src/js/tabs/motors.js +++ b/src/js/tabs/motors.js @@ -5,7 +5,8 @@ import MotorOutputReorderConfig from "../../components/MotorOutputReordering/Mot import MotorOutputReorderComponent from "../../components/MotorOutputReordering/MotorOutputReorderingComponent"; import EscDshotDirectionComponent from "../../components/EscDshotDirection/EscDshotDirectionComponent"; import { tracking } from "../Analytics"; -import { bit_check, reinitializeConnection } from "../serial_backend"; +import { reinitializeConnection } from "../serial_backend"; +import { bit_check } from "../bit"; import { mspHelper } from "../msp/MSPHelper"; import FC from "../fc"; import MSP from "../msp"; @@ -13,6 +14,7 @@ import { mixerList } from "../model"; import MSPCodes from "../msp/MSPCodes"; import { API_VERSION_1_42, API_VERSION_1_44 } from "../data_storage"; import EscProtocols from "../utils/EscProtocols"; +import { gui_log } from "../gui_log"; const motors = { previousDshotBidir: null, @@ -67,8 +69,7 @@ motors.initialize = async function (callback) { const self = this; self.armed = false; - // self.escProtocolIsDshot = false; - self.escProtocolIsDshot = true ; + self.escProtocolIsDshot = false; self.configHasChanged = false; self.configChanges = {}; @@ -236,8 +237,7 @@ motors.initialize = async function (callback) { && (FC.MOTOR_OUTPUT_ORDER) && (FC.MOTOR_OUTPUT_ORDER.length > 0); domMotorOutputReorderDialogOpen.toggle(isMotorReorderingAvailable); - // self.escProtocolIsDshot = EscProtocols.IsProtocolDshot(FC.CONFIG.apiVersion, FC.PID_ADVANCED_CONFIG.fast_pwm_protocol); - self.escProtocolIsDshot = true; + self.escProtocolIsDshot = EscProtocols.IsProtocolDshot(FC.CONFIG.apiVersion, FC.PID_ADVANCED_CONFIG.fast_pwm_protocol); } function process_html() { @@ -1179,7 +1179,7 @@ motors.initialize = async function (callback) { } function reboot() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection); } diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index d57dce1909b..25184880504 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -7,6 +7,7 @@ import FC from "../fc"; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; import CONFIGURATOR, { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from "../data_storage"; +import { gui_log } from "../gui_log"; let sdcardTimer; @@ -58,7 +59,7 @@ onboard_logging.initialize = function (callback) { } function reboot() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); GUI.tab_switch_cleanup(function() { MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection); @@ -577,7 +578,7 @@ onboard_logging.initialize = function (callback) { accepts: [{description: `${suffix.toUpperCase()} files`, extensions: [suffix]}]}, function(fileEntry) { if (checkChromeRuntimeError()) { if (chrome.runtime.lastError.message !== "User cancelled") { - GUI.log(i18n.getMessage('dataflashFileWriteFailed')); + gui_log(i18n.getMessage('dataflashFileWriteFailed')); } return; } @@ -589,7 +590,7 @@ onboard_logging.initialize = function (callback) { fileEntry.createWriter(function (fileWriter) { fileWriter.onerror = function (e) { - GUI.log(`${i18n.getMessage('error', { errorMessage: e.target.error.message })}${i18n.getMessage('error', { errorMessage: e.target.error.message })} { @@ -3370,7 +3371,7 @@ osd.initialize = function(callback) { }); } else { console.log('You don\'t have write permissions for this file, sorry.'); - GUI.log(i18n.getMessage('osdWritePermissions')); + gui_log(i18n.getMessage('osdWritePermissions')); } }); }); diff --git a/src/js/tabs/pid_tuning.js b/src/js/tabs/pid_tuning.js index 71848f199b4..3d30cfa27d4 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -2,7 +2,7 @@ import { i18n } from "../localization"; import { colorTables, getColorForPercentage } from '../utils/css.js'; import GUI from '../gui'; import { tracking } from "../Analytics"; -import { have_sensor } from "../serial_backend"; +import { have_sensor } from "../sensor_helpers"; import { mspHelper } from "../msp/MSPHelper"; import FC from "../fc"; import MSP from "../msp"; @@ -11,6 +11,7 @@ import Model from "../model"; import RateCurve from "../RateCurve"; import MSPCodes from "../msp/MSPCodes"; import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from "../data_storage"; +import { gui_log } from "../gui_log"; const pid_tuning = { RATE_PROFILE_MASK: 128, @@ -1460,7 +1461,7 @@ pid_tuning.initialize = function (callback) { self.refresh(function () { self.updating = false; - GUI.log(i18n.getMessage('pidTuningPidProfileReset')); + gui_log(i18n.getMessage('pidTuningPidProfileReset')); }); }); }); @@ -1476,7 +1477,7 @@ pid_tuning.initialize = function (callback) { $('.tab-pid_tuning select[name="profile"]').prop('disabled', 'false'); FC.CONFIG.profile = self.currentProfile; - GUI.log(i18n.getMessage('pidTuningLoadedProfile', [self.currentProfile + 1])); + gui_log(i18n.getMessage('pidTuningLoadedProfile', [self.currentProfile + 1])); }); }); }); @@ -1493,7 +1494,7 @@ pid_tuning.initialize = function (callback) { FC.CONFIG.rateProfile = self.currentRateProfile; self.currentRates = self.rateCurve.getCurrentRates(); - GUI.log(i18n.getMessage('pidTuningLoadedRateProfile', [self.currentRateProfile + 1])); + gui_log(i18n.getMessage('pidTuningLoadedRateProfile', [self.currentRateProfile + 1])); }); }); }); @@ -1807,7 +1808,7 @@ pid_tuning.initialize = function (callback) { $('a.refresh').click(function () { self.refresh(function () { - GUI.log(i18n.getMessage('pidTuningDataRefreshed')); + gui_log(i18n.getMessage('pidTuningDataRefreshed')); }); }); @@ -2269,7 +2270,7 @@ pid_tuning.initialize = function (callback) { self.setDirty(false); - GUI.log(i18n.getMessage('pidTuningEepromSaved')); + gui_log(i18n.getMessage('pidTuningEepromSaved')); self.refresh(); }); @@ -2435,12 +2436,12 @@ pid_tuning.checkUpdateProfile = function (updateRateProfile) { self.refresh(function () { self.updating = false; if (changedProfile) { - GUI.log(i18n.getMessage('pidTuningReceivedProfile', [FC.CONFIG.profile + 1])); + gui_log(i18n.getMessage('pidTuningReceivedProfile', [FC.CONFIG.profile + 1])); FC.CONFIG.profile = self.currentProfile; } if (changedRateProfile) { - GUI.log(i18n.getMessage('pidTuningReceivedRateProfile', [FC.CONFIG.rateProfile + 1])); + gui_log(i18n.getMessage('pidTuningReceivedRateProfile', [FC.CONFIG.rateProfile + 1])); FC.CONFIG.rateProfile = self.currentRateProfile; } }); diff --git a/src/js/tabs/ports.js b/src/js/tabs/ports.js index d9ab34d392f..211b263d131 100644 --- a/src/js/tabs/ports.js +++ b/src/js/tabs/ports.js @@ -9,6 +9,7 @@ import MSP from '../msp'; import MSPCodes from '../msp/MSPCodes'; import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_45 } from '../data_storage'; import BOARD from '../boards'; +import { gui_log } from '../gui_log'; const ports = { analyticsChanges: {}, @@ -491,7 +492,7 @@ ports.initialize = function (callback) { } function on_saved_handler() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); GUI.tab_switch_cleanup(function() { MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection); diff --git a/src/js/tabs/power.js b/src/js/tabs/power.js index d458dba027d..d5f802ff662 100644 --- a/src/js/tabs/power.js +++ b/src/js/tabs/power.js @@ -5,6 +5,7 @@ import { mspHelper } from '../msp/MSPHelper'; import FC from '../fc'; import MSP from '../msp'; import MSPCodes from '../msp/MSPCodes'; +import { gui_log } from '../gui_log'; const power = { supported: false, @@ -502,7 +503,7 @@ power.initialize = function (callback) { } function save_completed() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); TABS.power.initialize(); } diff --git a/src/js/tabs/receiver.js b/src/js/tabs/receiver.js index 124a05054c8..410aa12c8c6 100644 --- a/src/js/tabs/receiver.js +++ b/src/js/tabs/receiver.js @@ -2,7 +2,8 @@ import { i18n } from "../localization"; import GUI from '../gui'; import { get as getConfig, set as setConfig } from '../ConfigStorage'; import { tracking } from "../Analytics"; -import { bit_check, reinitializeConnection } from "../serial_backend"; +import { reinitializeConnection } from "../serial_backend"; +import { bit_check } from "../bit"; import { mspHelper } from "../msp/MSPHelper"; import FC from "../fc"; import MSP from "../msp"; @@ -12,6 +13,7 @@ import MSPCodes from "../msp/MSPCodes"; import windowWatcherUtil from "../utils/window_watchers"; import CONFIGURATOR, { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from "../data_storage"; import DarkTheme from "../DarkTheme"; +import { gui_log } from "../gui_log"; import CryptoES from 'crypto-es'; @@ -424,7 +426,7 @@ receiver.initialize = function (callback) { $('a.refresh').click(function () { tab.refresh(function () { - GUI.log(i18n.getMessage('receiverDataRefreshed')); + gui_log(i18n.getMessage('receiverDataRefreshed')); }); }); @@ -496,7 +498,7 @@ receiver.initialize = function (callback) { } function reboot() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); if (boot) { GUI.tab_switch_cleanup(function() { MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection); @@ -556,7 +558,7 @@ receiver.initialize = function (callback) { $("a.bind").click(function() { MSP.send_message(MSPCodes.MSP2_BETAFLIGHT_BIND); - GUI.log(i18n.getMessage('receiverButtonBindMessage')); + gui_log(i18n.getMessage('receiverButtonBindMessage')); }); } $(".bind_btn").toggle(showBindButton); diff --git a/src/js/tabs/sensors.js b/src/js/tabs/sensors.js index 130568b9eb5..7d794ea02bb 100644 --- a/src/js/tabs/sensors.js +++ b/src/js/tabs/sensors.js @@ -1,7 +1,7 @@ import { i18n } from "../localization"; import GUI from '../gui'; import { get as getConfig, set as setConfig } from '../ConfigStorage'; -import { have_sensor } from "../serial_backend"; +import { have_sensor } from "../sensor_helpers"; import FC from "../fc"; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; diff --git a/src/js/tabs/servos.js b/src/js/tabs/servos.js index 9cbe9cb75aa..25a593dbf1f 100644 --- a/src/js/tabs/servos.js +++ b/src/js/tabs/servos.js @@ -4,6 +4,7 @@ import { mspHelper } from "../msp/MSPHelper"; import FC from "../fc"; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; +import { gui_log } from "../gui_log"; const servos = {}; servos.initialize = function (callback) { @@ -139,7 +140,7 @@ servos.initialize = function (callback) { function save_to_eeprom() { if (save_configuration_to_eeprom) { MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function () { - GUI.log(i18n.getMessage('servosEepromSave')); + gui_log(i18n.getMessage('servosEepromSave')); }); } } diff --git a/src/js/tabs/setup.js b/src/js/tabs/setup.js index 039b6d46c51..7e6cd556ab7 100644 --- a/src/js/tabs/setup.js +++ b/src/js/tabs/setup.js @@ -1,13 +1,14 @@ import { i18n } from '../localization'; import GUI from '../gui'; import { configuration_backup, configuration_restore } from '../backup_restore'; -import { have_sensor } from '../serial_backend'; +import { have_sensor } from '../sensor_helpers'; import { mspHelper } from '../msp/MSPHelper'; import FC from '../fc'; import MSP from '../msp'; import Model from '../model'; import MSPCodes from '../msp/MSPCodes'; import CONFIGURATOR, { API_VERSION_1_42, API_VERSION_1_43 } from '../data_storage'; +import { gui_log } from '../gui_log'; const setup = { yaw_fix: 0.0, @@ -38,13 +39,13 @@ setup.initialize = function (callback) { const backupButton = $('#content .backup'); const restoreButton = $('#content .restore'); - backupButton.on('click', () => configuration_backup(() => GUI.log(i18n.getMessage('initialSetupBackupSuccess')))); + backupButton.on('click', () => configuration_backup(() => gui_log(i18n.getMessage('initialSetupBackupSuccess')))); restoreButton.on('click', () => configuration_restore(() => { // get latest settings TABS.setup.initialize(); - GUI.log(i18n.getMessage('initialSetupRestoreSuccess')); + gui_log(i18n.getMessage('initialSetupRestoreSuccess')); })); if (CONFIGURATOR.virtualMode) { @@ -113,7 +114,7 @@ setup.initialize = function (callback) { // until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow GUI.interval_pause('setup_data_pull'); MSP.send_message(MSPCodes.MSP_ACC_CALIBRATION, false, false, function () { - GUI.log(i18n.getMessage('initialSetupAccelCalibStarted')); + gui_log(i18n.getMessage('initialSetupAccelCalibStarted')); $('#accel_calib_running').show(); $('#accel_calib_rest').hide(); }); @@ -121,7 +122,7 @@ setup.initialize = function (callback) { GUI.timeout_add('button_reset', function () { GUI.interval_resume('setup_data_pull'); - GUI.log(i18n.getMessage('initialSetupAccelCalibEnded')); + gui_log(i18n.getMessage('initialSetupAccelCalibEnded')); _self.removeClass('calibrating'); $('#accel_calib_running').hide(); $('#accel_calib_rest').show(); @@ -136,13 +137,13 @@ setup.initialize = function (callback) { _self.addClass('calibrating'); MSP.send_message(MSPCodes.MSP_MAG_CALIBRATION, false, false, function () { - GUI.log(i18n.getMessage('initialSetupMagCalibStarted')); + gui_log(i18n.getMessage('initialSetupMagCalibStarted')); $('#mag_calib_running').show(); $('#mag_calib_rest').hide(); }); GUI.timeout_add('button_reset', function () { - GUI.log(i18n.getMessage('initialSetupMagCalibEnded')); + gui_log(i18n.getMessage('initialSetupMagCalibEnded')); _self.removeClass('calibrating'); $('#mag_calib_running').hide(); $('#mag_calib_rest').show(); @@ -163,7 +164,7 @@ setup.initialize = function (callback) { $('.dialogConfirmReset-confirmbtn').click(function() { dialogConfirmReset.close(); MSP.send_message(MSPCodes.MSP_RESET_CONF, false, false, function () { - GUI.log(i18n.getMessage('initialSetupSettingsRestored')); + gui_log(i18n.getMessage('initialSetupSettingsRestored')); GUI.tab_switch_cleanup(function () { TABS.setup.initialize(); diff --git a/src/js/tabs/setup_osd.js b/src/js/tabs/setup_osd.js index 5638378b4ed..ef9c2fd07aa 100644 --- a/src/js/tabs/setup_osd.js +++ b/src/js/tabs/setup_osd.js @@ -2,6 +2,7 @@ import { i18n } from "../localization"; import GUI from '../gui'; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; +import { gui_log } from "../gui_log"; const setup_osd = { }; @@ -37,7 +38,7 @@ setup_osd.initialize = function (callback) { $('a.resetSettings').click(function () { MSP.send_message(MSPCodes.MSP_RESET_CONF, false, false, function () { - GUI.log(i18n.getMessage('initialSetupSettingsRestored')); + gui_log(i18n.getMessage('initialSetupSettingsRestored')); GUI.tab_switch_cleanup(function () { TABS.setup_osd.initialize(); diff --git a/src/js/tabs/transponder.js b/src/js/tabs/transponder.js index b5fdbc11326..247461a35aa 100644 --- a/src/js/tabs/transponder.js +++ b/src/js/tabs/transponder.js @@ -5,6 +5,7 @@ import { mspHelper } from '../msp/MSPHelper'; import FC from "../fc"; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; +import { gui_log } from "../gui_log"; const transponder = { available: false, @@ -302,7 +303,7 @@ transponder.initialize = function(callback) { function save_to_eeprom() { MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, function() { - GUI.log(i18n.getMessage('transponderEepromSaved')); + gui_log(i18n.getMessage('transponderEepromSaved')); if ( $(_this).hasClass('reboot') ) { GUI.tab_switch_cleanup(function() { MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection); @@ -314,7 +315,7 @@ transponder.initialize = function(callback) { if (FC.TRANSPONDER.provider !== "0" && FC.TRANSPONDER.data.length !== FC.TRANSPONDER.providers.find(function(provider) { return provider.id == FC.TRANSPONDER.provider; }).dataLength ) { - GUI.log(i18n.getMessage('transponderDataInvalid')); + gui_log(i18n.getMessage('transponderDataInvalid')); } else { save_transponder_data(); } diff --git a/src/js/tabs/vtx.js b/src/js/tabs/vtx.js index 5977bf6d033..a44d71a768a 100644 --- a/src/js/tabs/vtx.js +++ b/src/js/tabs/vtx.js @@ -9,6 +9,7 @@ import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; import { API_VERSION_1_42, API_VERSION_1_44 } from '../data_storage'; import UI_PHONES from "../phones_ui"; +import { gui_log } from "../gui_log"; const vtx = { supported: false, @@ -643,7 +644,7 @@ vtx.initialize = function (callback) { writer.onerror = function(){ console.error('Failed to write VTX table lua file'); - GUI.log(i18n.getMessage('vtxSavedLuaFileKo')); + gui_log(i18n.getMessage('vtxSavedLuaFileKo')); }; writer.onwriteend = function() { @@ -656,7 +657,7 @@ vtx.initialize = function (callback) { writer.onwriteend = function() { tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'VtxTableLuaSave', text.length); console.log('Write VTX table lua file end'); - GUI.log(i18n.getMessage('vtxSavedLuaFileOk')); + gui_log(i18n.getMessage('vtxSavedLuaFileOk')); }; writer.write(data); @@ -666,7 +667,7 @@ vtx.initialize = function (callback) { }, function (){ console.error('Failed to get VTX table lua file writer'); - GUI.log(i18n.getMessage('vtxSavedLuaFileKo')); + gui_log(i18n.getMessage('vtxSavedLuaFileKo')); }); }); } @@ -694,7 +695,7 @@ vtx.initialize = function (callback) { writer.onerror = function(){ console.error('Failed to write VTX file'); - GUI.log(i18n.getMessage('vtxSavedFileKo')); + gui_log(i18n.getMessage('vtxSavedFileKo')); }; writer.onwriteend = function() { @@ -708,7 +709,7 @@ vtx.initialize = function (callback) { tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'VtxTableSave', text.length); console.log(vtxConfig); console.log('Write VTX file end'); - GUI.log(i18n.getMessage('vtxSavedFileOk')); + gui_log(i18n.getMessage('vtxSavedFileOk')); }; writer.write(data); @@ -718,7 +719,7 @@ vtx.initialize = function (callback) { }, function (){ console.error('Failed to get VTX file writer'); - GUI.log(i18n.getMessage('vtxSavedFileKo')); + gui_log(i18n.getMessage('vtxSavedFileKo')); }); }); } @@ -760,20 +761,20 @@ vtx.initialize = function (callback) { self.analyticsChanges['VtxTableLoadFromFile'] = file.name; console.log('Load VTX file end'); - GUI.log(i18n.getMessage('vtxLoadFileOk')); + gui_log(i18n.getMessage('vtxLoadFileOk')); }, function() { // JSON is NOT valid console.error('VTX Config from file failed validation against schema'); - GUI.log(i18n.getMessage('vtxLoadFileKo')); + gui_log(i18n.getMessage('vtxLoadFileKo')); }, ); } catch (err) { console.error('Failed loading VTX file config'); - GUI.log(i18n.getMessage('vtxLoadFileKo')); + gui_log(i18n.getMessage('vtxLoadFileKo')); } }; @@ -781,7 +782,7 @@ vtx.initialize = function (callback) { }, function() { console.error('Failed to get VTX file reader'); - GUI.log(i18n.getMessage('vtxLoadFileKo')); + gui_log(i18n.getMessage('vtxLoadFileKo')); }); }); } @@ -810,25 +811,25 @@ vtx.initialize = function (callback) { self.analyticsChanges['VtxTableLoadFromClipboard'] = text.length; console.log('Load VTX clipboard end'); - GUI.log(i18n.getMessage('vtxLoadClipboardOk')); + gui_log(i18n.getMessage('vtxLoadClipboardOk')); }, function() { // JSON is NOT valid - GUI.log(i18n.getMessage('vtxLoadClipboardKo')); + gui_log(i18n.getMessage('vtxLoadClipboardKo')); console.error('VTX Config from clipboard failed validation against schema'); }, ); }, function(err) { - GUI.log(i18n.getMessage('vtxLoadClipboardKo')); + gui_log(i18n.getMessage('vtxLoadClipboardKo')); console.error('Failed to read clipboard contents: ', err); }, ); } catch (err) { console.error(`Failed loading VTX file config: ${err}`); - GUI.log(i18n.getMessage('vtxLoadClipboardKo')); + gui_log(i18n.getMessage('vtxLoadClipboardKo')); } } @@ -891,7 +892,7 @@ vtx.initialize = function (callback) { } function save_completed() { - GUI.log(i18n.getMessage('configurationEepromSaved')); + gui_log(i18n.getMessage('configurationEepromSaved')); TABS.vtx.vtxTableSavePending = false; diff --git a/src/js/update_dataflash_global.js b/src/js/update_dataflash_global.js new file mode 100644 index 00000000000..293352ed311 --- /dev/null +++ b/src/js/update_dataflash_global.js @@ -0,0 +1,44 @@ +import FC from "./fc"; + +export function update_dataflash_global() { + function formatFilesize(bytes) { + if (bytes < 1024) { + return `${bytes}B`; + } + const kilobytes = bytes / 1024; + + if (kilobytes < 1024) { + return `${Math.round(kilobytes)}kB`; + } + + const megabytes = kilobytes / 1024; + + return `${megabytes.toFixed(1)}MB`; + } + + const supportsDataflash = FC.DATAFLASH.totalSize > 0; + + if (supportsDataflash){ + $(".noflash_global").css({ + display: 'none', + }); + + $(".dataflash-contents_global").css({ + display: 'block', + }); + + $(".dataflash-free_global").css({ + width: `${100-(FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize) / FC.DATAFLASH.totalSize * 100}%`, + display: 'block', + }); + $(".dataflash-free_global div").text(`Dataflash: free ${formatFilesize(FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize)}`); + } else { + $(".noflash_global").css({ + display: 'block', + }); + + $(".dataflash-contents_global").css({ + display: 'none', + }); + } +} diff --git a/src/tabs/presets/CliEngine.js b/src/tabs/presets/CliEngine.js index fb2869debb2..4cf3ea30611 100644 --- a/src/tabs/presets/CliEngine.js +++ b/src/tabs/presets/CliEngine.js @@ -2,6 +2,7 @@ import GUI from "../../js/gui"; import { i18n } from "../../js/localization"; import CONFIGURATOR from "../../js/data_storage"; import serial from "../../js/serial"; +import { gui_log } from "../../js/gui_log"; export default class CliEngine { @@ -210,13 +211,13 @@ export default class CliEngine if (this.cliBuffer === 'Rebooting' && CliEngine.s_backspaceCode !== charCode) { CONFIGURATOR.cliEngineActive = false; CONFIGURATOR.cliEngineValid = false; - GUI.log(i18n.getMessage('cliReboot')); + gui_log(i18n.getMessage('cliReboot')); reinitializeConnection(this._currentTab); } } if (!CONFIGURATOR.cliEngineValid && validateText.indexOf('CLI') !== -1) { - GUI.log(i18n.getMessage('cliEnter')); + gui_log(i18n.getMessage('cliEnter')); CONFIGURATOR.cliEngineValid = true; } }