1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-24 16:55:22 +03:00

Convert to CommonJS Modules Part 3

This commit is contained in:
Scavanger 2024-04-18 15:39:19 -03:00
parent ca13eefa1b
commit 06a4d8b0c8
74 changed files with 1949 additions and 10259 deletions

View file

@ -1,5 +1,19 @@
'use strict';
const path = require('path');
const Store = require('electron-store');
const store = new Store();
const MSPCodes = require('./../js/msp/MSPCodes');
const MSP = require('./../js/msp');
const mspQueue = require('./../js/serial_queue');
const { GUI, TABS } = require('./../js/gui');
const FC = require('./../js/fc');
const CONFIGURATOR = require('./../js/data_storage');
const interval = require('./../js/intervals');
const i18n = require('./../js/localization');
const BitHelper = require('./../js/bitHelper');
TABS.sensors = {};
TABS.sensors.initialize = function (callback) {
var self = this;
@ -10,14 +24,14 @@ TABS.sensors.initialize = function (callback) {
function initSensorData(){
for (var i = 0; i < 3; i++) {
SENSOR_DATA.accelerometer[i] = 0;
SENSOR_DATA.gyroscope[i] = 0;
SENSOR_DATA.magnetometer[i] = 0;
SENSOR_DATA.sonar = 0;
SENSOR_DATA.air_speed = 0;
SENSOR_DATA.altitude = 0;
SENSOR_DATA.temperature[i] = 0;
SENSOR_DATA.debug[i] = 0;
FC.SENSOR_DATA.accelerometer[i] = 0;
FC.SENSOR_DATA.gyroscope[i] = 0;
FC.SENSOR_DATA.magnetometer[i] = 0;
FC.SENSOR_DATA.sonar = 0;
FC.SENSOR_DATA.air_speed = 0;
FC.SENSOR_DATA.altitude = 0;
FC.SENSOR_DATA.temperature[i] = 0;
FC.SENSOR_DATA.debug[i] = 0;
}
}
@ -197,24 +211,24 @@ TABS.sensors.initialize = function (callback) {
}
}
GUI.load(path.join(__dirname, "tabs/sensors.html"), function load_html() {
GUI.load(path.join(__dirname, "sensors.html"), function load_html() {
// translate to user-selected language
i18n.localize();;
// disable graphs for sensors that are missing
var checkboxes = $('.tab-sensors .info .checkboxes input');
if (!bit_check(CONFIG.activeSensors, 2)) { // mag
if (!BitHelper.bit_check(FC.CONFIG.activeSensors, 2)) { // mag
checkboxes.eq(2).prop('disabled', true);
}
if (!bit_check(CONFIG.activeSensors, 4)) { // sonar
if (!BitHelper.bit_check(FC.CONFIG.activeSensors, 4)) { // sonar
checkboxes.eq(4).prop('disabled', true);
}
if (!bit_check(CONFIG.activeSensors, 6)) { // airspeed
if (!BitHelper.bit_check(FC.CONFIG.activeSensors, 6)) { // airspeed
checkboxes.eq(5).prop('disabled', true);
}
if (!bit_check(CONFIG.activeSensors, 7)) {
if (!BitHelper.bit_check(FC.CONFIG.activeSensors, 7)) {
checkboxes.eq(6).prop('disabled', true);
}
@ -254,21 +268,21 @@ TABS.sensors.initialize = function (callback) {
checkboxes.push($(this).prop('checked'));
});
$('.tab-sensors .rate select:first').trigger('change');
startPolling();
store.set('graphs_enabled', checkboxes);
});
store.get('graphs_enabled', function (result) {
if (result.graphs_enabled) {
var checkboxes = $('.tab-sensors .info .checkboxes input');
for (var i = 0; i < result.graphs_enabled.length; i++) {
checkboxes.eq(i).not(':disabled').prop('checked', result.graphs_enabled[i]).trigger('change');
}
} else {
$('.tab-sensors .info input:lt(4):not(:disabled)').prop('checked', true).trigger('change');
var graphs_enabled = store.get('graphs_enabled', false);
if (graphs_enabled) {
var checkboxes = $('.tab-sensors .info .checkboxes input');
for (var i = 0; i < graphs_enabled.length; i++) {
checkboxes.eq(i).not(':disabled').prop('checked', graphs_enabled[i]).trigger('change');
}
});
} else {
$('.tab-sensors .info input:lt(4):not(:disabled)').prop('checked', true).trigger('change');
}
// Always start with default/empty sensor data array, clean slate all
initSensorData();
@ -372,14 +386,18 @@ TABS.sensors.initialize = function (callback) {
$('.tab-sensors select[name="debug_refresh_rate"]').val(sensor_settings.rates.debug);
// start polling data by triggering refresh rate change event
$('.tab-sensors .rate select:first').trigger('change');
startPolling();
} else {
// start polling immediatly (as there is no configuration saved in the storage)
$('.tab-sensors .rate select:first').trigger('change');
startPolling();
}
$('.tab-sensors .rate select, .tab-sensors .scale select').on('change', function () {
startPolling();
});
function startPolling() {
// if any of the select fields change value, all of the select values are grabbed
// and timers are re-initialized with the new settings
var rates = {
@ -419,16 +437,16 @@ TABS.sensors.initialize = function (callback) {
});
// timer initialization
helper.interval.killAll(['status_pull', 'global_data_refresh', 'msp-load-update']);
interval.killAll(['status_pull', 'global_data_refresh', 'msp-load-update']);
// data pulling timers
if (checkboxes[0] || checkboxes[1] || checkboxes[2]) {
helper.interval.add('IMU_pull', function () {
interval.add('IMU_pull', function () {
/*
* Enable balancer
*/
if (helper.mspQueue.shouldDrop()) {
if (mspQueue.shouldDrop()) {
update_imu_graphs();
return;
}
@ -438,12 +456,12 @@ TABS.sensors.initialize = function (callback) {
}
if (checkboxes[3]) {
helper.interval.add('altitude_pull', function altitude_data_pull() {
interval.add('altitude_pull', function altitude_data_pull() {
/*
* Enable balancer
*/
if (helper.mspQueue.shouldDrop()) {
if (mspQueue.shouldDrop()) {
update_altitude_graph();
return;
}
@ -453,12 +471,12 @@ TABS.sensors.initialize = function (callback) {
}
if (checkboxes[4]) {
helper.interval.add('sonar_pull', function sonar_data_pull() {
interval.add('sonar_pull', function sonar_data_pull() {
/*
* Enable balancer
*/
if (helper.mspQueue.shouldDrop()) {
if (mspQueue.shouldDrop()) {
update_sonar_graphs();
return;
}
@ -468,12 +486,12 @@ TABS.sensors.initialize = function (callback) {
}
if (checkboxes[5]) {
helper.interval.add('airspeed_pull', function airspeed_data_pull() {
interval.add('airspeed_pull', function airspeed_data_pull() {
/*
* Enable balancer
*/
if (helper.mspQueue.shouldDrop()) {
if (mspQueue.shouldDrop()) {
update_airspeed_graphs();
return;
}
@ -483,12 +501,12 @@ TABS.sensors.initialize = function (callback) {
}
if (checkboxes[6]) {
helper.interval.add('temperature_pull', function temperature_data_pull() {
interval.add('temperature_pull', function temperature_data_pull() {
/*
* Enable balancer
*/
if (helper.mspQueue.shouldDrop()) {
if (mspQueue.shouldDrop()) {
update_temperature_graphs();
return;
}
@ -498,12 +516,12 @@ TABS.sensors.initialize = function (callback) {
}
if (checkboxes[7]) {
helper.interval.add('debug_pull', function debug_data_pull() {
interval.add('debug_pull', function debug_data_pull() {
/*
* Enable balancer
*/
if (helper.mspQueue.shouldDrop()) {
if (mspQueue.shouldDrop()) {
update_debug_graphs();
return;
}
@ -516,65 +534,65 @@ TABS.sensors.initialize = function (callback) {
if (checkboxes[0]) {
updateGraphHelperSize(gyroHelpers);
samples_gyro_i = addSampleToData(gyro_data, samples_gyro_i, SENSOR_DATA.gyroscope);
samples_gyro_i = addSampleToData(gyro_data, samples_gyro_i, FC.SENSOR_DATA.gyroscope);
drawGraph(gyroHelpers, gyro_data, samples_gyro_i);
raw_data_text_ements.x[0].text(SENSOR_DATA.gyroscope[0].toFixed(2));
raw_data_text_ements.y[0].text(SENSOR_DATA.gyroscope[1].toFixed(2));
raw_data_text_ements.z[0].text(SENSOR_DATA.gyroscope[2].toFixed(2));
raw_data_text_ements.x[0].text(FC.SENSOR_DATA.gyroscope[0].toFixed(2));
raw_data_text_ements.y[0].text(FC.SENSOR_DATA.gyroscope[1].toFixed(2));
raw_data_text_ements.z[0].text(FC.SENSOR_DATA.gyroscope[2].toFixed(2));
}
if (checkboxes[1]) {
updateGraphHelperSize(accelHelpers);
samples_accel_i = addSampleToData(accel_data, samples_accel_i, SENSOR_DATA.accelerometer);
samples_accel_i = addSampleToData(accel_data, samples_accel_i, FC.SENSOR_DATA.accelerometer);
drawGraph(accelHelpers, accel_data, samples_accel_i);
raw_data_text_ements.x[1].text(SENSOR_DATA.accelerometer[0].toFixed(2));
raw_data_text_ements.y[1].text(SENSOR_DATA.accelerometer[1].toFixed(2));
raw_data_text_ements.z[1].text(SENSOR_DATA.accelerometer[2].toFixed(2));
raw_data_text_ements.x[1].text(FC.SENSOR_DATA.accelerometer[0].toFixed(2));
raw_data_text_ements.y[1].text(FC.SENSOR_DATA.accelerometer[1].toFixed(2));
raw_data_text_ements.z[1].text(FC.SENSOR_DATA.accelerometer[2].toFixed(2));
}
if (checkboxes[2]) {
updateGraphHelperSize(magHelpers);
samples_mag_i = addSampleToData(mag_data, samples_mag_i, SENSOR_DATA.magnetometer);
samples_mag_i = addSampleToData(mag_data, samples_mag_i, FC.SENSOR_DATA.magnetometer);
drawGraph(magHelpers, mag_data, samples_mag_i);
raw_data_text_ements.x[2].text(SENSOR_DATA.magnetometer[0].toFixed(2));
raw_data_text_ements.y[2].text(SENSOR_DATA.magnetometer[1].toFixed(2));
raw_data_text_ements.z[2].text(SENSOR_DATA.magnetometer[2].toFixed(2));
raw_data_text_ements.x[2].text(FC.SENSOR_DATA.magnetometer[0].toFixed(2));
raw_data_text_ements.y[2].text(FC.SENSOR_DATA.magnetometer[1].toFixed(2));
raw_data_text_ements.z[2].text(FC.SENSOR_DATA.magnetometer[2].toFixed(2));
}
}
function update_altitude_graph() {
updateGraphHelperSize(altitudeHelpers);
samples_altitude_i = addSampleToData(altitude_data, samples_altitude_i, [SENSOR_DATA.altitude, SENSOR_DATA.barometer]);
samples_altitude_i = addSampleToData(altitude_data, samples_altitude_i, [FC.SENSOR_DATA.altitude, FC.SENSOR_DATA.barometer]);
drawGraph(altitudeHelpers, altitude_data, samples_altitude_i);
raw_data_text_ements.x[3].text(SENSOR_DATA.altitude.toFixed(2));
raw_data_text_ements.y[3].text(SENSOR_DATA.barometer.toFixed(2));
raw_data_text_ements.x[3].text(FC.SENSOR_DATA.altitude.toFixed(2));
raw_data_text_ements.y[3].text(FC.SENSOR_DATA.barometer.toFixed(2));
}
function update_sonar_graphs() {
updateGraphHelperSize(sonarHelpers);
samples_sonar_i = addSampleToData(sonar_data, samples_sonar_i, [SENSOR_DATA.sonar]);
samples_sonar_i = addSampleToData(sonar_data, samples_sonar_i, [FC.SENSOR_DATA.sonar]);
drawGraph(sonarHelpers, sonar_data, samples_sonar_i);
raw_data_text_ements.x[4].text(SENSOR_DATA.sonar.toFixed(2));
raw_data_text_ements.x[4].text(FC.SENSOR_DATA.sonar.toFixed(2));
}
function update_airspeed_graphs() {
updateGraphHelperSize(airspeedHelpers);
samples_airspeed_i = addSampleToData(airspeed_data, samples_airspeed_i, [SENSOR_DATA.air_speed]);
samples_airspeed_i = addSampleToData(airspeed_data, samples_airspeed_i, [FC.SENSOR_DATA.air_speed]);
drawGraph(airspeedHelpers, airspeed_data, samples_airspeed_i);
raw_data_text_ements.x[5].text(SENSOR_DATA.air_speed);
raw_data_text_ements.x[5].text(FC.SENSOR_DATA.air_speed);
}
function update_temperature_graphs() {
for (var i = 0; i < 8; i++) {
updateGraphHelperSize(temperatureHelpers[i]);
addSampleToData(temperature_data[i], samples_temperature_i, [SENSOR_DATA.temperature[i]]);
addSampleToData(temperature_data[i], samples_temperature_i, [FC.SENSOR_DATA.temperature[i]]);
drawGraph(temperatureHelpers[i], temperature_data[i], samples_temperature_i);
raw_data_text_ements.x[6 + i].text(SENSOR_DATA.temperature[i]);
raw_data_text_ements.x[6 + i].text(FC.SENSOR_DATA.temperature[i]);
}
samples_temperature_i++;
}
@ -583,34 +601,19 @@ TABS.sensors.initialize = function (callback) {
for (var i = 0; i < 8; i++) {
updateGraphHelperSize(debugHelpers[i]);
addSampleToData(debug_data[i], samples_debug_i, [SENSOR_DATA.debug[i]]);
addSampleToData(debug_data[i], samples_debug_i, [FC.SENSOR_DATA.debug[i]]);
drawGraph(debugHelpers[i], debug_data[i], samples_debug_i);
raw_data_text_ements.x[6 + 8 + i].text(SENSOR_DATA.debug[i]);
raw_data_text_ements.x[6 + 8 + i].text(FC.SENSOR_DATA.debug[i]);
}
samples_debug_i++;
}
});
}
$("a.debug-trace").on('click', function () {
var windowWidth = 500;
var windowHeight = 510;
window.open("/tabs/debug_trace.html", {
id: "debug_trace",
innerBounds: {
minWidth: windowWidth, minHeight: windowHeight,
width: windowWidth, height: windowHeight,
},
alwaysOnTop: true
}, function (createdWindow) {
createdWindow.contentWindow.getDebugTrace = function () { return DEBUG_TRACE || ''; };
return true;
});
return false;
var debugWin = window.open("tabs/debug_trace.html", "receiver_msp", "width=500,height=510,menubar=no,contextIsolation=no,nodeIntegration=yes");
debugWin.window.getDebugTrace = function () { return FC.DEBUG_TRACE || ''; };
});
GUI.content_ready(callback);
});
};