Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions js/logicConditionOperators.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ const LOGIC_OPERATORS = {
output: "boolean"
},
52: {
name: "LED Pin PWM",
name: "PWM on pin",
operandType: "Set Flight Parameter",
hasOperand: [true, false],
hasOperand: [true, true],
output: "raw"
},
},
53: {
name: "Disable GPS Sensor Fix",
operandType: "Set Flight Parameter",
Expand Down
49 changes: 40 additions & 9 deletions js/outputMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,28 @@
//const TIM_USE_FW_SERVO = 6;
const TIM_USE_LED = 24;
const TIM_USE_BEEPER = 25;
const TIM_USE_PINIO = 26;

const OUTPUT_TYPE_MOTOR = 0;
const OUTPUT_TYPE_SERVO = 1;
const OUTPUT_TYPE_LED = 2;
const OUTPUT_TYPE_PINIO = 3;

const SPECIAL_LABEL_LED = 1;
const SPECIAL_LABEL_PINIO_BASE = 2; // values 2..5 = USER1..USER4 (add channel index 0-3)

self.TIMER_OUTPUT_MODE_AUTO = 0;
self.TIMER_OUTPUT_MODE_MOTORS = 1;
self.TIMER_OUTPUT_MODE_SERVOS = 2;
self.TIMER_OUTPUT_MODE_LED = 3;
self.TIMER_OUTPUT_MODE_PINIO = 4;

self.flushTimerOverrides = function() {
timerOverrides = {};
}

self.setTimerOverride = function (timer, outputMode) {
timerOverrides[timer] = outputMode;
timerOverrides[timer] = parseInt(outputMode, 10);

Check warning on line 51 in js/outputMapping.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `Number.parseInt` over `parseInt`.

See more on https://sonarcloud.io/project/issues?id=iNavFlight_inav-configurator&issues=AZ3xKVXzCNL_GdnX96dt&open=AZ3xKVXzCNL_GdnX96dt&pullRequest=2579
}

self.getTimerOverride = function (timer) {
Expand Down Expand Up @@ -88,6 +92,13 @@
timerMap[i] = null;
}

// Pre-assign PINIO outputs — identified by specialLabels, not timer priority
for (let i = 0; i < data.length; i++) {
if (data[i]['specialLabels'] >= SPECIAL_LABEL_PINIO_BASE) {
timerMap[i] = OUTPUT_TYPE_PINIO;
}
}

// Two priority passes: dedicated outputs first, then auto.
// Matches firmware pwmBuildTimerOutputList() behavior.
for (let priority = 0; priority < 2; priority++) {
Expand All @@ -100,6 +111,11 @@
let timerId = data[i]['timerId'];
let mode = timerOverrides[timerId] || self.TIMER_OUTPUT_MODE_AUTO;

// Pass 1: skip dedicated overrides — they were handled (or intentionally skipped) in Pass 0
if (!isDedicated && (mode === self.TIMER_OUTPUT_MODE_MOTORS || mode === self.TIMER_OUTPUT_MODE_SERVOS)) {
continue;
}

if (motorsToGo > 0 && BitHelper.bit_check(flags, TIM_USE_MOTOR)
&& (isDedicated ? mode === self.TIMER_OUTPUT_MODE_MOTORS : mode !== self.TIMER_OUTPUT_MODE_MOTORS)) {
timerMap[i] = OUTPUT_TYPE_MOTOR;
Expand All @@ -117,28 +133,39 @@
return timerMap;
};

self.getOutputTable = function (isMR, motors, servos) {

Check failure on line 136 in js/outputMapping.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=iNavFlight_inav-configurator&issues=AZ3xKVXzCNL_GdnX96du&open=AZ3xKVXzCNL_GdnX96du&pullRequest=2579
let currentMotorIndex = 1,
currentServoIndex = 0,
let currentServoIndex = 0,
timerMap = getTimerMap(isMR, motors, servos.length),
motorNumbers = {},
outputMap = [],
offset = getFirstOutputOffset();

console.log("Offset: " + offset)
// Number motors in assignment order: dedicated (OUTPUT_MODE_MOTORS) first, then auto.
// Matches firmware timMotors[] build order in pwmBuildTimerOutputList().
let motorNum = 1;
for (let i = 0; i < data.length; i++) {
if (timerMap[i] !== OUTPUT_TYPE_MOTOR) continue;
let mode = timerOverrides[data[i]['timerId']] || self.TIMER_OUTPUT_MODE_AUTO;
if (mode === self.TIMER_OUTPUT_MODE_MOTORS) motorNumbers[i] = motorNum++;
}
for (let i = 0; i < data.length; i++) {
if (timerMap[i] === OUTPUT_TYPE_MOTOR && motorNumbers[i] === undefined) motorNumbers[i] = motorNum++;
}
for (let i = 0; i < self.getOutputCount(); i++) {

let assignment = timerMap[i + offset];

if (assignment === null) {
outputMap[i] = "-";
} else if (assignment == OUTPUT_TYPE_MOTOR) {
outputMap[i] = "Motor " + currentMotorIndex;
currentMotorIndex++;
outputMap[i] = "Motor " + motorNumbers[i + offset];
} else if (assignment == OUTPUT_TYPE_SERVO) {
outputMap[i] = "Servo " + servos[currentServoIndex];
currentServoIndex++;
} else if (assignment == OUTPUT_TYPE_LED) {
outputMap[i] = "Led";
} else if (assignment == OUTPUT_TYPE_PINIO) {
outputMap[i] = "USER" + (data[i + offset]['specialLabels'] - SPECIAL_LABEL_PINIO_BASE + 1);
}
}

Expand All @@ -161,7 +188,9 @@
if (
BitHelper.bit_check(flags, TIM_USE_MOTOR) ||
BitHelper.bit_check(flags, TIM_USE_SERVO) ||
BitHelper.bit_check(flags, TIM_USE_LED)
BitHelper.bit_check(flags, TIM_USE_LED) ||
BitHelper.bit_check(flags, TIM_USE_PINIO) ||
data[i]['specialLabels'] >= SPECIAL_LABEL_PINIO_BASE
) {
retVal++;
};
Expand All @@ -175,7 +204,9 @@
if (
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_MOTOR) ||
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_SERVO) ||
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_LED)
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_LED) ||
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_PINIO) ||
data[i]['specialLabels'] >= SPECIAL_LABEL_PINIO_BASE
) {
return i;
}
Expand Down
Loading
Loading