Commit 48a9b36d authored by Pawel Spychalski (DzikuVx)'s avatar Pawel Spychalski (DzikuVx)
Browse files

Load and save of mmix over MSP

parent 07304087
......@@ -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',
......
/*global $*/
'use strict';
function constrain(input, min, max) {
if (input < min) {
return min;
}
if (input > max) {
return max;
}
return input;
}
\ No newline at end of file
/*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,8 +2588,12 @@ 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")) {
MSP.send_message(MSPCodes.MSP_NAME, false, false, function(resp) {
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment