Skip to content

Commit

Permalink
Serial backend modules (#3192)
Browse files Browse the repository at this point in the history
  • Loading branch information
chmelevskij committed Jan 8, 2023
1 parent e64873a commit 4582f4d
Show file tree
Hide file tree
Showing 35 changed files with 122 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MotorOutputReorderConfig from "./MotorOutputReorderingConfig";
import MotorOutputReorderCanvas from "./MotorOutputReorderingCanvas";
import { mspHelper } from "../../js/msp/MSPHelper";

export default class MotorOutputReorderComponent
{
Expand Down
1 change: 1 addition & 0 deletions src/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BatteryLegend from "./quad-status/BatteryLegend.vue";
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';

// Most of the global objects can go here at first.
// It's a bit of overkill for simple components,
Expand Down
4 changes: 3 additions & 1 deletion src/js/Beepers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import { bit_check, bit_clear, bit_set } from './serial_backend';

class Beepers {
constructor(config, supportedConditions) {
Expand Down Expand Up @@ -105,3 +105,5 @@ class Beepers {
}
}
}

export default Beepers;
4 changes: 3 additions & 1 deletion src/js/Features.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import { bit_check, bit_set, bit_clear } from "./serial_backend";

const Features = function (config) {
const self = this;
Expand Down Expand Up @@ -198,3 +198,5 @@ Features.prototype.updateData = function (featureElement) {
}
}
};

export default Features;
6 changes: 5 additions & 1 deletion src/js/VirtualFC.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
import Features from "./Features";
import Beepers from "./Beepers";
import FC from "./fc";

const VirtualFC = {
// these values are manufactured to unlock all the functionality of the configurator, they dont represent actual hardware
Expand Down Expand Up @@ -215,3 +217,5 @@ const VirtualFC = {
};
},
};

export default VirtualFC;
12 changes: 9 additions & 3 deletions src/js/backup_restore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use strict';
import { sensor_status, update_dataflash_global, reinitializeConnection } from "./serial_backend";
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";

