Skip to content

Commit

Permalink
Refactor msp to modules (#3214)
Browse files Browse the repository at this point in the history
* feat: refactor everything to modules

* fix: a lot of circular deps fixes

* feat: use vitest instead of karma
  • Loading branch information
chmelevskij authored Jan 14, 2023
1 parent 654dca2 commit c086395
Show file tree
Hide file tree
Showing 82 changed files with 1,662 additions and 1,378 deletions.
19 changes: 4 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/components/EscDshotDirection/EscDshotCommandQueue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import MSP from '../../js/msp.js';

class EscDshotCommandQueue
{
constructor (intervalMs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)));
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/js/Beepers.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions src/js/BuildApi.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
7 changes: 6 additions & 1 deletion src/js/CliAutoComplete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
import GUI from './gui';
import CONFIGURATOR from './data_storage';
import FC from './fc';

/**
* Encapsulates the AutoComplete logic
Expand Down Expand Up @@ -575,3 +577,6 @@ CliAutoComplete._initTextcomplete = function() {
}),
]);
};

window.CliAutoComplete = CliAutoComplete;
export default CliAutoComplete;
5 changes: 4 additions & 1 deletion src/js/DarkTheme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import GUI from "./gui";
import windowWatcherUtil from "./utils/window_watchers";

const css_dark = [
'./css/dark-theme.css',
Expand Down Expand Up @@ -63,3 +64,5 @@ DarkTheme.applyDark = function () {
DarkTheme.applyNormal = function () {
css_dark.forEach((el) => $(`link[href="${el}"]`).prop('disabled', true));
};

export default DarkTheme;
3 changes: 2 additions & 1 deletion src/js/Features.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/js/GitHubApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

// NOTE: this files seems to be unused anywhere
const GitHubApi = function ()
{
const self = this;
Expand All @@ -25,3 +24,5 @@ GitHubApi.prototype.getFileLastCommitInfo = function (project, branch, filename,
callback(result);
});
};

export default GitHubApi;
13 changes: 5 additions & 8 deletions src/js/LogoManager.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
}));
Expand All @@ -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],
Expand Down Expand Up @@ -288,6 +287,4 @@ LogoManager.drawPreview = function () {
}
};

window.LogoManager = LogoManager;

})();
export default LogoManager;
5 changes: 4 additions & 1 deletion src/js/RateCurve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import FC from "./fc";
import { API_VERSION_1_43 } from "./data_storage";

const minRc = 1000;
const midRc = 1500;
Expand Down Expand Up @@ -277,3 +278,5 @@ RateCurve.prototype.draw = function (rate, rcRate, rcExpo, superExpoActive, dead
}
}
};

export default RateCurve;
7 changes: 6 additions & 1 deletion src/js/TuningSliders.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -824,3 +827,5 @@ TuningSliders.resetDTermFilterSlider = function() {
this.calculateNewDTermFilters();
this.updateFilterSlidersDisplay();
};

export default TuningSliders;
2 changes: 2 additions & 0 deletions src/js/VirtualFC.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit c086395

Please sign in to comment.