Serial backend modules (#3192)

10.9-maintenance
Tomas Chmelevskij 2023-01-08 07:13:20 +01:00 committed by GitHub
parent e64873aec9
commit 4582f4d39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 122 additions and 34 deletions

View File

@ -1,5 +1,6 @@
import MotorOutputReorderConfig from "./MotorOutputReorderingConfig";
import MotorOutputReorderCanvas from "./MotorOutputReorderingCanvas";
import { mspHelper } from "../../js/msp/MSPHelper";
export default class MotorOutputReorderComponent
{

View File

@ -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,

View File

@ -1,4 +1,4 @@
'use strict';
import { bit_check, bit_clear, bit_set } from './serial_backend';
class Beepers {
constructor(config, supportedConditions) {
@ -105,3 +105,5 @@ class Beepers {
}
}
}
export default Beepers;

View File

@ -1,4 +1,4 @@
'use strict';
import { bit_check, bit_set, bit_clear } from "./serial_backend";
const Features = function (config) {
const self = this;
@ -198,3 +198,5 @@ Features.prototype.updateData = function (featureElement) {
}
}
};
export default Features;

View File

@ -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
@ -215,3 +217,5 @@ const VirtualFC = {
};
},
};
export default VirtualFC;

View File

@ -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;
@ -245,7 +251,7 @@ function configuration_backup(callback) {
}
function configuration_restore(callback) {
export function configuration_restore(callback) {
let chosenFileEntry = null;
const accepts = [{

View File

@ -1,4 +1,4 @@
'use strict';
import { bit_check } from "./serial_backend";
const INITIAL_CONFIG = {
apiVersion: "0.0.0",
@ -901,3 +901,7 @@ const FC = {
QUICKRATES: 4,
},
};
// temp binding to global scope
window.FC = FC;
export default FC;

View File

@ -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 () {

View File

@ -1,4 +1,5 @@
'use strict';
import MspHelper from "./MSPHelper";
import { read_serial } from "../serial_backend";
const MSPConnectorImpl = function () {
this.baud = undefined;
@ -74,3 +75,5 @@ MSPConnectorImpl.prototype.disconnect = function(onDisconnectCallback) {
MSP.disconnect_cleanup();
};
export default MSPConnectorImpl;

View File

@ -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
@ -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;

View File

@ -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;
@ -881,3 +882,4 @@ STM32_protocol.prototype.cleanup = function () {
// initialize object
const STM32 = new STM32_protocol();
export default STM32;

View File

@ -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) {
@ -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();
@ -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
@ -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);
@ -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`;
@ -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;

View File

@ -1,5 +1,6 @@
import { i18n } from '../localization';
import GUI from '../gui';
import { mspHelper } from '../msp/MSPHelper';
const adjustments = {};

View File

@ -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 = {};

View File

@ -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,

View File

@ -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: {},

View File

@ -1,5 +1,8 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { reinitializeConnection } from "../serial_backend";
import { mspHelper } from "../msp/MSPHelper";
const failsafe = {};

View File

@ -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,

View File

@ -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) {

View File

@ -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,

View File

@ -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) {

View File

@ -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,

View File

@ -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;

View File

@ -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 = {};

View File

@ -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,

View File

@ -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: {},

View File

@ -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,

View File

@ -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 = {

View File

@ -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) {

View File

@ -1,5 +1,7 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { mspHelper } from "../msp/MSPHelper";
import FC from "../fc";
const servos = {};
servos.initialize = function (callback) {

View File

@ -1,5 +1,9 @@
import { i18n } from '../localization';
import GUI from '../gui';
import { configuration_backup, configuration_restore } from '../backup_restore';
import { have_sensor } from '../serial_backend';
import { mspHelper } from '../msp/MSPHelper';
import FC from '../fc';
const setup = {
yaw_fix: 0.0,

View File

@ -1,5 +1,8 @@
import { i18n } from "../localization";
import GUI from '../gui';
import { reinitializeConnection } from "../serial_backend";
import { mspHelper } from '../msp/MSPHelper';
import FC from "../fc";
const transponder = {
available: false,

View File

@ -2,6 +2,8 @@ import { i18n } from "../localization";
import Clipboard from "../Clipboard";
import GUI from '../gui';
import { tracking } from "../Analytics";
import { mspHelper } from "../msp/MSPHelper";
import FC from '../fc';
const vtx = {
supported: false,

View File

@ -86,8 +86,6 @@
<script type="text/javascript" src="./js/utils/VtxDeviceStatus/SmartAudioDeviceStatus.js"></script>
<script type="text/javascript" src="./js/utils/VtxDeviceStatus/Rtc6705DeviceStatus.js"></script>
<script type="text/javascript" src="./js/data_storage.js"></script>
<script type="text/javascript" src="./js/fc.js"></script>
<script type="text/javascript" src="./js/VirtualFC.js"></script>
<script type="text/javascript" src="./js/port_handler.js"></script>
<script type="text/javascript" src="./js/port_usage.js"></script>
<script type="text/javascript" src="./js/serial.js"></script>
@ -95,19 +93,12 @@
<script type="text/javascript" src="./js/huffman.js"></script>
<script type="text/javascript" src="./js/default_huffman_tree.js"></script>
<script type="text/javascript" src="./js/model.js"></script>
<script type="text/javascript" src="./js/serial_backend.js"></script>
<script type="text/javascript" src="./js/msp/MSPCodes.js"></script>
<script type="text/javascript" src="./js/msp/MSPConnector.js"></script>
<script type="text/javascript" src="./js/msp.js"></script>
<script type="text/javascript" src="./js/msp/MSPHelper.js"></script>
<script type="text/javascript" src="./js/backup_restore.js"></script>
<script type="text/javascript" src="./js/peripherals.js"></script>
<script type="text/javascript" src="./js/protocols/stm32.js"></script>
<script type="text/javascript" src="./js/protocols/stm32usbdfu.js"></script>
<script type="text/javascript" src="./js/boards.js"></script>
<script type="text/javascript" src="./js/RateCurve.js"></script>
<script type="text/javascript" src="./js/Features.js"></script>
<script type="text/javascript" src="./js/Beepers.js"></script>
<script type="text/javascript" src="./js/GitHubApi.js"></script>
<script type="module" src="./js/main.js"></script>
<script type="text/javascript" src="./js/LogoManager.js"></script>

View File

@ -14,6 +14,7 @@ module.exports = function(config) {
'./node_modules/jquery-textcomplete/dist/jquery.textcomplete.min.js',
'./node_modules/bluebird/js/browser/bluebird.min.js',
'./node_modules/jbox/dist/jBox.min.js',
'./src/js/msp.js',
'./src/js/serial.js',
'./src/js/data_storage.js',
{ pattern: './src/js/localization.js', type: 'module', watched: false },