diff --git a/package.json b/package.json index 57b70b8d36..7d3fb8df54 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "release:default": "NODE_ENV=production gulp release", "release:windows": "set NODE_ENV=production&& gulp release", "pretest": "yarn run lint", - "test": "karma start test/karma.conf.js", + "test": "vitest", "lint": "eslint --ext .js,.vue src gulpfile.js gulp-appdmg.js", "lint:fix": "eslint --fix src gulpfile.js gulp-appdmg.js", "storybook": "start-storybook -p 6006" @@ -66,6 +66,7 @@ "jquery-textcomplete": "^1.8.5", "jquery-touchswipe": "^1.6.19", "jquery-ui-npm": "^1.12.0", + "jsdom": "^21.0.0", "lru_map": "^0.3.3", "marked": "^4.1.1", "multicast-dns": "^7.2.5", @@ -92,7 +93,6 @@ "@storybook/addon-links": "^6.5.12", "@storybook/vue": "^6.5.12", "babel-loader": "^8.2.5", - "chai": "^4.3.6", "command-exists": "^1.2.9", "cordova-lib": "^11.0.0", "del": "^6.1.1", @@ -114,17 +114,6 @@ "gulp-yarn": "^3.0.0", "gulp-zip": "^5.1.0", "husky": "^4.3.0", - "karma": "^6.4.1", - "karma-chai": "^0.1.0", - "karma-chrome-launcher": "^3.1.1", - "karma-junit-reporter": "^2.0.1", - "karma-mocha": "^2.0.1", - "karma-rollup-preprocessor": "^7.0.8", - "karma-sinon": "^1.0.5", - "karma-sinon-chai": "^2.0.2", - "karma-spec-reporter": "^0.0.34", - "karma-tfs-reporter": "^1.0.2", - "mocha": "^10.0.0", "nw-builder": "^3.8.6", "os": "^0.1.2", "postcss": "^8.4.17", @@ -133,12 +122,12 @@ "rpm-builder": "^1.2.1", "run-script-os": "^1.1.6", "simple-git": "^3.15.0", - "sinon": "^14.0.0", - "sinon-chai": "^3.7.0", "targz": "^1.0.1", "temp": "^0.9.4", "through2": "^4.0.2", "vinyl-source-stream": "^2.0.0", + "vite": "^4.0.4", + "vitest": "^0.27.1", "vue-loader": "^15.9.8", "vue-template-compiler": "^2.7.10", "yarn": "^1.22.19" diff --git a/src/components/EscDshotDirection/EscDshotCommandQueue.js b/src/components/EscDshotDirection/EscDshotCommandQueue.js index 94a9a01014..7b5b805a45 100644 --- a/src/components/EscDshotDirection/EscDshotCommandQueue.js +++ b/src/components/EscDshotDirection/EscDshotCommandQueue.js @@ -1,3 +1,5 @@ +import MSP from '../../js/msp.js'; + class EscDshotCommandQueue { constructor (intervalMs) diff --git a/src/components/EscDshotDirection/EscDshotDirectionComponent.js b/src/components/EscDshotDirection/EscDshotDirectionComponent.js index 0990ca8904..2af3a00885 100644 --- a/src/components/EscDshotDirection/EscDshotDirectionComponent.js +++ b/src/components/EscDshotDirection/EscDshotDirectionComponent.js @@ -3,6 +3,8 @@ import GUI from "../../js/gui.js"; import semver from "semver"; import EscDshotDirectionMotorDriver from "./EscDshotDirectionMotorDriver.js"; import DshotCommand from "../../js/utils/DshotCommand.js"; +import FC from "../../js/fc.js"; +import { API_VERSION_1_44 } from '../../js/data_storage.js'; class EscDshotDirectionComponent { diff --git a/src/components/EscDshotDirection/EscDshotDirectionMotorDriver.js b/src/components/EscDshotDirection/EscDshotDirectionMotorDriver.js index 90dd9e3ca4..f18994f5de 100644 --- a/src/components/EscDshotDirection/EscDshotDirectionMotorDriver.js +++ b/src/components/EscDshotDirection/EscDshotDirectionMotorDriver.js @@ -1,5 +1,6 @@ import EscDshotCommandQueue from './EscDshotCommandQueue.js'; import DshotCommand from '../../js/utils/DshotCommand.js'; +import MSPCodes from '../../js/msp/MSPCodes.js'; class EscDshotDirectionMotorDriver { diff --git a/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js b/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js index 624892142c..e5d5067b0a 100644 --- a/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js +++ b/src/components/MotorOutputReordering/MotorOutputReorderingComponent.js @@ -2,6 +2,10 @@ import MotorOutputReorderConfig from "./MotorOutputReorderingConfig"; import MotorOutputReorderCanvas from "./MotorOutputReorderingCanvas"; import { mspHelper } from "../../js/msp/MSPHelper"; 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 { @@ -94,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/components/init.js b/src/components/init.js index e07c49a27f..79501b3e10 100644 --- a/src/components/init.js +++ b/src/components/init.js @@ -12,6 +12,9 @@ import BetaflightLogo from "./betaflight-logo/BetaflightLogo.vue"; import StatusBar from "./status-bar/StatusBar.vue"; import BatteryIcon from "./quad-status/BatteryIcon.vue"; import FC from '../js/fc.js'; +import MSP from '../js/msp.js'; +import PortUsage from '../js/port_usage.js'; +import CONFIGURATOR from '../js/data_storage.js'; // Most of the global objects can go here at first. // It's a bit of overkill for simple components, diff --git a/src/js/Beepers.js b/src/js/Beepers.js index 466b8914d5..7dc2efce48 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 911afc582d..577c9fde31 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 67791b15fb..f3f57f2ce9 100644 --- a/src/js/CliAutoComplete.js +++ b/src/js/CliAutoComplete.js @@ -1,4 +1,6 @@ -'use strict'; +import GUI from './gui'; +import CONFIGURATOR from './data_storage'; +import FC from './fc'; /** * Encapsulates the AutoComplete logic @@ -575,3 +577,6 @@ CliAutoComplete._initTextcomplete = function() { }), ]); }; + +window.CliAutoComplete = CliAutoComplete; +export default CliAutoComplete; diff --git a/src/js/DarkTheme.js b/src/js/DarkTheme.js index 40784bce7f..7cbeeabbde 100644 --- a/src/js/DarkTheme.js +++ b/src/js/DarkTheme.js @@ -1,4 +1,5 @@ -'use strict'; +import GUI from "./gui"; +import windowWatcherUtil from "./utils/window_watchers"; const css_dark = [ './css/dark-theme.css', @@ -63,3 +64,5 @@ DarkTheme.applyDark = function () { DarkTheme.applyNormal = function () { css_dark.forEach((el) => $(`link[href="${el}"]`).prop('disabled', true)); }; + +export default DarkTheme; diff --git a/src/js/Features.js b/src/js/Features.js index 14e83c19e8..91c5a93aae 100644 --- a/src/js/Features.js +++ b/src/js/Features.js @@ -1,4 +1,5 @@ -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) { const self = this; diff --git a/src/js/GitHubApi.js b/src/js/GitHubApi.js index 5f6316ffdf..ebca77af5e 100644 --- a/src/js/GitHubApi.js +++ b/src/js/GitHubApi.js @@ -1,5 +1,4 @@ -'use strict'; - +// NOTE: this files seems to be unused anywhere const GitHubApi = function () { const self = this; @@ -25,3 +24,5 @@ GitHubApi.prototype.getFileLastCommitInfo = function (project, branch, filename, callback(result); }); }; + +export default GitHubApi; diff --git a/src/js/LogoManager.js b/src/js/LogoManager.js index 8f9c48f6c5..664c06646a 100644 --- a/src/js/LogoManager.js +++ b/src/js/LogoManager.js @@ -1,6 +1,5 @@ -'use strict'; - -(function () { +import { gui_log } from "./gui_log"; +import { i18n } from "./localization"; /** * Takes an ImageData object and returns an MCM symbol as an array of strings. @@ -132,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, })); @@ -158,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], @@ -288,6 +287,4 @@ LogoManager.drawPreview = function () { } }; -window.LogoManager = LogoManager; - -})(); +export default LogoManager; diff --git a/src/js/RateCurve.js b/src/js/RateCurve.js index c509ac0960..e83cdd9bc0 100644 --- a/src/js/RateCurve.js +++ b/src/js/RateCurve.js @@ -1,4 +1,5 @@ -'use strict'; +import FC from "./fc"; +import { API_VERSION_1_43 } from "./data_storage"; const minRc = 1000; const midRc = 1500; @@ -277,3 +278,5 @@ RateCurve.prototype.draw = function (rate, rcRate, rcExpo, superExpoActive, dead } } }; + +export default RateCurve; diff --git a/src/js/TuningSliders.js b/src/js/TuningSliders.js index 0e28dff528..621ad7b0ad 100644 --- a/src/js/TuningSliders.js +++ b/src/js/TuningSliders.js @@ -1,4 +1,7 @@ -'use strict'; +import MSP from "./msp"; +import FC from "./fc"; +import MSPCodes from "./msp/MSPCodes"; +import { API_VERSION_1_44 } from './data_storage'; const TuningSliders = { // Legacy Sliders @@ -824,3 +827,5 @@ TuningSliders.resetDTermFilterSlider = function() { this.calculateNewDTermFilters(); this.updateFilterSlidersDisplay(); }; + +export default TuningSliders; diff --git a/src/js/VirtualFC.js b/src/js/VirtualFC.js index 0117350410..21a43152f5 100644 --- a/src/js/VirtualFC.js +++ b/src/js/VirtualFC.js @@ -1,6 +1,8 @@ import Features from "./Features"; +import { i18n } from "./localization"; import Beepers from "./Beepers"; import FC from "./fc"; +import CONFIGURATOR from "./data_storage"; const VirtualFC = { // these values are manufactured to unlock all the functionality of the configurator, they dont represent actual hardware diff --git a/src/js/backup_restore.js b/src/js/backup_restore.js index 1e67870b18..c849dbdd2a 100644 --- a/src/js/backup_restore.js +++ b/src/js/backup_restore.js @@ -1,10 +1,16 @@ -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"; import Beepers from "./Beepers"; import FC from "./fc"; 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 @@ -305,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) { @@ -318,7 +324,7 @@ export function configuration_restore(callback) { configuration_upload(configuration, callback); } else { - GUI.log(i18n.getMessage('backupFileIncompatible')); + gui_log(i18n.getMessage('backupFileIncompatible')); } } }; @@ -338,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')) { @@ -347,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++; } @@ -359,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++; } @@ -374,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++; } @@ -404,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++; } @@ -460,7 +466,7 @@ export function configuration_restore(callback) { ports: ports, }; - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -480,7 +486,7 @@ export function configuration_restore(callback) { }; } - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -520,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++; } @@ -538,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++; } @@ -555,7 +561,7 @@ export function configuration_restore(callback) { }; } - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -622,7 +628,7 @@ export function configuration_restore(callback) { } } - GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion])); + gui_log(i18n.getMessage('configMigratedTo', [migratedVersion])); appliedMigrationsCount++; } @@ -633,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++; } @@ -649,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; } @@ -879,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 0000000000..b447147a8a --- /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/boards.js b/src/js/boards.js index 1e8a7aa53a..3a1409346a 100644 --- a/src/js/boards.js +++ b/src/js/boards.js @@ -91,3 +91,5 @@ BOARD.find_board_definition = function (identifier) { } return DEFAULT_BOARD_DEFINITION; }; + +export default BOARD; diff --git a/src/js/data_storage.js b/src/js/data_storage.js index 174cfbbca7..c3fdfcd1de 100644 --- a/src/js/data_storage.js +++ b/src/js/data_storage.js @@ -1,13 +1,11 @@ -'use strict'; +export const API_VERSION_1_39 = '1.39.0'; +export const API_VERSION_1_40 = '1.40.0'; -const API_VERSION_1_39 = '1.39.0'; -const API_VERSION_1_40 = '1.40.0'; - -const API_VERSION_1_41 = '1.41.0'; -const API_VERSION_1_42 = '1.42.0'; -const API_VERSION_1_43 = '1.43.0'; -const API_VERSION_1_44 = '1.44.0'; -const API_VERSION_1_45 = '1.45.0'; +export const API_VERSION_1_41 = '1.41.0'; +export const API_VERSION_1_42 = '1.42.0'; +export const API_VERSION_1_43 = '1.43.0'; +export const API_VERSION_1_44 = '1.44.0'; +export const API_VERSION_1_45 = '1.45.0'; const CONFIGURATOR = { // all versions are specified and compared using semantic versioning http://semver.org/ @@ -38,3 +36,5 @@ const CONFIGURATOR = { } }, }; + +export default CONFIGURATOR; diff --git a/src/js/default_huffman_tree.js b/src/js/default_huffman_tree.js index 3c7a34a04d..26763ce73b 100644 --- a/src/js/default_huffman_tree.js +++ b/src/js/default_huffman_tree.js @@ -1,6 +1,6 @@ -'use strict'; +import { HUFFMAN_EOF } from "./huffman"; -const defaultHuffmanTree = [ +export const defaultHuffmanTree = [ { value: 0x00, codeLen: 2, code: 0x0003 }, // 11 { value: 0x01, codeLen: 3, code: 0x0005 }, // 101 { value: 0x02, codeLen: 4, code: 0x0009 }, // 1001 @@ -260,7 +260,7 @@ const defaultHuffmanTree = [ { value: HUFFMAN_EOF, codeLen: 12, code: 0x0000 }, // 000000000000 ]; -const defaultHuffmanLenIndex = function() { +export const defaultHuffmanLenIndex = function() { const result = Array(defaultHuffmanTree.length).fill(-1); for (let i = 0; i < defaultHuffmanTree.length; ++i) { diff --git a/src/js/fc.js b/src/js/fc.js index fd8210e9aa..96ab2ba407 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -1,4 +1,5 @@ -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 = { apiVersion: "0.0.0", @@ -902,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 d637d2a2d0..055a9dceee 100644 --- a/src/js/gui.js +++ b/src/js/gui.js @@ -1,6 +1,9 @@ import { get as getConfig } from './ConfigStorage'; +import MSP from './msp'; -window.TABS = {}; // filled by individual tab js file +const TABS = {}; + +window.TABS = TABS; // filled by individual tab js file const GUI_MODES = { NWJS: "NW.js", @@ -242,22 +245,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 @@ -538,7 +526,7 @@ function GUI_checkOperatingSystem() { const GUI = new GuiControl(); +export { TABS }; // initialize object into GUI variable window.GUI = GUI; - export default GUI; diff --git a/src/js/gui_log.js b/src/js/gui_log.js new file mode 100644 index 0000000000..f45874aa86 --- /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/huffman.js b/src/js/huffman.js index fbbbad1349..dcb5a7e856 100644 --- a/src/js/huffman.js +++ b/src/js/huffman.js @@ -1,6 +1,4 @@ -'use strict'; - -const HUFFMAN_EOF = -1; +export const HUFFMAN_EOF = -1; function huffmanDecodeBuf(inBuf, inBufCharacterCount, huffmanTree, huffmanLenIndex) { let code = 0; @@ -57,3 +55,5 @@ function huffmanDecodeBuf(inBuf, inBufCharacterCount, huffmanTree, huffmanLenInd return new Uint8Array(outBuf); } + +export default huffmanDecodeBuf; diff --git a/src/js/localization.js b/src/js/localization.js index 1086960de1..9afefdad33 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 9e248a9852..5ecfec0592 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -1,14 +1,19 @@ import '../components/init.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'; import GUI from './gui.js'; import { get as getConfig, set as setConfig } from './ConfigStorage.js'; import ReleaseChecker from './release_checker.js'; import { tracking, createAnalytics } from './Analytics.js'; import { initializeSerialBackend } from './serial_backend.js'; -// Currently fc is everywhere, so we need to import it here -// till all is in modules -import './fc.js'; -import './msp/MSPHelper.js'; +import FC from './fc.js'; +import CONFIGURATOR, { API_VERSION_1_42, API_VERSION_1_45 } from './data_storage.js'; +import serial from './serial.js'; +import CliAutoComplete from './CliAutoComplete.js'; +import DarkTheme from './DarkTheme.js'; +import UI_PHONES from './phones_ui.js'; $(document).ready(function () { @@ -215,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(); @@ -291,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; } @@ -308,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; } @@ -690,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/mdns_discovery.js b/src/js/mdns_discovery.js index 29b5ef65dd..fb8fd0c8f7 100644 --- a/src/js/mdns_discovery.js +++ b/src/js/mdns_discovery.js @@ -1,4 +1,5 @@ -'use strict'; +import GUI from './gui'; +import PortHandler from './port_handler'; const MDNS_INTERVAL = 10000; const TCP_CHECK_INTERVAL = 5000; @@ -132,3 +133,5 @@ MdnsDiscovery.tcpCheck = function() { } } }; + +export default MdnsDiscovery; diff --git a/src/js/model.js b/src/js/model.js index 37095b3e25..dfcda13aed 100644 --- a/src/js/model.js +++ b/src/js/model.js @@ -1,7 +1,7 @@ -'use strict'; +import FC from "./fc"; // generate mixer -const mixerList = [ +export const mixerList = [ { name: 'Tricopter', pos: 3, model: 'tricopter', image: 'tri', motors: 3, servos: true }, { name: 'Quad +', pos: 2, model: 'quad_x', image: 'quad_p', motors: 4, servos: false }, { name: 'Quad X', pos: 0, model: 'quad_x', image: 'quad_x', motors: 4, servos: false }, @@ -151,3 +151,5 @@ Model.prototype.dispose = function () { this.renderer.dispose(); } }; + +export default Model; diff --git a/src/js/msp.js b/src/js/msp.js index eb7bb0ba95..28d4e3e0f7 100644 --- a/src/js/msp.js +++ b/src/js/msp.js @@ -1,4 +1,6 @@ -'use strict'; +import GUI from "./gui.js"; +import CONFIGURATOR from "./data_storage.js"; +import serial from "./serial.js"; const MSP = { symbols: { @@ -407,3 +409,12 @@ const MSP = { this.callbacks_cleanup(); }, }; + +MSP.SDCARD_STATE_NOT_PRESENT = 0; +MSP.SDCARD_STATE_FATAL = 1; +MSP.SDCARD_STATE_CARD_INIT = 2; +MSP.SDCARD_STATE_FS_INIT = 3; +MSP.SDCARD_STATE_READY = 4; + +window.MSP = MSP; +export default MSP; diff --git a/src/js/msp/MSPCodes.js b/src/js/msp/MSPCodes.js index 610221ea7a..e4f1f7178f 100644 --- a/src/js/msp/MSPCodes.js +++ b/src/js/msp/MSPCodes.js @@ -1,5 +1,3 @@ -'use strict'; - //MSPCodes needs to be re-integrated inside MSP object const MSPCodes = { MSP_API_VERSION: 1, @@ -205,3 +203,5 @@ const MSPCodes = { PID_PROFILE_NAME: 3, RATE_PROFILE_NAME: 4, }; + +export default MSPCodes; diff --git a/src/js/msp/MSPConnector.js b/src/js/msp/MSPConnector.js index a21f8b9a75..3f90e98a81 100644 --- a/src/js/msp/MSPConnector.js +++ b/src/js/msp/MSPConnector.js @@ -1,5 +1,13 @@ import MspHelper from "./MSPHelper"; import { read_serial } from "../serial_backend"; +import { i18n } from "../localization"; +import GUI from "../gui"; +import MSP from "../msp"; +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; @@ -37,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(); } @@ -57,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 cc6e51aeed..d1e4236ddc 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -1,10 +1,17 @@ -// 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"; +import MSP from "../msp"; +import MSPCodes from "./MSPCodes"; +import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from '../data_storage'; +import EscProtocols from "../utils/EscProtocols"; +import huffmanDecodeBuf from "../huffman"; +import { defaultHuffmanTree, defaultHuffmanLenIndex } from "../default_huffman_tree"; // Used for LED_STRIP const ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order @@ -2610,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) { @@ -2641,11 +2648,6 @@ MspHelper.prototype.sendSerialConfig = function(callback) { MSP.send_message(mspCode, mspHelper.crunch(mspCode), false, callback); }; -MSP.SDCARD_STATE_NOT_PRESENT = 0; //TODO, move these to better place -MSP.SDCARD_STATE_FATAL = 1; -MSP.SDCARD_STATE_CARD_INIT = 2; -MSP.SDCARD_STATE_FS_INIT = 3; -MSP.SDCARD_STATE_READY = 4; let mspHelper; // This is temporary, till things are moved diff --git a/src/js/peripherals.js b/src/js/peripherals.js index 1754e05f05..daa97c95e1 100644 --- a/src/js/peripherals.js +++ b/src/js/peripherals.js @@ -1,4 +1,5 @@ -'use strict'; +import { i18n } from "./localization"; +import FC from "./fc"; // return true if user has choose a special peripheral function isPeripheralSelected(peripheralName) { @@ -30,3 +31,5 @@ function adjustBoxNameIfPeripheralWithModeID(modeId, defaultName) { return defaultName; } + +export default adjustBoxNameIfPeripheralWithModeID; diff --git a/src/js/phones_ui.js b/src/js/phones_ui.js index 202d277221..08903c04b0 100644 --- a/src/js/phones_ui.js +++ b/src/js/phones_ui.js @@ -1,4 +1,4 @@ -'use strict'; +import GUI from "./gui"; const UI_PHONES = { background: '#background', @@ -85,3 +85,5 @@ const UI_PHONES = { $(this.headerbar).removeClass('expand2 expand'); }, }; + +export default UI_PHONES; diff --git a/src/js/port_handler.js b/src/js/port_handler.js index c8f1f7fca7..94847859df 100644 --- a/src/js/port_handler.js +++ b/src/js/port_handler.js @@ -1,8 +1,14 @@ -'use strict'; +import GUI from "./gui"; +import FC from "./fc"; +import { i18n } from "./localization"; +import { generateVirtualApiVersions } from './utils/common'; +import { get as getConfig } from "./ConfigStorage"; +import serial from "./serial"; +import MdnsDiscovery from "./mdns_discovery"; const TIMEOUT_CHECK = 500 ; // With 250 it seems that it produces a memory leak and slowdown in some versions, reason unknown -const usbDevices = { filters: [ +export const usbDevices = { filters: [ {'vendorId': 1155, 'productId': 57105}, // STM Device in DFU Mode || Digital Radio in USB mode {'vendorId': 10473, 'productId': 393}, // GD32 DFU Bootloader ] }; @@ -36,8 +42,8 @@ PortHandler.reinitialize = function () { if (this.usbCheckLoop) { clearTimeout(this.usbCheckLoop); } - this.showVirtualMode = ConfigStorage.get('showVirtualMode').showVirtualMode; - this.showAllSerialDevices = ConfigStorage.get('showAllSerialDevices').showAllSerialDevices; + this.showVirtualMode = getConfig('showVirtualMode').showVirtualMode; + this.showAllSerialDevices = getConfig('showAllSerialDevices').showAllSerialDevices; this.check(); // start listening, check after TIMEOUT_CHECK ms }; @@ -420,3 +426,7 @@ PortHandler.flush_callbacks = function () { return killed; }; + +// temp workaround till everything is in modules +window.PortHandler = PortHandler; +export default PortHandler; diff --git a/src/js/port_usage.js b/src/js/port_usage.js index a7c3c68eb1..f51fba03be 100644 --- a/src/js/port_usage.js +++ b/src/js/port_usage.js @@ -1,4 +1,4 @@ -'use strict'; +import serial from "./serial"; const PortUsage = { previous_received: 0, @@ -36,3 +36,7 @@ const PortUsage = { this.port_usage_up = 0; }, }; + +// drop these after all is in modules +window.PortUsage = PortUsage; +export default PortUsage; diff --git a/src/js/protocols/stm32.js b/src/js/protocols/stm32.js index 1600aa37ef..52d70cea67 100644 --- a/src/js/protocols/stm32.js +++ b/src/js/protocols/stm32.js @@ -6,7 +6,18 @@ popular choices - 921600, 460800, 256000, 230400, 153600, 128000, 115200, 57600, 38400, 28800, 19200 */ import MSPConnectorImpl from "../msp/MSPConnector"; -import { bit_check } from "../serial_backend"; +import GUI from "../gui"; +import { i18n } from "../localization"; +import MSP from "../msp"; +import FC from "../fc"; +import { bit_check } from "../bit"; +import { gui_log } from "../gui_log"; +import MSPCodes from "../msp/MSPCodes"; +import PortUsage from "../port_usage"; +import PortHandler, { usbDevices } from "../port_handler"; +import { API_VERSION_1_42 } from "../data_storage"; +import serial from "../serial"; +import STM32DFU from "./stm32usbdfu"; const STM32_protocol = function () { this.baud = null; @@ -85,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 { @@ -106,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')); } }); } @@ -127,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; } } @@ -144,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; } @@ -164,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) { @@ -178,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 f5defaab54..68eaef129f 100644 --- a/src/js/protocols/stm32usbdfu.js +++ b/src/js/protocols/stm32usbdfu.js @@ -10,7 +10,9 @@ that being said, it seems that certain level of CLRSTATUS is required before running another type of operation for example switching from DNLOAD to UPLOAD, etc, clearning the state so device is in dfuIDLE is highly recommended. */ -'use strict'; +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` @@ -100,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')); } }); }; @@ -111,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); }); @@ -132,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}`); } @@ -634,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. @@ -648,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 { @@ -673,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 @@ -695,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); @@ -706,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(); @@ -716,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(); } @@ -736,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); @@ -785,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(); } }; @@ -852,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(); @@ -1124,3 +1126,5 @@ STM32DFU_protocol.prototype.cleanup = function () { // initialize object const STM32DFU = new STM32DFU_protocol(); + +export default STM32DFU; diff --git a/src/js/release_checker.js b/src/js/release_checker.js index d981859794..14529dfd48 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 0000000000..3da219e355 --- /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 f8edf393ac..9c2f65788c 100644 --- a/src/js/serial.js +++ b/src/js/serial.js @@ -1,4 +1,8 @@ -'use strict'; +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, @@ -64,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 { @@ -85,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 { @@ -104,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 @@ -461,3 +465,5 @@ const serial = { } }, }; + +export default serial; diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 3702b182b9..d2dd7fcee9 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -6,6 +6,18 @@ import Features from "./Features"; import VirtualFC from "./VirtualFC"; import Beepers from "./Beepers"; import FC from "./fc"; +import MSP from "./msp"; +import MSPCodes from "./msp/MSPCodes"; +import PortUsage from "./port_usage"; +import PortHandler from "./port_handler"; +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; @@ -211,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 } @@ -227,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'); @@ -258,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)) { @@ -268,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); }); @@ -313,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(); } @@ -354,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]; @@ -450,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(); }); @@ -463,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)); @@ -564,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(); @@ -606,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); @@ -753,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. @@ -821,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); @@ -831,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(); } @@ -840,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 8cb1319c2d..b3318e9865 100644 --- a/src/js/tabs/adjustments.js +++ b/src/js/tabs/adjustments.js @@ -1,6 +1,11 @@ import { i18n } from '../localization'; import GUI from '../gui'; import { mspHelper } from '../msp/MSPHelper'; +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 = {}; @@ -232,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 9b684c6d0b..0bb77c99a5 100644 --- a/src/js/tabs/auxiliary.js +++ b/src/js/tabs/auxiliary.js @@ -1,8 +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 = {}; @@ -392,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')); }); } }); @@ -561,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 fa832d1b5e..928925accb 100644 --- a/src/js/tabs/cli.js +++ b/src/js/tabs/cli.js @@ -4,6 +4,11 @@ import GUI from '../gui'; import BuildApi from '../BuildApi'; import { tracking } from '../Analytics'; import { reinitializeConnection } from "../serial_backend"; +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, @@ -503,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(); } @@ -512,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 0170c34861..d1335653c5 100644 --- a/src/js/tabs/configuration.js +++ b/src/js/tabs/configuration.js @@ -4,6 +4,11 @@ import GUI from '../gui'; import { tracking } from "../Analytics"; import { reinitializeConnection } from '../serial_backend'; import { mspHelper } from '../msp/MSPHelper'; +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: {}, @@ -549,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 c4822afa89..891817b764 100644 --- a/src/js/tabs/failsafe.js +++ b/src/js/tabs/failsafe.js @@ -2,7 +2,12 @@ import { i18n } from "../localization"; import GUI from '../gui'; import { reinitializeConnection } from "../serial_backend"; import { mspHelper } from "../msp/MSPHelper"; - +import MSP from "../msp"; +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 = {}; @@ -366,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 359abbf939..1e08d87376 100644 --- a/src/js/tabs/firmware_flasher.js +++ b/src/js/tabs/firmware_flasher.js @@ -8,6 +8,13 @@ import { tracking } from "../Analytics"; import MspHelper from '../msp/MSPHelper'; import STM32 from '../protocols/stm32'; import FC from '../fc'; +import MSP from '../msp'; +import MSPCodes from '../msp/MSPCodes'; +import PortHandler, { usbDevices } 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, @@ -449,7 +456,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; } @@ -494,7 +501,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); @@ -532,10 +539,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(); } @@ -565,7 +572,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')); } } @@ -578,7 +585,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; @@ -593,7 +600,7 @@ firmware_flasher.initialize = function (callback) { console.log('Releases not loaded yet'); } } else { - GUI.log(i18n.getMessage('firmwareFlasherNoValidPort')); + gui_log(i18n.getMessage('firmwareFlasherNoValidPort')); } } } @@ -789,7 +796,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; } @@ -1090,7 +1097,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')); } }); }); @@ -1106,7 +1113,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 @@ -1114,7 +1121,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 627849d0cb..d277194519 100644 --- a/src/js/tabs/gps.js +++ b/src/js/tabs/gps.js @@ -1,7 +1,9 @@ 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"; const gps = {}; gps.initialize = function (callback) { diff --git a/src/js/tabs/led_strip.js b/src/js/tabs/led_strip.js index c6451e2bb0..a0d41e348e 100644 --- a/src/js/tabs/led_strip.js +++ b/src/js/tabs/led_strip.js @@ -2,6 +2,9 @@ import { i18n } from "../localization"; import GUI from '../gui'; 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, @@ -579,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 5f2d165280..571e312b58 100644 --- a/src/js/tabs/logging.js +++ b/src/js/tabs/logging.js @@ -3,6 +3,10 @@ import GUI from '../gui'; import { i18n } from '../localization'; import { get as getConfig, set as setConfig } from '../ConfigStorage'; 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) { @@ -86,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(); @@ -96,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')); } }); @@ -297,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 a74db9a8d0..767893dcaf 100644 --- a/src/js/tabs/motors.js +++ b/src/js/tabs/motors.js @@ -6,9 +6,16 @@ import MotorOutputReorderComponent from "../../components/MotorOutputReordering/ import EscDshotDirectionComponent from "../../components/EscDshotDirection/EscDshotDirectionComponent"; import DshotCommand from "../../js/utils/DshotCommand.js"; 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"; +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, @@ -1173,7 +1180,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 d5bcf97d05..2518488050 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -4,6 +4,10 @@ import { tracking } from "../Analytics"; import { reinitializeConnection } from "../serial_backend"; import { mspHelper } from "../msp/MSPHelper"; 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; @@ -55,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); @@ -574,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; } @@ -586,7 +590,7 @@ onboard_logging.initialize = function (callback) { fileEntry.createWriter(function (fileWriter) { fileWriter.onerror = function (e) { - GUI.log(` `); + gui_log(` `); console.error(e); @@ -598,7 +602,7 @@ onboard_logging.initialize = function (callback) { }, function (e) { // File is not readable or does not exist! console.error(e); - GUI.log(i18n.getMessage('dataflashFileWriteFailed')); + gui_log(i18n.getMessage('dataflashFileWriteFailed')); }); }); } diff --git a/src/js/tabs/options.js b/src/js/tabs/options.js index fd2e334b5e..d8b9a2d23b 100644 --- a/src/js/tabs/options.js +++ b/src/js/tabs/options.js @@ -1,6 +1,9 @@ import { i18n } from '../localization'; import GUI from '../gui'; import { get as getConfig, set as setConfig } from '../ConfigStorage'; +import PortHandler from '../port_handler'; +import CliAutoComplete from '../CliAutoComplete'; +import DarkTheme from '../DarkTheme'; const options = {}; options.initialize = function (callback) { diff --git a/src/js/tabs/osd.js b/src/js/tabs/osd.js index 652da339eb..4deb8d3871 100644 --- a/src/js/tabs/osd.js +++ b/src/js/tabs/osd.js @@ -1,9 +1,15 @@ import { i18n } from "../localization"; import GUI from '../gui'; import { tracking } from "../Analytics"; -import { bit_check } from "../serial_backend"; +import { bit_check } from "../bit"; import VirtualFC from "../VirtualFC"; import FC from "../fc"; +import MSP from "../msp"; +import MSPCodes from "../msp/MSPCodes"; +import PortHandler from "../port_handler"; +import CONFIGURATOR, { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from "../data_storage"; +import LogoManager from "../LogoManager"; +import { gui_log } from "../gui_log"; const FONT = {}; const SYM = {}; @@ -250,7 +256,7 @@ FONT.upload = function($progress) { .then(function() { console.log(`Uploaded all ${FONT.data.characters.length} characters`); - GUI.log(i18n.getMessage('osdSetupUploadingFontEnd', {length: FONT.data.characters.length})); + gui_log(i18n.getMessage('osdSetupUploadingFontEnd', {length: FONT.data.characters.length})); OSD.GUI.fontManager.close(); @@ -3245,7 +3251,7 @@ osd.initialize = function(callback) { $('a.save').click(function() { MSP.promise(MSPCodes.MSP_EEPROM_WRITE); - GUI.log(i18n.getMessage('osdSettingsSaved')); + gui_log(i18n.getMessage('osdSettingsSaved')); const oldText = $(this).html(); $(this).html(i18n.getMessage('osdButtonSaved')); setTimeout(() => { @@ -3365,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 372b00d8b7..3d30cfa27d 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -2,9 +2,16 @@ 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"; +import TuningSliders from "../TuningSliders"; +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, @@ -1454,7 +1461,7 @@ pid_tuning.initialize = function (callback) { self.refresh(function () { self.updating = false; - GUI.log(i18n.getMessage('pidTuningPidProfileReset')); + gui_log(i18n.getMessage('pidTuningPidProfileReset')); }); }); }); @@ -1470,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])); }); }); }); @@ -1487,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])); }); }); }); @@ -1801,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')); }); }); @@ -2263,7 +2270,7 @@ pid_tuning.initialize = function (callback) { self.setDirty(false); - GUI.log(i18n.getMessage('pidTuningEepromSaved')); + gui_log(i18n.getMessage('pidTuningEepromSaved')); self.refresh(); }); @@ -2429,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 67eae9f661..211b263d13 100644 --- a/src/js/tabs/ports.js +++ b/src/js/tabs/ports.js @@ -5,6 +5,11 @@ import { tracking } from "../Analytics"; import { reinitializeConnection } from '../serial_backend'; import { mspHelper } from '../msp/MSPHelper'; 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 BOARD from '../boards'; +import { gui_log } from '../gui_log'; const ports = { analyticsChanges: {}, @@ -487,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 0c6d68f66e..d5f802ff66 100644 --- a/src/js/tabs/power.js +++ b/src/js/tabs/power.js @@ -3,6 +3,9 @@ import GUI from '../gui'; import { tracking } from "../Analytics"; 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, @@ -500,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 123975c366..410aa12c8c 100644 --- a/src/js/tabs/receiver.js +++ b/src/js/tabs/receiver.js @@ -2,9 +2,18 @@ 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"; +import Model from "../model"; +import RateCurve from "../RateCurve"; +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'; @@ -417,7 +426,7 @@ receiver.initialize = function (callback) { $('a.refresh').click(function () { tab.refresh(function () { - GUI.log(i18n.getMessage('receiverDataRefreshed')); + gui_log(i18n.getMessage('receiverDataRefreshed')); }); }); @@ -489,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); @@ -549,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/receiver_msp.js b/src/js/tabs/receiver_msp.js index 03a52fb625..69a8e095df 100644 --- a/src/js/tabs/receiver_msp.js +++ b/src/js/tabs/receiver_msp.js @@ -1,4 +1,5 @@ -"use strict"; +import windowWatcherUtil from "../utils/window_watchers"; +import { i18n } from "../localization"; const css_dark = [ '/css/dark-theme.css', @@ -42,8 +43,9 @@ let gimbalElems; let sliderElems; let enableTX = false; +// NOTE: import should be enough right? // This is a hack to get the i18n var of the parent, but the localizePage not works -const i18n = opener.i18n; +// const i18n = opener.i18n; const watchers = { darkTheme: (val) => { diff --git a/src/js/tabs/sensors.js b/src/js/tabs/sensors.js index f3b9b66cb0..7d794ea02b 100644 --- a/src/js/tabs/sensors.js +++ b/src/js/tabs/sensors.js @@ -1,8 +1,11 @@ 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"; +import serial from "../serial"; const sensors = {}; sensors.initialize = function (callback) { diff --git a/src/js/tabs/servos.js b/src/js/tabs/servos.js index 497fa4a8ef..25a593dbf1 100644 --- a/src/js/tabs/servos.js +++ b/src/js/tabs/servos.js @@ -2,6 +2,9 @@ import { i18n } from "../localization"; import GUI from '../gui'; 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) { @@ -137,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 ca602494a4..7e6cd556ab 100644 --- a/src/js/tabs/setup.js +++ b/src/js/tabs/setup.js @@ -1,9 +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, @@ -34,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) { @@ -109,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(); }); @@ -117,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(); @@ -132,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(); @@ -159,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 2a0afb38f0..ef9c2fd07a 100644 --- a/src/js/tabs/setup_osd.js +++ b/src/js/tabs/setup_osd.js @@ -1,5 +1,8 @@ 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 = { }; @@ -35,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 8217473541..247461a35a 100644 --- a/src/js/tabs/transponder.js +++ b/src/js/tabs/transponder.js @@ -3,6 +3,9 @@ import GUI from '../gui'; import { reinitializeConnection } from "../serial_backend"; 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, @@ -300,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); @@ -312,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 0a807a7cfd..a44d71a768 100644 --- a/src/js/tabs/vtx.js +++ b/src/js/tabs/vtx.js @@ -5,6 +5,11 @@ import { tracking } from "../Analytics"; import { mspHelper } from "../msp/MSPHelper"; import FC from '../fc'; import { VtxDeviceTypes } from '../utils/VtxDeviceStatus/VtxDeviceStatus'; +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, @@ -639,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() { @@ -652,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); @@ -662,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')); }); }); } @@ -690,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() { @@ -704,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); @@ -714,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')); }); }); } @@ -756,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')); } }; @@ -777,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')); }); }); } @@ -806,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')); } } @@ -887,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 0000000000..293352ed31 --- /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/js/utils/EscProtocols.js b/src/js/utils/EscProtocols.js index 95c41be6ac..07d2beb6c7 100644 --- a/src/js/utils/EscProtocols.js +++ b/src/js/utils/EscProtocols.js @@ -1,4 +1,4 @@ -'use strict'; +import { API_VERSION_1_42, API_VERSION_1_43 } from '../data_storage'; class EscProtocols { @@ -71,3 +71,5 @@ class EscProtocols } + +export default EscProtocols; diff --git a/src/js/utils/VtxDeviceStatus/VtxDeviceStatusFactory.js b/src/js/utils/VtxDeviceStatus/VtxDeviceStatusFactory.js index 4a001ceaf9..30aaacba68 100644 --- a/src/js/utils/VtxDeviceStatus/VtxDeviceStatusFactory.js +++ b/src/js/utils/VtxDeviceStatus/VtxDeviceStatusFactory.js @@ -1,3 +1,5 @@ +import VtxDeviceStatus from './VtxDeviceStatus'; + const vtxDeviceStatusFactory = { _vtxDeviceStatusClasses: [], diff --git a/src/js/utils/common.js b/src/js/utils/common.js index f2d7a780eb..b8788a3d4c 100644 --- a/src/js/utils/common.js +++ b/src/js/utils/common.js @@ -1,4 +1,6 @@ import semver from "semver"; +import { mixerList } from "../model"; +import CONFIGURATOR from "../data_storage"; export function millitime() { return new Date().getTime(); diff --git a/src/js/utils/window_watchers.js b/src/js/utils/window_watchers.js index df820d003f..80e0dee805 100644 --- a/src/js/utils/window_watchers.js +++ b/src/js/utils/window_watchers.js @@ -1,5 +1,3 @@ -'use strict'; - /* This utility is intended to communicate between chrome windows. One window could watch passed values from another window and react to them. @@ -57,3 +55,5 @@ windowWatcherUtil.passValue = function(windows, key, val) { applyBinding(windows, key, val); } }; + +export default windowWatcherUtil; diff --git a/src/main.html b/src/main.html index 2ce0c2a05f..c593f9bbec 100644 --- a/src/main.html +++ b/src/main.html @@ -78,34 +78,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - +