diff --git a/js/bitHelper.js b/js/bitHelper.js index 13df5b92c..bee166d4a 100644 --- a/js/bitHelper.js +++ b/js/bitHelper.js @@ -17,7 +17,7 @@ var BitHelper = function() { } self.bit_check = function (num, bit) { - return ((num >> bit) % 2 != 0); + return ((1 << bit) & num) != 0; } self.bit_set = function (num, bit) { diff --git a/js/msp/MSPCodes.js b/js/msp/MSPCodes.js index bcc49eaff..613f0f6c3 100644 --- a/js/msp/MSPCodes.js +++ b/js/msp/MSPCodes.js @@ -165,6 +165,7 @@ var MSPCodes = { MSP2_INAV_MC_BRAKING: 0x200B, MSP2_INAV_SET_MC_BRAKING: 0x200C, MSPV2_INAV_OUTPUT_MAPPING_EXT: 0x200D, + MSPV2_INAV_OUTPUT_MAPPING_EXT2: 0x210D, MSP2_INAV_TIMER_OUTPUT_MODE: 0x200E, MSP2_INAV_SET_TIMER_OUTPUT_MODE: 0x200F, diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 95ce5cbd9..613fb7445 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -1409,6 +1409,7 @@ var mspHelper = (function () { case MSPCodes.MSP2_INAV_SET_CUSTOM_OSD_ELEMENTS: console.log('OSD custom elements preferences saved'); break; +/* case MSPCodes.MSPV2_INAV_OUTPUT_MAPPING: FC.OUTPUT_MAPPING.flush(); for (let i = 0; i < data.byteLength; ++i) @@ -1416,15 +1417,18 @@ var mspHelper = (function () { 'timerId': i, 'usageFlags': data.getUint8(i)}); break; - case MSPCodes.MSPV2_INAV_OUTPUT_MAPPING_EXT: + */ + case MSPCodes.MSPV2_INAV_OUTPUT_MAPPING_EXT2: FC.OUTPUT_MAPPING.flush(); - for (let i = 0; i < data.byteLength; i += 2) { + for (let i = 0; i < data.byteLength; i += 6) { let timerId = data.getUint8(i); - let usageFlags = data.getUint8(i + 1); + let usageFlags = data.getUint32(i + 1, true); + let specialLabels = data.getUint8(i + 5); FC.OUTPUT_MAPPING.put( { 'timerId': timerId, - 'usageFlags': usageFlags + 'usageFlags': usageFlags, + 'specialLabels': specialLabels }); } break; @@ -2771,11 +2775,12 @@ var mspHelper = (function () { }; self.loadOutputMapping = function (callback) { + alert('Obsolete MSPHelper.loadOutputMapping call'); MSP.send_message(MSPCodes.MSPV2_INAV_OUTPUT_MAPPING, false, false, callback); }; self.loadOutputMappingExt = function (callback) { - MSP.send_message(MSPCodes.MSPV2_INAV_OUTPUT_MAPPING_EXT, false, false, callback); + MSP.send_message(MSPCodes.MSPV2_INAV_OUTPUT_MAPPING_EXT2, false, false, callback); }; self.loadTimerOutputModes = function(callback) { diff --git a/js/outputMapping.js b/js/outputMapping.js index 28be64498..7a92f7c13 100644 --- a/js/outputMapping.js +++ b/js/outputMapping.js @@ -30,10 +30,14 @@ var OutputMappingCollection = function () { const OUTPUT_TYPE_MOTOR = 0; const OUTPUT_TYPE_SERVO = 1; + const OUTPUT_TYPE_LED = 2; + + const SPECIAL_LABEL_LED = 1; self.TIMER_OUTPUT_MODE_AUTO = 0; self.TIMER_OUTPUT_MODE_MOTORS = 1; self.TIMER_OUTPUT_MODE_SERVOS = 2; + self.TIMER_OUTPUT_MODE_LED = 3; self.flushTimerOverrides = function() { timerOverrides = {}; @@ -53,6 +57,10 @@ var OutputMappingCollection = function () { return colorTable[timerIndex % colorTable.length]; } + self.isLedPin = function(timer) { + return data[timer].specialLabels == SPECIAL_LABEL_LED; + } + self.getOutputTimerColor = function (output) { let timerId = self.getTimerId(output); @@ -79,10 +87,15 @@ var OutputMappingCollection = function () { for (let i = 0; i < data.length; i++) { timerMap[i] = null; - if (servosToGo > 0 && BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_SERVO)) { + if (servosToGo > 0 && BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_LED)) { + console.log(i + ": LED"); + timerMap[i] = OUTPUT_TYPE_LED; + } else if (servosToGo > 0 && BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_SERVO)) { + console.log(i + ": SERVO"); servosToGo--; timerMap[i] = OUTPUT_TYPE_SERVO; } else if (motorsToGo > 0 && BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_MOTOR)) { + console.log(i + ": MOTOR"); motorsToGo--; timerMap[i] = OUTPUT_TYPE_MOTOR; } @@ -98,6 +111,7 @@ var OutputMappingCollection = function () { outputMap = [], offset = getFirstOutputOffset(); + console.log("Offset: " + offset) for (let i = 0; i < self.getOutputCount(); i++) { let assignment = timerMap[i + offset]; @@ -110,6 +124,8 @@ var OutputMappingCollection = function () { } else if (assignment == OUTPUT_TYPE_SERVO) { outputMap[i] = "Servo " + servos[currentServoIndex]; currentServoIndex++; + } else if (assignment == OUTPUT_TYPE_LED) { + outputMap[i] = "Led"; } } @@ -128,9 +144,11 @@ var OutputMappingCollection = function () { let retVal = 0; for (let i = 0; i < data.length; i++) { + let flags = data[i]['usageFlags']; if ( - BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_MOTOR) || - BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_SERVO) + BitHelper.bit_check(flags, TIM_USE_MOTOR) || + BitHelper.bit_check(flags, TIM_USE_SERVO) || + BitHelper.bit_check(flags, TIM_USE_LED) ) { retVal++; }; @@ -143,7 +161,8 @@ var OutputMappingCollection = function () { for (let i = 0; i < data.length; i++) { if ( BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_MOTOR) || - BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_SERVO) + BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_SERVO) || + BitHelper.bit_check(data[i]['usageFlags'], TIM_USE_LED) ) { return i; } diff --git a/tabs/mixer.js b/tabs/mixer.js index 6c257e62f..bdd41a419 100644 --- a/tabs/mixer.js +++ b/tabs/mixer.js @@ -94,8 +94,9 @@ TABS.mixer.initialize = function (callback, scrollPosition) { let timerId = FC.OUTPUT_MAPPING.getTimerId(i - 1); let color = FC.OUTPUT_MAPPING.getOutputTimerColor(i - 1); + let isLed = FC.OUTPUT_MAPPING.isLedPin(i - 1); - $outputRow.append('S' + i + ' (Timer ' + (timerId + 1) + ')'); + $outputRow.append('S' + i + (isLed ? '/LED' : '') + ' (Timer ' + (timerId + 1) + ')'); $functionRow.append('-'); } @@ -131,6 +132,7 @@ TABS.mixer.initialize = function (callback, scrollPosition) { ''+ ''+ ''+ + ''+ '' + '