Improve MSP handling of servo configuration. Fixes backup of CJMCU

boards.
10.3.x-maintenance
Dominic Clifton 2015-05-07 22:47:32 +01:00
parent 244685c9a6
commit 0f95f4ec4c
1 changed files with 12 additions and 10 deletions

View File

@ -434,15 +434,17 @@ var MSP = {
case MSP_codes.MSP_SERVO_CONF: case MSP_codes.MSP_SERVO_CONF:
SERVO_CONFIG = []; // empty the array as new data is coming in SERVO_CONFIG = []; // empty the array as new data is coming in
for (var i = 0; i < 56; i += 7) { if (data.byteLength % 7 == 0) {
var arr = { for (var i = 0; i < data.byteLength; i += 7) {
'min': data.getInt16(i, 1), var arr = {
'max': data.getInt16(i + 2, 1), 'min': data.getInt16(i, 1),
'middle': data.getInt16(i + 4, 1), 'max': data.getInt16(i + 2, 1),
'rate': data.getInt8(i + 6) 'middle': data.getInt16(i + 4, 1),
}; 'rate': data.getInt8(i + 6)
};
SERVO_CONFIG.push(arr); SERVO_CONFIG.push(arr);
}
} }
break; break;
case MSP_codes.MSP_SET_RAW_RC: case MSP_codes.MSP_SET_RAW_RC:
@ -688,7 +690,7 @@ var MSP = {
} }
break; break;
case MSP_codes.MSP_CHANNEL_FORWARDING: case MSP_codes.MSP_CHANNEL_FORWARDING:
for (var i = 0; i < 8; i ++) { for (var i = 0; i < data.byteLength && i < SERVO_CONFIG.length; i ++) {
var channelIndex = data.getUint8(i); var channelIndex = data.getUint8(i);
if (channelIndex < 255) { if (channelIndex < 255) {
SERVO_CONFIG[i].indexOfChannelToForward = channelIndex; SERVO_CONFIG[i].indexOfChannelToForward = channelIndex;