// 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
function configuration_backup(callback) {
export function configuration_backup(callback) {
let activeProfile = null;

let version = CONFIGURATOR.version;
Expand Down Expand Up @@ -245,7 +251,7 @@ function configuration_backup(callback) {

}

function configuration_restore(callback) {
export function configuration_restore(callback) {
let chosenFileEntry = null;

const accepts = [{
Expand Down
6 changes: 5 additions & 1 deletion src/js/fc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import { bit_check } from "./serial_backend";

const INITIAL_CONFIG = {
apiVersion: "0.0.0",
Expand Down Expand Up @@ -901,3 +901,7 @@ const FC = {
QUICKRATES: 4,
},
};

// temp binding to global scope
window.FC = FC;
export default FC;
5 changes: 5 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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';

$(document).ready(function () {

Expand Down
5 changes: 4 additions & 1 deletion src/js/msp/MSPConnector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import MspHelper from "./MSPHelper";
import { read_serial } from "../serial_backend";

const MSPConnectorImpl = function () {
this.baud = undefined;
Expand Down Expand Up @@ -74,3 +75,5 @@ MSPConnectorImpl.prototype.disconnect = function(onDisconnectCallback) {

MSP.disconnect_cleanup();
};

export default MSPConnectorImpl;
16 changes: 14 additions & 2 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
'use strict';
// NOTE: this is a circular dependency, needs investigating
import { bit_check, sensor_status, bit_set, update_dataflash_global } from "../serial_backend";
import { i18n } from "../localization";
import GUI from "../gui";
import FC from "../fc";
import semver from 'semver';

// Used for LED_STRIP
const ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order
const ledFunctionLetters = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b', 'l']; // in LSB bit order
const ledBaseFunctionLetters = ['c', 'f', 'a', 'l', 's', 'g', 'r']; // in LSB bit
let ledOverlayLetters = ['t', 'o', 'b', 'v', 'i', 'w']; // in LSB bit

Expand Down Expand Up @@ -2641,3 +2645,11 @@ 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
// to modules and every usage of this can create own
// instance or re-use existing where needed.
window.mspHelper = mspHelper = new MspHelper();
export { mspHelper };
export default MspHelper;
4 changes: 3 additions & 1 deletion src/js/protocols/stm32.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
popular choices - 921600, 460800, 256000, 230400, 153600, 128000, 115200, 57600, 38400, 28800, 19200
*/
'use strict';
import MSPConnectorImpl from "../msp/MSPConnector";
import { bit_check } from "../serial_backend";

const STM32_protocol = function () {
this.baud = null;
Expand Down Expand Up @@ -881,3 +882,4 @@ STM32_protocol.prototype.cleanup = function () {

// initialize object
const STM32 = new STM32_protocol();
export default STM32;
31 changes: 17 additions & 14 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
'use strict';
import GUI from "./gui";
import { i18n } from "./localization";
// NOTE: this is a circular dependency, needs investigating
import MspHelper from "./msp/MSPHelper";
import Features from "./Features";
import VirtualFC from "./VirtualFC";
import Beepers from "./Beepers";
import FC from "./fc";

let mspHelper;
let connectionTimestamp;
let clicks = false;

function initializeSerialBackend() {
export function initializeSerialBackend() {
GUI.updateManualPortVisibility = function() {
const selected_port = $('div#port-picker #port option:selected');
if (selected_port.data().isManual) {
Expand Down Expand Up @@ -587,7 +594,7 @@ function onClosed(result) {
CONFIGURATOR.cliEngineActive = false;
}

function read_serial(info) {
export function read_serial(info) {
if (CONFIGURATOR.cliActive) {
MSP.clearListeners();
MSP.disconnect_cleanup();
Expand All @@ -599,7 +606,7 @@ function read_serial(info) {
}
}

function sensor_status(sensors_detected) {
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
Expand Down Expand Up @@ -665,7 +672,7 @@ function sensor_status(sensors_detected) {
}
}

function have_sensor(sensors_detected, sensor_code) {
export function have_sensor(sensors_detected, sensor_code) {
switch(sensor_code) {
case 'acc':
return bit_check(sensors_detected, 0);
Expand Down Expand Up @@ -746,23 +753,19 @@ async function update_live_status() {
}
}

function specificByte(num, pos) {
return 0x000000FF & (num >> (8 * pos));
}

function bit_check(num, bit) {
export function bit_check(num, bit) {
return ((num >> bit) % 2 != 0);
}

function bit_set(num, bit) {
export function bit_set(num, bit) {
return num | 1 << bit;
}

function bit_clear(num, bit) {
export function bit_clear(num, bit) {
return num & ~(1 << bit);
}

function update_dataflash_global() {
export function update_dataflash_global() {
function formatFilesize(bytes) {
if (bytes < 1024) {
return `${bytes}B`;
Expand Down Expand Up @@ -805,7 +808,7 @@ function update_dataflash_global() {
}
}

function reinitializeConnection(callback) {
export function reinitializeConnection(callback) {

// Close connection gracefully if it still exists.
const previousTimeStamp = connectionTimestamp;
Expand Down
1 change: 1 addition & 0 deletions src/js/tabs/adjustments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { i18n } from '../localization';
import GUI from '../gui';
import { mspHelper } from '../msp/MSPHelper';

const adjustments = {};

Expand Down
2 changes: 2 additions & 0 deletions src/js/tabs/auxiliary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { i18n } from '../localization';
import GUI from '../gui';
import { get as getConfig, set as setConfig } from '../ConfigStorage';
import { bit_check } from '../serial_backend';
import { mspHelper } from '../msp/MSPHelper';

const auxiliary = {};

Expand Down
1 change: 1 addition & 0 deletions src/js/tabs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Clipboard from "../Clipboard";
import GUI from '../gui';
import BuildApi from '../BuildApi';
import { tracking } from '../Analytics';
import { reinitializeConnection } from "../serial_backend";

const cli = {
lineDelayMs: 15,
Expand Down
2 changes: 2 additions & 0 deletions src/js/tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import semver from 'semver';
import { i18n } from '../localization';
import GUI from '../gui';
import { tracking } from "../Analytics";
import { reinitializeConnection } from '../serial_backend';
import { mspHelper } from '../msp/MSPHelper';

const configuration = {
analyticsChanges: {},
Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/failsafe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { reinitializeConnection } from "../serial_backend";
import { mspHelper } from "../msp/MSPHelper";


const failsafe = {};

Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { get as getStorage, set as setStorage } from '../SessionStorage';
import BuildApi from '../BuildApi';
import ConfigInserter from "../ConfigInserter.js";
import { tracking } from "../Analytics";
import MspHelper from '../msp/MSPHelper';
import STM32 from '../protocols/stm32';
import FC from '../fc';

const firmware_flasher = {
targets: null,
Expand Down
2 changes: 2 additions & 0 deletions src/js/tabs/gps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { have_sensor } from "../serial_backend";
import FC from '../fc';

const gps = {};
gps.initialize = function (callback) {
Expand Down
2 changes: 2 additions & 0 deletions src/js/tabs/led_strip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { mspHelper } from "../msp/MSPHelper";
import FC from "../fc";

const led_strip = {
wireMode: false,
Expand Down
1 change: 1 addition & 0 deletions src/js/tabs/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { millitime } from '../utils/common.js';
import GUI from '../gui';
import { i18n } from '../localization';
import { get as getConfig, set as setConfig } from '../ConfigStorage';
import FC from '../fc.js';

const logging = {};
logging.initialize = function (callback) {
Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/motors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import MotorOutputReorderConfig from "../../components/MotorOutputReordering/Mot
import MotorOutputReorderComponent from "../../components/MotorOutputReordering/MotorOutputReorderingComponent";
import EscDshotDirectionComponent from "../../components/EscDshotDirection/EscDshotDirectionComponent";
import { tracking } from "../Analytics";
import { bit_check, reinitializeConnection } from "../serial_backend";
import { mspHelper } from "../msp/MSPHelper";
import FC from "../fc";

const motors = {
previousDshotBidir: null,
Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/onboard_logging.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { tracking } from "../Analytics";
import { reinitializeConnection } from "../serial_backend";
import { mspHelper } from "../msp/MSPHelper";
import FC from "../fc";

let sdcardTimer;

Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/osd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { tracking } from "../Analytics";
import { bit_check } from "../serial_backend";
import VirtualFC from "../VirtualFC";
import FC from "../fc";

const FONT = {};
const SYM = {};
Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/pid_tuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ 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 { mspHelper } from "../msp/MSPHelper";
import FC from "../fc";

const pid_tuning = {
RATE_PROFILE_MASK: 128,
Expand Down
3 changes: 3 additions & 0 deletions src/js/tabs/ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import semver from 'semver';
import { i18n } from "../localization";
import GUI from '../gui';
import { tracking } from "../Analytics";
import { reinitializeConnection } from '../serial_backend';
import { mspHelper } from '../msp/MSPHelper';
import FC from '../fc';

const ports = {
analyticsChanges: {},
Expand Down
2 changes: 2 additions & 0 deletions src/js/tabs/power.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { i18n } from '../localization';
import GUI from '../gui';
import { tracking } from "../Analytics";
import { mspHelper } from '../msp/MSPHelper';
import FC from '../fc';

const power = {
supported: false,
Expand Down
4 changes: 4 additions & 0 deletions src/js/tabs/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ 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 { mspHelper } from "../msp/MSPHelper";
import FC from "../fc";

import CryptoES from 'crypto-es';

const receiver = {
Expand Down
2 changes: 2 additions & 0 deletions src/js/tabs/sensors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { get as getConfig, set as setConfig } from '../ConfigStorage';
import { have_sensor } from "../serial_backend";
import FC from "../fc";

const sensors = {};
sensors.initialize = function (callback) {
Expand Down

0 comments on commit 4582f4d

Please sign in to comment.