From f9dbdf661d0cce6cc21e91e4d843e7496cc4c98c Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 30 Jul 2016 02:27:34 -0700 Subject: [PATCH] implement verison checking in conflicting msp commands --- js/msp.js | 25 ++++++++++++++++++++++--- tabs/pid_tuning.js | 4 ++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/js/msp.js b/js/msp.js index 658d68bb..96f889ba 100755 --- a/js/msp.js +++ b/js/msp.js @@ -962,8 +962,8 @@ var MSP = { break; case MSP_codes.MSP_PID_ADVANCED: - if (semver.gte(CONFIG.flightControllerVersion, "2.8.2")) { - var offset = 0; + var offset = 0; + if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) { ADVANCED_TUNING.rollPitchItermIgnoreRate = data.getUint16(offset, 1); offset += 2; ADVANCED_TUNING.yawItermIgnoreRate = data.getUint16(offset, 1); @@ -982,6 +982,17 @@ var MSP = { ADVANCED_TUNING.pidMaxVelocityYaw = data.getUint16(offset, 1); offset += 2; } + // intentionally supports only 1 version previous to 3.0.0 + else { + ADVANCED_TUNING.rollPitchItermIgnoreRate = data.getUint16(offset, 1); + offset += 2; + ADVANCED_TUNING.yawItermIgnoreRate = data.getUint16(offset, 1); + offset += 2; + ADVANCED_TUNING.yaw_p_limit = data.getUint16(offset, 1); + offset += 2; + ADVANCED_TUNING.deltaMethod = data.getUint8(offset++, 1); + ADVANCED_TUNING.vbatPidCompensation = data.getUint8(offset++, 1); + } break; case MSP_codes.MSP_SPECIAL_PARAMETERS: var offset = 0; @@ -1651,7 +1662,7 @@ MSP.crunch = function (code) { .push16(FILTER_CONFIG.yaw_lpf_hz); break; case MSP_codes.MSP_SET_PID_ADVANCED: - if (semver.gte(CONFIG.flightControllerVersion, "2.8.2")) { + if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) { buffer.push16(ADVANCED_TUNING.rollPitchItermIgnoreRate) .push16(ADVANCED_TUNING.yawItermIgnoreRate) .push16(ADVANCED_TUNING.yaw_p_limit) @@ -1665,6 +1676,14 @@ MSP.crunch = function (code) { .push16(ADVANCED_TUNING.pidMaxVelocity) .push16(ADVANCED_TUNING.pidMaxVelocityYaw); } + // only supports 1 version pre bf 3.0 + else { + buffer.push16(ADVANCED_TUNING.rollPitchItermIgnoreRate) + .push16(ADVANCED_TUNING.yawItermIgnoreRate) + .push16(ADVANCED_TUNING.yaw_p_limit) + .push8(ADVANCED_TUNING.deltaMethod) + .push8(ADVANCED_TUNING.vbatPidCompensation); + } break; case MSP_codes.MSP_SET_SPECIAL_PARAMETERS: buffer.push(Math.round(RC_tuning.yaw_rate * 100)); diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index c49c40de..90fd52b3 100755 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -26,7 +26,7 @@ TABS.pid_tuning.initialize = function (callback) { return MSP.promise(MSP_codes.MSP_SPECIAL_PARAMETERS); } }).then(function() { - if (semver.gte(CONFIG.apiVersion, "3.0.0")) { + if (semver.gte(CONFIG.apiVersion, "2.8.2")) { return MSP.promise(MSP_codes.MSP_PID_ADVANCED); } }).then(function() { @@ -707,7 +707,7 @@ TABS.pid_tuning.initialize = function (callback) { return MSP.promise(MSP_codes.MSP_SET_SPECIAL_PARAMETERS, MSP.crunch(MSP_codes.MSP_SET_SPECIAL_PARAMETERS)); } }).then(function () { - if (semver.gte(CONFIG.apiVersion, "3.0.0")) { + if (semver.gte(CONFIG.apiVersion, "2.8.2")) { return MSP.promise(MSP_codes.MSP_SET_PID_ADVANCED, MSP.crunch(MSP_codes.MSP_SET_PID_ADVANCED)); } }).then(function () {