Skip to content

Commit fd9388a

Browse files
Merge pull request #2579 from sensei-hacker/feature/unified-pinio-pwm-output
PINIO: update configurator for unified PINIO/PWM output
2 parents df35d9a + 44e7de1 commit fd9388a

11 files changed

Lines changed: 1052 additions & 21 deletions

js/logicConditionOperators.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ const LOGIC_OPERATORS = {
322322
output: "boolean"
323323
},
324324
52: {
325-
name: "LED Pin PWM",
325+
name: "PWM on pin",
326326
operandType: "Set Flight Parameter",
327-
hasOperand: [true, false],
327+
hasOperand: [true, true],
328328
output: "raw"
329-
},
329+
},
330330
53: {
331331
name: "Disable GPS Sensor Fix",
332332
operandType: "Set Flight Parameter",

js/outputMapping.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,28 @@ var OutputMappingCollection = function () {
2727
//const TIM_USE_FW_SERVO = 6;
2828
const TIM_USE_LED = 24;
2929
const TIM_USE_BEEPER = 25;
30+
const TIM_USE_PINIO = 26;
3031

3132
const OUTPUT_TYPE_MOTOR = 0;
3233
const OUTPUT_TYPE_SERVO = 1;
3334
const OUTPUT_TYPE_LED = 2;
35+
const OUTPUT_TYPE_PINIO = 3;
3436

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

3740
self.TIMER_OUTPUT_MODE_AUTO = 0;
3841
self.TIMER_OUTPUT_MODE_MOTORS = 1;
3942
self.TIMER_OUTPUT_MODE_SERVOS = 2;
4043
self.TIMER_OUTPUT_MODE_LED = 3;
44+
self.TIMER_OUTPUT_MODE_PINIO = 4;
4145

4246
self.flushTimerOverrides = function() {
4347
timerOverrides = {};
4448
}
4549

4650
self.setTimerOverride = function (timer, outputMode) {
47-
timerOverrides[timer] = outputMode;
51+
timerOverrides[timer] = parseInt(outputMode, 10);
4852
}
4953

5054
self.getTimerOverride = function (timer) {
@@ -88,6 +92,13 @@ var OutputMappingCollection = function () {
8892
timerMap[i] = null;
8993
}
9094

95+
// Pre-assign PINIO outputs — identified by specialLabels, not timer priority
96+
for (let i = 0; i < data.length; i++) {
97+
if (data[i]['specialLabels'] >= SPECIAL_LABEL_PINIO_BASE) {
98+
timerMap[i] = OUTPUT_TYPE_PINIO;
99+
}
100+
}
101+
91102
// Two priority passes: dedicated outputs first, then auto.
92103
// Matches firmware pwmBuildTimerOutputList() behavior.
93104
for (let priority = 0; priority < 2; priority++) {
@@ -100,6 +111,11 @@ var OutputMappingCollection = function () {
100111
let timerId = data[i]['timerId'];
101112
let mode = timerOverrides[timerId] || self.TIMER_OUTPUT_MODE_AUTO;
102113

114+
// Pass 1: skip dedicated overrides — they were handled (or intentionally skipped) in Pass 0
115+
if (!isDedicated && (mode === self.TIMER_OUTPUT_MODE_MOTORS || mode === self.TIMER_OUTPUT_MODE_SERVOS)) {
116+
continue;
117+
}
118+
103119
if (motorsToGo > 0 && BitHelper.bit_check(flags, TIM_USE_MOTOR)
104120
&& (isDedicated ? mode === self.TIMER_OUTPUT_MODE_MOTORS : mode !== self.TIMER_OUTPUT_MODE_MOTORS)) {
105121
timerMap[i] = OUTPUT_TYPE_MOTOR;
@@ -118,27 +134,38 @@ var OutputMappingCollection = function () {
118134
};
119135

120136
self.getOutputTable = function (isMR, motors, servos) {
121-
let currentMotorIndex = 1,
122-
currentServoIndex = 0,
137+
let currentServoIndex = 0,
123138
timerMap = getTimerMap(isMR, motors, servos.length),
139+
motorNumbers = {},
124140
outputMap = [],
125141
offset = getFirstOutputOffset();
126142

127-
console.log("Offset: " + offset)
143+
// Number motors in assignment order: dedicated (OUTPUT_MODE_MOTORS) first, then auto.
144+
// Matches firmware timMotors[] build order in pwmBuildTimerOutputList().
145+
let motorNum = 1;
146+
for (let i = 0; i < data.length; i++) {
147+
if (timerMap[i] !== OUTPUT_TYPE_MOTOR) continue;
148+
let mode = timerOverrides[data[i]['timerId']] || self.TIMER_OUTPUT_MODE_AUTO;
149+
if (mode === self.TIMER_OUTPUT_MODE_MOTORS) motorNumbers[i] = motorNum++;
150+
}
151+
for (let i = 0; i < data.length; i++) {
152+
if (timerMap[i] === OUTPUT_TYPE_MOTOR && motorNumbers[i] === undefined) motorNumbers[i] = motorNum++;
153+
}
128154
for (let i = 0; i < self.getOutputCount(); i++) {
129-
155+
130156
let assignment = timerMap[i + offset];
131157

132158
if (assignment === null) {
133159
outputMap[i] = "-";
134160
} else if (assignment == OUTPUT_TYPE_MOTOR) {
135-
outputMap[i] = "Motor " + currentMotorIndex;
136-
currentMotorIndex++;
161+
outputMap[i] = "Motor " + motorNumbers[i + offset];
137162
} else if (assignment == OUTPUT_TYPE_SERVO) {
138163
outputMap[i] = "Servo " + servos[currentServoIndex];
139164
currentServoIndex++;
140165
} else if (assignment == OUTPUT_TYPE_LED) {
141166
outputMap[i] = "Led";
167+
} else if (assignment == OUTPUT_TYPE_PINIO) {
168+
outputMap[i] = "USER" + (data[i + offset]['specialLabels'] - SPECIAL_LABEL_PINIO_BASE + 1);
142169
}
143170
}
144171

@@ -161,7 +188,9 @@ var OutputMappingCollection = function () {
161188
if (
162189
BitHelper.bit_check(flags, TIM_USE_MOTOR) ||
163190
BitHelper.bit_check(flags, TIM_USE_SERVO) ||
164-
BitHelper.bit_check(flags, TIM_USE_LED)
191+
BitHelper.bit_check(flags, TIM_USE_LED) ||
192+
BitHelper.bit_check(flags, TIM_USE_PINIO) ||
193+
data[i]['specialLabels'] >= SPECIAL_LABEL_PINIO_BASE
165194
) {
166195
retVal++;
167196
};
@@ -175,7 +204,9 @@ var OutputMappingCollection = function () {
175204
if (
176205
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_MOTOR) ||
177206
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_SERVO) ||
178-
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_LED)
207+
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_LED) ||
208+
BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_PINIO) ||
209+
data[i]['specialLabels'] >= SPECIAL_LABEL_PINIO_BASE
179210
) {
180211
return i;
181212
}

0 commit comments

Comments
 (0)