1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-16 12:55:13 +03:00

Backend for getting logic conditions from FC

This commit is contained in:
Pawel Spychalski (DzikuVx) 2019-03-10 14:39:32 +01:00
parent 3c7cf5fc47
commit d6ded2404e
8 changed files with 166 additions and 5 deletions

View file

@ -85,6 +85,7 @@ sources.js = [
'./js/serial.js',
'./js/servoMixRule.js',
'./js/motorMixRule.js',
'./js/logicCondition.js',
'./js/settings.js',
'./js/outputMapping.js',
'./js/model.js',
@ -98,6 +99,7 @@ sources.js = [
'./js/boards.js',
'./js/servoMixerRuleCollection.js',
'./js/motorMixerRuleCollection.js',
'./js/logicConditionsCollection.js',
'./js/vtx.js',
'./main.js',
'./tabs/*.js',

View file

@ -19,6 +19,7 @@ var CONFIG,
SERVO_CONFIG,
SERVO_RULES,
MOTOR_RULES,
LOGIC_CONDITIONS,
SERIAL_CONFIG,
SENSOR_DATA,
MOTOR_DATA,
@ -174,6 +175,7 @@ var FC = {
SERVO_CONFIG = [];
SERVO_RULES = new ServoMixerRuleCollection();
MOTOR_RULES = new MotorMixerRuleCollection();
LOGIC_CONDITIONS = new LogicConditionsCollection();
MIXER_CONFIG = {
yawMotorDirection: 0,

63
js/logicCondition.js Normal file
View file

@ -0,0 +1,63 @@
'use strict';
let LogicCondition = function (enabled, operation, operandAType, operandAValue, operandBType, operandBValue, flags) {
let self = {};
self.getEnabled = function () {
return !!enabled;
};
self.setEnabled = function (data) {
enabled = !!data;
};
self.getOperation = function () {
return operation;
};
self.setOperation = function (data) {
operation = data;
};
self.getOperandAType = function () {
return operandAType;
};
self.setOperandAType = function (data) {
operandAType = data;
};
self.getOperandAValue = function () {
return operandAValue;
};
self.setOperandAValue = function (data) {
operandAValue = data;
};
self.getOperandBType = function () {
return operandBType;
};
self.setOperandBType = function (data) {
operandBType = data;
};
self.getOperandBValue = function () {
return operandBValue;
};
self.setOperandBValue = function (data) {
operandBValue = data;
};
self.getFlags = function () {
return flags;
};
self.setFlags = function (data) {
flags = data;
};
return self;
};

View file

@ -0,0 +1,25 @@
'use strict';
let LogicConditionsCollection = function () {
let self = {},
data = [];
self.put = function (element) {
data.push(element);
};
self.get = function () {
return data;
};
self.flush = function () {
data = [];
};
self.getCount = function () {
return data.length
}
return self;
};

View file

@ -534,13 +534,33 @@ var mspHelper = (function (gui) {
}
}
SERVO_RULES.cleanup();
break;
case MSPCodes.MSP_SET_SERVO_MIX_RULE:
console.log("Servo mix saved");
break;
case MSPCodes.MSP2_INAV_LOGIC_CONDITIONS:
LOGIC_CONDITIONS.flush();
if (data.byteLength % 13 === 0) {
for (i = 0; i < data.byteLength; i += 13) {
LOGIC_CONDITIONS.put(new LogicCondition(
data.getInt8(i),
data.getInt8(i + 1),
data.getInt8(i + 2),
data.getInt32(i + 3, true),
data.getInt8(i + 7),
data.getInt32(i + 8, true),
data.getInt8(i + 12)
));
}
}
break;
case MSPCodes.MSP2_INAV_SET_LOGIC_CONDITIONS:
console.log("Logic conditions saved");
break;
case MSPCodes.MSP2_COMMON_MOTOR_MIXER:
MOTOR_RULES.flush();
@ -2330,6 +2350,54 @@ var mspHelper = (function (gui) {
}
};
self.loadLogicConditions = function (callback) {
if (semver.gte(CONFIG.flightControllerVersion, "2.2.0")) {
MSP.send_message(MSPCodes.MSP2_INAV_LOGIC_CONDITIONS, false, false, callback);
}
}
self.sendLogicConditions = function (onCompleteCallback) {
let nextFunction = sendCondition,
conditionIndex = 0;
if (LOGIC_CONDITIONS.getCount() == 0 || semver.lt(CONFIG.flightControllerVersion, "2.2.0")) {
onCompleteCallback();
} else {
nextFunction();
}
function sendCondition() {
let buffer = [];
// send one at a time, with index
let condition = LOGIC_CONDITIONS.get()[conditionIndex];
buffer.push(conditionIndex);
buffer.push(condition.getEnabled());
buffer.push(condition.getOperation());
buffer.push(condition.getOperandAType());
buffer.push(specificByte(condition.getOperandAValue(), 0));
buffer.push(specificByte(condition.getOperandAValue(), 1));
buffer.push(specificByte(condition.getOperandAValue(), 2));
buffer.push(specificByte(condition.getOperandAValue(), 3));
buffer.push(condition.getOperandBType());
buffer.push(specificByte(condition.getOperandAValue(), 0));
buffer.push(specificByte(condition.getOperandAValue(), 1));
buffer.push(specificByte(condition.getOperandAValue(), 2));
buffer.push(specificByte(condition.getOperandAValue(), 3));
buffer.push(condition.getFlags());
// prepare for next iteration
conditionIndex++;
if (conditionIndex == LOGIC_CONDITIONS.getCount()) { //This is the last rule. Not pretty, but we have to send all rules
nextFunction = onCompleteCallback;
}
MSP.send_message(MSPCodes.MSP2_INAV_SET_LOGIC_CONDITIONS, buffer, false, nextFunction);
}
};
self.sendModeRanges = function (onCompleteCallback) {
var nextFunction = send_next_mode_range;

View file

@ -1,7 +1,7 @@
/*global $*/
'use strict';
var ServoMixRule = function (target, input, rate, speed, condition) {
let ServoMixRule = function (target, input, rate, speed, condition) {
var self = {};
@ -43,7 +43,7 @@ var ServoMixRule = function (target, input, rate, speed, condition) {
self.getConditionId = function () {
return (condition == undefined) ? -1 : condition;
}
};
self.setConditionId = function (data) {
condition = data;

View file

@ -1,7 +1,7 @@
/*global ServoMixRule*/
'use strict';
var ServoMixerRuleCollection = function () {
let ServoMixerRuleCollection = function () {
let self = {},
data = [],

View file

@ -24,7 +24,8 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
mspHelper.loadMotors,
mspHelper.loadServoMixRules,
mspHelper.loadMotorMixRules,
mspHelper.loadOutputMapping
mspHelper.loadOutputMapping,
mspHelper.loadLogicConditions
]);
loadChainer.setExitPoint(loadHtml);
loadChainer.execute();