Skip to content

Commit

Permalink
Merge pull request #2068 from iNavFlight/dzikuvx-do-not-use-MSP_BOXNAMES
Browse files Browse the repository at this point in the history
Do not use MSP_BOXNAMES
  • Loading branch information
DzikuVx authored May 12, 2024
2 parents 90b8139 + cb3a7e9 commit b1f5f32
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 84 deletions.
28 changes: 20 additions & 8 deletions js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const FwApproachCollection = require('./fwApproachCollection')
const { PLATFORM } = require('./model')
const VTX = require('./vtx');
const BitHelper = require('./bitHelper');
const { FLIGHT_MODES } = require('./flightModes');


var FC = {
Expand All @@ -28,8 +29,8 @@ var FC = {
RC_MAP: null,
RC: null,
RC_tuning: null,
AUX_CONFIG: null,
AUX_CONFIG_IDS: null,
AUX_CONFIG: [],
AUX_CONFIG_IDS: [],
MODE_RANGES: null,
ADJUSTMENT_RANGES: null,
SERVO_CONFIG: null,
Expand Down Expand Up @@ -85,6 +86,7 @@ var FC = {
FEATURES: null,
RATE_DYNAMICS: null,
EZ_TUNE: null,
FLIGHT_MODES: null,

restartRequired: false,
MAX_SERVO_RATE: 125,
Expand Down Expand Up @@ -198,8 +200,16 @@ var FC = {
manual_yaw_rate: 0,
};

this.AUX_CONFIG = [];
this.AUX_CONFIG_IDS = [];
this.generateAuxConfig = function () {
console.log('Generating AUX_CONFIG');
this.AUX_CONFIG = [];
for ( let i = 0; i < this.AUX_CONFIG_IDS.length; i++ ) {
let found = FLIGHT_MODES.find( mode => mode.permanentId === this.AUX_CONFIG_IDS[i] );
if (found) {
this.AUX_CONFIG.push(found.boxName);
}
}
};

this.MODE_RANGES = [];
this.ADJUSTMENT_RANGES = [];
Expand Down Expand Up @@ -940,11 +950,13 @@ var FC = {
return this.getServoMixInputNames()[input];
},
getModeId: function (name) {
for (var i = 0; i < this.AUX_CONFIG.length; i++) {
if (this.AUX_CONFIG[i] == name)
return i;

let mode = FLIGHT_MODES.find( mode => mode.boxName === name );
if (mode) {
return mode.permanentId;
} else {
return -1;
}
return -1;
},
isModeBitSet: function (i) {
return BitHelper.bit_check(this.CONFIG.mode[Math.trunc(i / 32)], i % 32);
Expand Down
286 changes: 286 additions & 0 deletions js/flightModes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
'use strict';

var FLIGHT_MODES = [
{
boxId: 0,
boxName: "ARM",
permanentId: 0
},
{
boxId: 1,
boxName: "ANGLE",
permanentId: 1
},
{
boxId: 2,
boxName: "HORIZON",
permanentId: 2
},
{
boxId: 3,
boxName: "NAV ALTHOLD",
permanentId: 3
},
{
boxId: 4,
boxName: "HEADING HOLD",
permanentId: 5
},
{
boxId: 5,
boxName: "HEADFREE",
permanentId: 6
},
{
boxId: 6,
boxName: "HEADADJ",
permanentId: 7
},
{
boxId: 7,
boxName: "CAMSTAB",
permanentId: 8
},
{
boxId: 8,
boxName: "NAV RTH",
permanentId: 10
},
{
boxId: 9,
boxName: "NAV POSHOLD",
permanentId: 11
},
{
boxId: 10,
boxName: "MANUAL",
permanentId: 12
},
{
boxId: 11,
boxName: "BEEPER",
permanentId: 13
},
{
boxId: 12,
boxName: "LEDS OFF",
permanentId: 15
},
{
boxId: 13,
boxName: "LIGHTS",
permanentId: 16
},
{
boxId: 15,
boxName: "OSD OFF",
permanentId: 19
},
{
boxId: 16,
boxName: "TELEMETRY",
permanentId: 20
},
{
boxId: 28,
boxName: "AUTO TUNE",
permanentId: 21
},
{
boxId: 17,
boxName: "BLACKBOX",
permanentId: 26
},
{
boxId: 18,
boxName: "FAILSAFE",
permanentId: 27
},
{
boxId: 19,
boxName: "NAV WP",
permanentId: 28
},
{
boxId: 20,
boxName: "AIR MODE",
permanentId: 29
},
{
boxId: 21,
boxName: "HOME RESET",
permanentId: 30
},
{
boxId: 22,
boxName: "GCS NAV",
permanentId: 31
},
{
boxId: 39,
boxName: "FPV ANGLE MIX",
permanentId: 32
},
{
boxId: 24,
boxName: "SURFACE",
permanentId: 33
},
{
boxId: 25,
boxName: "FLAPERON",
permanentId: 34
},
{
boxId: 26,
boxName: "TURN ASSIST",
permanentId: 35
},
{
boxId: 14,
boxName: "NAV LAUNCH",
permanentId: 36
},
{
boxId: 27,
boxName: "SERVO AUTOTRIM",
permanentId: 37
},
{
boxId: 23,
boxName: "KILLSWITCH",
permanentId: 38
},
{
boxId: 29,
boxName: "CAMERA CONTROL 1",
permanentId: 39
},
{
boxId: 30,
boxName: "CAMERA CONTROL 2",
permanentId: 40
},
{
boxId: 31,
boxName: "CAMERA CONTROL 3",
permanentId: 41
},
{
boxId: 32,
boxName: "OSD ALT 1",
permanentId: 42
},
{
boxId: 33,
boxName: "OSD ALT 2",
permanentId: 43
},
{
boxId: 34,
boxName: "OSD ALT 3",
permanentId: 44
},
{
boxId: 35,
boxName: "NAV COURSE HOLD",
permanentId: 45
},
{
boxId: 36,
boxName: "MC BRAKING",
permanentId: 46
},
{
boxId: 37,
boxName: "USER1",
permanentId: 47
},
{
boxId: 38,
boxName: "USER2",
permanentId: 48
},
{
boxId: 48,
boxName: "USER3",
permanentId: 57
},
{
boxId: 49,
boxName: "USER4",
permanentId: 58
},
{
boxId: 40,
boxName: "LOITER CHANGE",
permanentId: 49
},
{
boxId: 41,
boxName: "MSP RC OVERRIDE",
permanentId: 50
},
{
boxId: 42,
boxName: "PREARM",
permanentId: 51
},
{
boxId: 43,
boxName: "TURTLE",
permanentId: 52
},
{
boxId: 44,
boxName: "NAV CRUISE",
permanentId: 53
},
{
boxId: 45,
boxName: "AUTO LEVEL TRIM",
permanentId: 54
},
{
boxId: 46,
boxName: "WP PLANNER",
permanentId: 55
},
{
boxId: 47,
boxName: "SOARING",
permanentId: 56
},
{
boxId: 50,
boxName: "MISSION CHANGE",
permanentId: 59
},
{
boxId: 51,
boxName: "BEEPER MUTE",
permanentId: 60
},
{
boxId: 52,
boxName: "MULTI FUNCTION",
permanentId: 61
},
{
boxId: 53,
boxName: "MIXER PROFILE 2",
permanentId: 62
},
{
boxId: 54,
boxName: "MIXER TRANSITION",
permanentId: 63
},
{
boxId: 55,
boxName: "ANGLE HOLD",
permanentId: 64
}
];

module.exports = {FLIGHT_MODES};
1 change: 0 additions & 1 deletion js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ var MSPCodes = {
MSP_PID: 112,
MSP_ACTIVEBOXES: 113,
MSP_MOTOR_PINS: 115,
MSP_BOXNAMES: 116,
MSP_PIDNAMES: 117,
MSP_WP: 118,
MSP_BOXIDS: 119,
Expand Down
15 changes: 0 additions & 15 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,21 +386,6 @@ var mspHelper = (function () {
case MSPCodes.MSP_MOTOR_PINS:
console.log(data);
break;
case MSPCodes.MSP_BOXNAMES:
//noinspection JSUndeclaredVariable
FC.AUX_CONFIG = []; // empty the array as new data is coming in
buff = [];
for (let i = 0; i < data.byteLength; i++) {
if (data.getUint8(i) == 0x3B) { // ; (delimeter char)
FC.AUX_CONFIG.push(String.fromCharCode.apply(null, buff)); // convert bytes into ASCII and save as strings

// empty buffer
buff = [];
} else {
buff.push(data.getUint8(i));
}
}
break;
case MSPCodes.MSP_PIDNAMES:
//noinspection JSUndeclaredVariable
FC.PID_names = []; // empty the array as new data is coming in
Expand Down
Loading

0 comments on commit b1f5f32

Please sign in to comment.