From 346c317dedf142270017ed13fcdc4b442f35b5c8 Mon Sep 17 00:00:00 2001 From: fgiudice98 Date: Tue, 30 Jun 2020 11:27:17 +0200 Subject: [PATCH] Blackbox sample rate selection --- src/js/fc.js | 1 + src/js/msp/MSPHelper.js | 7 ++++++- src/js/tabs/onboard_logging.js | 22 ++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/js/fc.js b/src/js/fc.js index d0cc3151..b65117f2 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -342,6 +342,7 @@ var FC = { blackboxRateNum: 1, blackboxRateDenom: 1, blackboxPDenom: 0, + blackboxSampleRate: 0, }; TRANSPONDER = { diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 3872c6b4..b3e82b77 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -1353,7 +1353,9 @@ MspHelper.prototype.process_data = function(dataHandler) { BLACKBOX.blackboxRateDenom = data.readU8(); if (semver.gte(CONFIG.apiVersion, "1.36.0")) { BLACKBOX.blackboxPDenom = data.readU16(); - + } + if (semver.gte(CONFIG.apiVersion, API_VERSION_1_44)) { + BLACKBOX.blackboxSampleRate = data.readU8(); } break; case MSPCodes.MSP_SET_BLACKBOX_CONFIG: @@ -2135,6 +2137,9 @@ MspHelper.prototype.crunch = function(code) { if (semver.gte(CONFIG.apiVersion, "1.36.0")) { buffer.push16(BLACKBOX.blackboxPDenom); } + if (semver.gte(CONFIG.apiVersion, API_VERSION_1_44)) { + buffer.push8(BLACKBOX.blackboxSampleRate); + } break; case MSPCodes.MSP_COPY_PROFILE: diff --git a/src/js/tabs/onboard_logging.js b/src/js/tabs/onboard_logging.js index 534aff6a..a3540483 100644 --- a/src/js/tabs/onboard_logging.js +++ b/src/js/tabs/onboard_logging.js @@ -104,7 +104,9 @@ TABS.onboard_logging.initialize = function (callback) { if (BLACKBOX.supported) { $(".tab-onboard_logging a.save-settings").click(function() { - if (semver.gte(CONFIG.apiVersion, "1.36.0")) { + if (semver.gte(CONFIG.apiVersion, API_VERSION_1_44)) { + BLACKBOX.blackboxSampleRate = parseInt(loggingRatesSelect.val(), 10); + } else if (semver.gte(CONFIG.apiVersion, "1.36.0")) { BLACKBOX.blackboxPDenom = parseInt(loggingRatesSelect.val(), 10); } else { var rate = loggingRatesSelect.val().split('/'); @@ -208,7 +210,19 @@ TABS.onboard_logging.initialize = function (callback) { pidRate = pidRateBase / PID_ADVANCED_CONFIG.gyro_sync_denom / PID_ADVANCED_CONFIG.pid_process_denom; } - if (semver.gte(CONFIG.apiVersion, "1.36.0")) { + if (semver.gte(CONFIG.apiVersion, API_VERSION_1_44)) { + const sampleRateNum=5; + for (let i = 0; i < sampleRateNum; i++) { + let loggingFrequency = Math.round(pidRate / (2**i)); + let loggingFrequencyUnit = "Hz"; + if (gcd(loggingFrequency, 1000) === 1000) { + loggingFrequency /= 1000; + loggingFrequencyUnit = "KHz"; + } + loggingRatesSelect.append(``); + } + loggingRatesSelect.val(BLACKBOX.blackboxSampleRate); + } else if (semver.gte(CONFIG.apiVersion, "1.36.0")) { loggingRates = [ {text: "Disabled", hz: 0, p_denom: 0}, {text: "500 Hz", hz: 500, p_denom: 16}, @@ -244,7 +258,7 @@ TABS.onboard_logging.initialize = function (callback) { ]; - for (var i = 0; i < loggingRates.length; i++) { + for (let i = 0; i < loggingRates.length; i++) { var loggingRate = Math.round(pidRate / loggingRates[i].denom); var loggingRateUnit = " Hz"; if (loggingRate !== Infinity) { @@ -330,7 +344,7 @@ TABS.onboard_logging.initialize = function (callback) { {text: "FF_INTERPOLATED"}, ]; - for (var i = 0; i < PID_ADVANCED_CONFIG.debugModeCount; i++) { + for (let i = 0; i < PID_ADVANCED_CONFIG.debugModeCount; i++) { if (i < debugModes.length) { debugModeSelect.append(new Option(debugModes[i].text, i)); } else {