Skip to content

Commit

Permalink
fix: a lot of circular deps fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chmelevskij committed Jan 10, 2023
1 parent 0e50f1f commit 4f5b5be
Show file tree
Hide file tree
Showing 49 changed files with 389 additions and 348 deletions.
Expand Up @@ -5,6 +5,7 @@ import { reinitializeConnection } from "../../js/serial_backend";
import MSP from "../../js/msp";
import MSPCodes from "../../js/msp/MSPCodes";
import FC from "../../js/fc";
import { gui_log } from "../../js/gui_log";

export default class MotorOutputReorderComponent
{
Expand Down Expand Up @@ -97,7 +98,7 @@ export default class MotorOutputReorderComponent

function reboot()
{
GUI.log(i18n.getMessage('configurationEepromSaved'));
gui_log(i18n.getMessage('configurationEepromSaved'));
GUI.tab_switch_cleanup(() => MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(TABS.motors)));
}

Expand Down
2 changes: 1 addition & 1 deletion 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) {
Expand Down
20 changes: 10 additions & 10 deletions 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";

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
1 change: 1 addition & 0 deletions src/js/CliAutoComplete.js
@@ -1,5 +1,6 @@
import GUI from './gui';
import CONFIGURATOR from './data_storage';
import FC from './fc';

/**
* Encapsulates the AutoComplete logic
Expand Down
2 changes: 1 addition & 1 deletion src/js/Features.js
@@ -1,4 +1,4 @@
import { bit_check, bit_set, bit_clear } from "./serial_backend";
import { bit_check, bit_set, bit_clear } from "./bit";
import { API_VERSION_1_44 } from './data_storage';

const Features = function (config) {
Expand Down
6 changes: 3 additions & 3 deletions src/js/LogoManager.js
@@ -1,4 +1,4 @@
import GUI from "./gui";
import { gui_log } from "./gui_log";
import { i18n } from "./localization";

/**
Expand Down Expand Up @@ -131,7 +131,7 @@ LogoManager.init = function (font, logoStartIndex) {
const constraint = this.constraints.imageSize;
if (img.width !== constraint.expectedWidth
|| img.height !== constraint.expectedHeight) {
GUI.log(i18n.getMessage("osdSetupCustomLogoImageSizeError", {
gui_log(i18n.getMessage("osdSetupCustomLogoImageSizeError", {
width: img.width,
height: img.height,
}));
Expand All @@ -157,7 +157,7 @@ LogoManager.init = function (font, logoStartIndex) {
const rgbPixel = ctx.getImageData(x, y, 1, 1).data.slice(0, 3),
colorKey = rgbPixel.join("-");
if (!this.constants.MCM_COLORMAP[colorKey]) {
GUI.log(i18n.getMessage("osdSetupCustomLogoColorMapError", {
gui_log(i18n.getMessage("osdSetupCustomLogoColorMapError", {
valueR: rgbPixel[0],
valueG: rgbPixel[1],
valueB: rgbPixel[2],
Expand Down
1 change: 1 addition & 0 deletions src/js/VirtualFC.js
@@ -1,4 +1,5 @@
import Features from "./Features";
import { i18n } from "./localization";
import Beepers from "./Beepers";
import FC from "./fc";
import CONFIGURATOR from "./data_storage";
Expand Down
39 changes: 21 additions & 18 deletions src/js/backup_restore.js
@@ -1,4 +1,6 @@
import { sensor_status, update_dataflash_global, reinitializeConnection } from "./serial_backend";
import { reinitializeConnection } from "./serial_backend";
import { update_dataflash_global } from "./update_dataflash_global";
import { sensor_status } from "./sensor_helpers.js";
import GUI from "./gui";
import Features from "./Features";
import { i18n } from "./localization";
Expand All @@ -8,6 +10,7 @@ import { mspHelper } from "./msp/MSPHelper";
import MSP from "./msp";
import MSPCodes from "./msp/MSPCodes";
import CONFIGURATOR, { API_VERSION_1_41, API_VERSION_1_45 } from "./data_storage";
import { gui_log } from './gui_log';

// code below is highly experimental, although it runs fine on latest firmware
// the data inside nested objects needs to be verified if deep copy works properly
Expand Down Expand Up @@ -308,7 +311,7 @@ export function configuration_restore(callback) {
// validate
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.BACKUP_FILE_VERSION_MIN_SUPPORTED)) {
if (!compareVersions(configuration.generatedBy, "1.14.0") && !migrate(configuration)) {
GUI.log(i18n.getMessage('backupFileUnmigratable'));
gui_log(i18n.getMessage('backupFileUnmigratable'));
return;
}
if (configuration.FEATURE_CONFIG.features._featureMask) {
Expand All @@ -321,7 +324,7 @@ export function configuration_restore(callback) {

configuration_upload(configuration, callback);
} else {
GUI.log(i18n.getMessage('backupFileIncompatible'));
gui_log(i18n.getMessage('backupFileIncompatible'));
}
}
};
Expand All @@ -341,7 +344,7 @@ export function configuration_restore(callback) {
function migrate(configuration) {
let appliedMigrationsCount = 0;
let migratedVersion = configuration.generatedBy;
GUI.log(i18n.getMessage('configMigrationFrom', [migratedVersion]));
gui_log(i18n.getMessage('configMigrationFrom', [migratedVersion]));

if (!compareVersions(migratedVersion, '0.59.1')) {

Expand All @@ -350,7 +353,7 @@ export function configuration_restore(callback) {
configuration.MISC.rssi_aux_channel = undefined;

migratedVersion = '0.59.1';
GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand All @@ -362,7 +365,7 @@ export function configuration_restore(callback) {
}

migratedVersion = '0.60.1';
GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand All @@ -377,7 +380,7 @@ export function configuration_restore(callback) {
}

migratedVersion = '0.61.0';
GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand Down Expand Up @@ -407,7 +410,7 @@ export function configuration_restore(callback) {
}

migratedVersion = '0.63.0';
GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand Down Expand Up @@ -463,7 +466,7 @@ export function configuration_restore(callback) {
ports: ports,
};

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand All @@ -483,7 +486,7 @@ export function configuration_restore(callback) {
};
}

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand Down Expand Up @@ -523,7 +526,7 @@ export function configuration_restore(callback) {

migratedVersion = '0.66.0';

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand All @@ -541,7 +544,7 @@ export function configuration_restore(callback) {
configuration.profiles[profileIndex].PID.controller = newPidControllerIndex;
}

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand All @@ -558,7 +561,7 @@ export function configuration_restore(callback) {
};
}

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand Down Expand Up @@ -625,7 +628,7 @@ export function configuration_restore(callback) {
}
}

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand All @@ -636,7 +639,7 @@ export function configuration_restore(callback) {
}
migratedVersion = '1.2.0';

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

Expand All @@ -652,12 +655,12 @@ export function configuration_restore(callback) {

migratedVersion = '1.3.1';

GUI.log(i18n.getMessage('configMigratedTo', [migratedVersion]));
gui_log(i18n.getMessage('configMigratedTo', [migratedVersion]));
appliedMigrationsCount++;
}

if (appliedMigrationsCount > 0) {
GUI.log(i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount]));
gui_log(i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount]));
}
return true;
}
Expand Down Expand Up @@ -882,7 +885,7 @@ export function configuration_restore(callback) {
}

function reboot() {
GUI.log(i18n.getMessage('eeprom_saved_ok'));
gui_log(i18n.getMessage('eeprom_saved_ok'));

GUI.tab_switch_cleanup(function() {
MSP.Promise(MSPCodes.MSP_SET_REBOOT)
Expand Down
11 changes: 11 additions & 0 deletions 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);
}
5 changes: 1 addition & 4 deletions src/js/fc.js
@@ -1,4 +1,4 @@
import { bit_check } from "./serial_backend";
import { bit_check } from "./bit";
import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45 } from './data_storage';

const INITIAL_CONFIG = {
Expand Down Expand Up @@ -162,7 +162,6 @@ const FC = {
VTX_DEVICE_STATUS: null,

resetState () {
console.log('resetting state');
// Using `Object.assign` instead of reassigning to
// trigger the updates on the Vue side
Object.assign(this.CONFIG, INITIAL_CONFIG);
Expand Down Expand Up @@ -904,6 +903,4 @@ const FC = {
},
};

// temp binding to global scope
window.FC = FC;
export default FC;
17 changes: 1 addition & 16 deletions src/js/gui.js
Expand Up @@ -243,22 +243,7 @@ class GuiControl {

return timersKilled;
}
// message = string
log(message) {
const commandLog = $('div#log');
const d = new Date();
const year = d.getFullYear();
const month = (d.getMonth() < 9) ? `0${d.getMonth() + 1}` : (d.getMonth() + 1);
const date = (d.getDate() < 10) ? `0${d.getDate()}` : d.getDate();
const hours = (d.getHours() < 10) ? `0${d.getHours()}` : d.getHours();
const minutes = (d.getMinutes() < 10) ? `0${d.getMinutes()}` : d.getMinutes();
const seconds = (d.getSeconds() < 10) ? `0${d.getSeconds()}` : d.getSeconds();
const time = `${hours}:${minutes}:${seconds}`;

const formattedDate = `${year}-${month}-${date} @${time}`;
$('div.wrapper', commandLog).append(`<p>${formattedDate} -- ${message}</p>`);
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
Expand Down
21 changes: 21 additions & 0 deletions 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(
`<p>${formattedDate} -- ${message}</p>`,
);
commandLog.scrollTop($("div.wrapper", commandLog).height());
}

0 comments on commit 4f5b5be

Please sign in to comment.