mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-14 20:10:11 +03:00
MSP layer for global functions
This commit is contained in:
parent
7f4ec9a559
commit
554bec3606
6 changed files with 154 additions and 0 deletions
|
@ -539,6 +539,26 @@ var mspHelper = (function (gui) {
|
|||
console.log("Logic conditions saved");
|
||||
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:
|
||||
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) {
|
||||
var nextFunction = send_next_mode_range;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue