You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
inav-configurator/js/motorMixerRuleCollection.js

62 lines
1.2 KiB
JavaScript

/*global $, MotorMixRule*/
'use strict';
var MotorMixerRuleCollection = function () {
let self = {},
data = [],
maxMotorCount = 8;
self.setMotorCount = function (value) {
maxMotorCount = value;
};
self.getMotorCount = function () {
return maxMotorCount;
};
self.put = function (element) {
data.push(element);
};
self.get = function () {
return data;
};
self.drop = function (index) {
data[index].setThrottle(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 MotorMixRule(0, 0, 0, 0));
}
};
self.hasFreeSlots = function () {
return data.length < self.getMotorCount();
};
self.getNumberOfConfiguredMotors = function () {
return data.length;
};
return self;
};