mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 19:40:22 +03:00
First cut of code. It's pretty much there. I just need to decide how to handle changing the mixer type, then deciding to stick with the current mixer. Other than that, it's working as expected.
133 lines
No EOL
2.9 KiB
JavaScript
133 lines
No EOL
2.9 KiB
JavaScript
/*global ServoMixRule*/
|
|
'use strict';
|
|
|
|
let ServoMixerRuleCollection = function () {
|
|
|
|
let self = {},
|
|
data = [],
|
|
maxServoCount = 16;
|
|
|
|
self.setServoCount = function (value) {
|
|
maxServoCount = value;
|
|
};
|
|
|
|
self.getServoCount = function () {
|
|
return maxServoCount;
|
|
}
|
|
|
|
self.getServoRulesCount = function () {
|
|
return self.getServoCount() * 2;
|
|
}
|
|
|
|
self.put = function (element) {
|
|
data.push(element);
|
|
};
|
|
|
|
self.get = function () {
|
|
return data;
|
|
};
|
|
|
|
self.drop = function (index) {
|
|
data[index].setRate(0);
|
|
self.cleanup();
|
|
};
|
|
|
|
self.flush = function () {
|
|
data = [];
|
|
};
|
|
|
|
self.cleanup = function () {
|
|
var tmpData = [];
|
|
|
|
data.forEach(function (element) {
|
|
if (element.isUsed()) {
|
|
tmpData.push(element);
|
|
}
|
|
});
|
|
|
|
data = tmpData;
|
|
};
|
|
|
|
self.inflate = function () {
|
|
while (self.hasFreeSlots()) {
|
|
self.put(new ServoMixRule(0, 0, 0, 0));
|
|
}
|
|
};
|
|
|
|
self.hasFreeSlots = function () {
|
|
return data.length < self.getServoRulesCount();
|
|
};
|
|
|
|
self.isServoConfigured = function(servoId) {
|
|
|
|
for (let ruleIndex in data) {
|
|
if (data.hasOwnProperty(ruleIndex)) {
|
|
let rule = data[ruleIndex];
|
|
|
|
if (rule.getTarget() == servoId && rule.isUsed()) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
self.getServoMixRuleFromTarget = function(wantedTarget) {
|
|
let returnTarget = null;
|
|
|
|
for (let ruleIndex in data) {
|
|
if (data.hasOwnProperty(ruleIndex)) {
|
|
if (data[ruleIndex].getTarget() == wantedTarget) {
|
|
returnTarget = data[ruleIndex];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return returnTarget;
|
|
}
|
|
|
|
self.getNumberOfConfiguredServos = function () {
|
|
let count = 0;
|
|
for (let i = 0; i < self.getServoCount(); i ++) {
|
|
if (self.isServoConfigured(i)) {
|
|
count++;
|
|
}
|
|
}
|
|
return count;
|
|
};
|
|
|
|
self.getUsedServoIndexes = function () {
|
|
let out = [];
|
|
|
|
for (let ruleIndex in data) {
|
|
if (data.hasOwnProperty(ruleIndex)) {
|
|
let rule = data[ruleIndex];
|
|
out.push(rule.getTarget());
|
|
}
|
|
}
|
|
|
|
let unique = [...new Set(out)];
|
|
|
|
return unique.sort(function(a, b) {
|
|
return a-b;
|
|
});
|
|
}
|
|
|
|
self.getNextUnusedIndex = function() {
|
|
let nextTarget = 0;
|
|
|
|
for (let ruleIndex in data) {
|
|
if (data.hasOwnProperty(ruleIndex)) {
|
|
let target = data[ruleIndex].getTarget();
|
|
if (target > nextTarget) {
|
|
nextTarget = target;
|
|
}
|
|
}
|
|
}
|
|
|
|
return nextTarget+1;
|
|
}
|
|
|
|
return self;
|
|
}; |