From 8d39b3f8cc037cf5b7a17b274664c9118238a491 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Mon, 1 Jun 2015 11:02:09 +0100 Subject: [PATCH] Fix handling of MSP_SERVO and MSP_MOTOR. Previously the code assumed there was always 8 servos and 8 motors. --- js/msp.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/msp.js b/js/msp.js index 5051ec9cc..c6e8d3a69 100644 --- a/js/msp.js +++ b/js/msp.js @@ -240,16 +240,18 @@ var MSP = { SENSOR_DATA.magnetometer[2] = data.getInt16(16, 1) / 1090; break; case MSP_codes.MSP_SERVO: + var servoCount = message_length / 2; var needle = 0; - for (var i = 0; i < 8; i++) { + for (var i = 0; i < servoCount; i++) { SERVO_DATA[i] = data.getUint16(needle, 1); needle += 2; } break; case MSP_codes.MSP_MOTOR: + var motorCount = message_length / 2; var needle = 0; - for (var i = 0; i < 8; i++) { + for (var i = 0; i < motorCount; i++) { MOTOR_DATA[i] = data.getUint16(needle, 1); needle += 2;