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

MSP layer for global functions

This commit is contained in:
Pawel Spychalski (DzikuVx) 2020-04-05 18:09:15 +02:00
parent 7f4ec9a559
commit 554bec3606
6 changed files with 154 additions and 0 deletions

View file

@ -90,6 +90,7 @@ sources.js = [
'./js/servoMixRule.js', './js/servoMixRule.js',
'./js/motorMixRule.js', './js/motorMixRule.js',
'./js/logicCondition.js', './js/logicCondition.js',
'./js/globalFunction.js',
'./js/settings.js', './js/settings.js',
'./js/outputMapping.js', './js/outputMapping.js',
'./js/model.js', './js/model.js',
@ -104,6 +105,7 @@ sources.js = [
'./js/servoMixerRuleCollection.js', './js/servoMixerRuleCollection.js',
'./js/motorMixerRuleCollection.js', './js/motorMixerRuleCollection.js',
'./js/logicConditionsCollection.js', './js/logicConditionsCollection.js',
'./js/globalFunctionsCollection.js',
'./js/logicConditionsStatus.js', './js/logicConditionsStatus.js',
'./js/vtx.js', './js/vtx.js',
'./main.js', './main.js',

View file

@ -20,6 +20,7 @@ var CONFIG,
SERVO_RULES, SERVO_RULES,
MOTOR_RULES, MOTOR_RULES,
LOGIC_CONDITIONS, LOGIC_CONDITIONS,
GLOBAL_FUNCTIONS,
SERIAL_CONFIG, SERIAL_CONFIG,
SENSOR_DATA, SENSOR_DATA,
MOTOR_DATA, MOTOR_DATA,
@ -169,6 +170,7 @@ var FC = {
SERVO_RULES = new ServoMixerRuleCollection(); SERVO_RULES = new ServoMixerRuleCollection();
MOTOR_RULES = new MotorMixerRuleCollection(); MOTOR_RULES = new MotorMixerRuleCollection();
LOGIC_CONDITIONS = new LogicConditionsCollection(); LOGIC_CONDITIONS = new LogicConditionsCollection();
GLOBAL_FUNCTIONS = new GlobalFunctionsCollection();
LOGIC_CONDITIONS_STATUS = new LogicConditionsStatus(); LOGIC_CONDITIONS_STATUS = new LogicConditionsStatus();
MIXER_CONFIG = { MIXER_CONFIG = {

57
js/globalFunction.js Normal file
View file

@ -0,0 +1,57 @@
/*global $,FC*/
'use strict';
let GlobalFunction = function (enabled, conditionId, action, operandType, operandValue, flags) {
let self = {};
let $row;
self.getEnabled = function () {
return !!enabled;
}
self.setEnabled = function (data) {
enabled = !!data;
}
self.getConditionId = function () {
return conditionId;
}
self.setConditionId = function (data) {
conditionId = data;
}
self.getAction = function () {
return action;
}
self.setAction = function (data) {
action = data;
}
self.getOperandType = function () {
return operandType;
}
self.setOperandType = function (data) {
operandType = data;
}
self.getOperandValue = function () {
return operandValue;
}
self.setOperandValue = function (data) {
operandValue = data;
}
self.getFlags = function () {
return flags;
};
self.setFlags = function (data) {
flags = data;
};
return self;
}

View file

@ -0,0 +1,25 @@
'use strict';
let GlobalFunctionsCollection = function () {
let self = {},
data = [],
$container;
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

@ -207,6 +207,8 @@ var MSPCodes = {
MSP2_INAV_SET_SERVO_MIXER: 0x2021, MSP2_INAV_SET_SERVO_MIXER: 0x2021,
MSP2_INAV_LOGIC_CONDITIONS: 0x2022, MSP2_INAV_LOGIC_CONDITIONS: 0x2022,
MSP2_INAV_SET_LOGIC_CONDITIONS: 0x2023, MSP2_INAV_SET_LOGIC_CONDITIONS: 0x2023,
MSP2_INAV_GLOBAL_FUNCTIONS: 0x2024,
MSP2_INAV_SET_GLOBAL_FUNCTIONS: 0x2025,
MSP2_INAV_LOGIC_CONDITIONS_STATUS: 0x2026, MSP2_INAV_LOGIC_CONDITIONS_STATUS: 0x2026,
MSP2_PID: 0x2030, MSP2_PID: 0x2030,

View file

@ -539,6 +539,26 @@ var mspHelper = (function (gui) {
console.log("Logic conditions saved"); console.log("Logic conditions saved");
break; break;
case MSPCodes.MSP2_INAV_GLOBAL_FUNCTIONS:
GLOBAL_FUNCTIONS.flush();
if (data.byteLength % 9 === 0) {
for (i = 0; i < data.byteLength; i += 9) {
GLOBAL_FUNCTIONS.put(new GlobalFunction(
data.getInt8(i),
data.getInt8(i + 1),
data.getInt8(i + 2),
data.getInt8(i + 3),
data.getInt32(i + 4, true),
data.getInt8(i + 8)
));
}
}
break;
case MSPCodes.MSP2_INAV_SET_GLOBAL_FUNCTIONS:
console.log("Global functions saved");
break;
case MSPCodes.MSP2_COMMON_MOTOR_MIXER: case MSPCodes.MSP2_COMMON_MOTOR_MIXER:
MOTOR_RULES.flush(); MOTOR_RULES.flush();
@ -2392,6 +2412,52 @@ var mspHelper = (function (gui) {
} }
}; };
self.loadGlobalFunctions = function (callback) {
if (semver.gte(CONFIG.flightControllerVersion, "2.4.0")) {
MSP.send_message(MSPCodes.MSP2_INAV_GLOBAL_FUNCTIONS, false, false, callback);
} else {
callback();
}
}
self.sendGlobalFunctions = function (onCompleteCallback) {
let nextFunction = sendGlobalFunction,
functionIndex = 0;
if (GLOBAL_FUNCTIONS.getCount() == 0 || semver.lt(CONFIG.flightControllerVersion, "2.4.0")) {
onCompleteCallback();
} else {
nextFunction();
}
function sendGlobalFunction() {
let buffer = [];
// send one at a time, with index, 14 bytes per one condition
let globalFunction = GLOBAL_FUNCTIONS.get()[functionIndex];
buffer.push(functionIndex);
buffer.push(globalFunction.getEnabled());
buffer.push(globalFunction.getConditionId());
buffer.push(globalFunction.getAction());
buffer.push(globalFunction.getOperandType());
buffer.push(specificByte(globalFunction.getOperandValue(), 0));
buffer.push(specificByte(globalFunction.getOperandValue(), 1));
buffer.push(specificByte(globalFunction.getOperandValue(), 2));
buffer.push(specificByte(globalFunction.getOperandValue(), 3));
buffer.push(globalFunction.getFlags());
// prepare for next iteration
functionIndex++;
if (functionIndex == GLOBAL_FUNCTIONS.getCount()) { //This is the last rule. Not pretty, but we have to send all rules
nextFunction = onCompleteCallback;
}
MSP.send_message(MSPCodes.MSP2_INAV_SET_GLOBAL_FUNCTIONS, buffer, false, nextFunction);
}
};
self.sendModeRanges = function (onCompleteCallback) { self.sendModeRanges = function (onCompleteCallback) {
var nextFunction = send_next_mode_range; var nextFunction = send_next_mode_range;