mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-25 09:15:42 +03:00
Load and save of mmix over MSP
This commit is contained in:
parent
0730408796
commit
48a9b36d86
6 changed files with 558 additions and 435 deletions
|
@ -66,6 +66,7 @@ sources.js = [
|
|||
'./js/libraries/jbox/jBox.min.js',
|
||||
'./js/libraries/switchery/switchery.js',
|
||||
'./js/libraries/jquery.ba-throttle-debounce.js',
|
||||
'./js/helpers.js',
|
||||
'./node_modules/inflection/inflection.min.js',
|
||||
'./node_modules/bluebird/js/browser/bluebird.min.js',
|
||||
'./js/injected_methods.js',
|
||||
|
|
15
js/helpers.js
Normal file
15
js/helpers.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*global $*/
|
||||
'use strict';
|
||||
|
||||
function constrain(input, min, max) {
|
||||
|
||||
if (input < min) {
|
||||
return min;
|
||||
}
|
||||
|
||||
if (input > max) {
|
||||
return max;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/*global $*/
|
||||
/*global $,constrain*/
|
||||
'use strict';
|
||||
|
||||
var MotorMixRule = function (throttle, roll, pitch, yaw) {
|
||||
|
@ -17,15 +17,23 @@ var MotorMixRule = function (throttle, roll, pitch, yaw) {
|
|||
};
|
||||
|
||||
self.getThrottle = function () {
|
||||
return throttle;
|
||||
return constrain(throttle, 0, 1);
|
||||
};
|
||||
|
||||
self.getThrottleForMsp = function () {
|
||||
return self.getThrottle() * 1000;
|
||||
}
|
||||
|
||||
self.setThrottle = function (data) {
|
||||
throttle = data;
|
||||
};
|
||||
|
||||
self.getRoll = function () {
|
||||
return roll;
|
||||
return constrain(roll, -1, 1);
|
||||
};
|
||||
|
||||
self.getRollForMsp = function () {
|
||||
return (self.getRoll() + 1) * 1000;
|
||||
};
|
||||
|
||||
self.setRoll = function (data) {
|
||||
|
@ -33,7 +41,11 @@ var MotorMixRule = function (throttle, roll, pitch, yaw) {
|
|||
};
|
||||
|
||||
self.getPitch = function () {
|
||||
return pitch;
|
||||
return constrain(pitch, -1, 1);
|
||||
};
|
||||
|
||||
self.getPitchForMsp = function () {
|
||||
return (self.getPitch() + 1) * 1000;
|
||||
};
|
||||
|
||||
self.setPitch = function (data) {
|
||||
|
@ -41,7 +53,11 @@ var MotorMixRule = function (throttle, roll, pitch, yaw) {
|
|||
};
|
||||
|
||||
self.getYaw = function () {
|
||||
return yaw;
|
||||
return constrain(yaw, -1, 1);
|
||||
};
|
||||
|
||||
self.getYawForMsp = function () {
|
||||
return (self.getYaw() + 1) * 1000;
|
||||
};
|
||||
|
||||
self.setYaw = function (data) {
|
||||
|
|
|
@ -373,12 +373,14 @@ var mspHelper = (function (gui) {
|
|||
for (i = 0; i < data.byteLength; i += 8) {
|
||||
var rule = new MotorMixRule(0, 0, 0, 0);
|
||||
|
||||
MOTOR_RULES.put(rule.fromMsp(
|
||||
rule.fromMsp(
|
||||
data.getUint16(i + 0, true),
|
||||
data.getUint16(i + 2, true),
|
||||
data.getUint16(i + 4, true),
|
||||
data.getUint16(i + 6, true)
|
||||
));
|
||||
)
|
||||
|
||||
MOTOR_RULES.put(rule);
|
||||
}
|
||||
}
|
||||
MOTOR_RULES.cleanup();
|
||||
|
@ -1751,6 +1753,52 @@ var mspHelper = (function (gui) {
|
|||
}
|
||||
};
|
||||
|
||||
self.sendMotorMixer = function (onCompleteCallback) {
|
||||
var nextFunction = sendMixer,
|
||||
servoIndex = 0;
|
||||
|
||||
if (MOTOR_RULES.length == 0) {
|
||||
onCompleteCallback();
|
||||
} else {
|
||||
nextFunction();
|
||||
}
|
||||
|
||||
function sendMixer() {
|
||||
|
||||
var buffer = [];
|
||||
|
||||
// send one at a time, with index
|
||||
|
||||
var rule = MOTOR_RULES.get()[servoIndex];
|
||||
|
||||
if (rule) {
|
||||
|
||||
buffer.push(servoIndex);
|
||||
|
||||
buffer.push(lowByte(rule.getThrottleForMsp()));
|
||||
buffer.push(highByte(rule.getThrottleForMsp()));
|
||||
|
||||
buffer.push(lowByte(rule.getRollForMsp()));
|
||||
buffer.push(highByte(rule.getRollForMsp()));
|
||||
|
||||
buffer.push(lowByte(rule.getPitchForMsp()));
|
||||
buffer.push(highByte(rule.getPitchForMsp()));
|
||||
|
||||
buffer.push(lowByte(rule.getYawForMsp()));
|
||||
buffer.push(highByte(rule.getYawForMsp()));
|
||||
|
||||
// prepare for next iteration
|
||||
servoIndex++;
|
||||
if (servoIndex == MOTOR_RULES.length) { //This is the last rule. Not pretty, but we have to send all rules
|
||||
nextFunction = onCompleteCallback;
|
||||
}
|
||||
MSP.send_message(MSPCodes.MSP2_COMMON_SET_MOTOR_MIXER, buffer, false, nextFunction);
|
||||
} else {
|
||||
onCompleteCallback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.sendModeRanges = function (onCompleteCallback) {
|
||||
var nextFunction = send_next_mode_range;
|
||||
|
||||
|
@ -2540,7 +2588,11 @@ var mspHelper = (function (gui) {
|
|||
|
||||
self.loadServoMixRules = function (callback) {
|
||||
MSP.send_message(MSPCodes.MSP_SERVO_MIX_RULES, false, false, callback);
|
||||
}
|
||||
};
|
||||
|
||||
self.loadMotorMixRules = function (callback) {
|
||||
MSP.send_message(MSPCodes.MSP2_COMMON_MOTOR_MIXER, false, false, callback);
|
||||
};
|
||||
|
||||
self.getCraftName = function(callback) {
|
||||
if (semver.gt(CONFIG.flightControllerVersion, "1.8.0")) {
|
||||
|
|
885
package-lock.json
generated
885
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -29,9 +29,9 @@
|
|||
"inflection": "1.12.0",
|
||||
"jquery": "2.1.4",
|
||||
"jquery-ui-npm": "1.12.0",
|
||||
"nw": "^0.25.4-sdk",
|
||||
"nw-builder": "^3.4.1",
|
||||
"openlayers": "^4.3.3",
|
||||
"nw": "^0.25.4",
|
||||
"nw-builder": "^3.5.1",
|
||||
"openlayers": "^4.6.4",
|
||||
"run-sequence": "^2.2.0",
|
||||
"temp": "^0.8.3",
|
||||
"three": "0.72.0"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue