diff --git a/js/flightlog.js b/js/flightlog.js index 7d3c3887..07d7425e 100644 --- a/js/flightlog.js +++ b/js/flightlog.js @@ -1147,7 +1147,16 @@ FlightLog.prototype.rcCommandRawToThrottle = function(value) { FlightLog.prototype.rcMotorRawToPct = function(value) { // Motor displayed as percentage - return Math.min(Math.max(((value - this.getSysConfig().motorOutput[0]) / (this.getSysConfig().motorOutput[1] - this.getSysConfig().motorOutput[0])) * 100.0, 0.0),100.0); + let motorPct; + if (this.getSysConfig().fast_pwm_protocol < FAST_PROTOCOL.indexOf('DSHOT150')) { + // Analog protocol + const ANALOG_RANGE = this.getSysConfig().maxthrottle - ANALOG_MIN_VALUE; + motorPct = ((value - ANALOG_MIN_VALUE) / ANALOG_RANGE) * 100; + } else { + // Digital protocol + motorPct = ((value - DSHOT_MIN_VALUE) / DSHOT_RANGE) * 100; + } + return Math.min(Math.max(motorPct, 0.0), 100.0); }; FlightLog.prototype.getPIDPercentage = function(value) { diff --git a/js/flightlog_fielddefs.js b/js/flightlog_fielddefs.js index a7d05990..edfa5861 100644 --- a/js/flightlog_fielddefs.js +++ b/js/flightlog_fielddefs.js @@ -10,6 +10,13 @@ function makeReadOnly(x) { return x; } +// Some constants used at different places +const DSHOT_MIN_VALUE = 48; +const DSHOT_MAX_VALUE = 2047; +const DSHOT_RANGE = DSHOT_MAX_VALUE - DSHOT_MIN_VALUE; +const ANALOG_MIN_VALUE = 1000; + +// Fields definitions for lists var FlightLogEvent = makeReadOnly({ SYNC_BEEP: 0, diff --git a/js/flightlog_fields_presenter.js b/js/flightlog_fields_presenter.js index 6079e3f8..012e87e7 100644 --- a/js/flightlog_fields_presenter.js +++ b/js/flightlog_fields_presenter.js @@ -511,7 +511,7 @@ function FlightLogFieldPresenter() { case 'motor[5]': case 'motor[6]': case 'motor[7]': - return Math.round(flightLog.rcMotorRawToPct(value)) + " %"; + return `${Math.round(flightLog.rcMotorRawToPct(value))} %`; case 'rcCommands[0]': case 'rcCommands[1]': diff --git a/js/flightlog_parser.js b/js/flightlog_parser.js index d22e4d01..68d6dc68 100644 --- a/js/flightlog_parser.js +++ b/js/flightlog_parser.js @@ -621,6 +621,7 @@ var FlightLogParser = function(logData) { case "rates_type": case "vbat_sag_compensation": case "fields_disabled_mask": + case "motor_pwm_protocol": that.sysConfig[fieldName] = parseInt(fieldValue, 10); break; case "rc_expo": diff --git a/js/graph_config.js b/js/graph_config.js index def6cd8b..6ac6785c 100644 --- a/js/graph_config.js +++ b/js/graph_config.js @@ -261,10 +261,11 @@ GraphConfig.load = function(config) { try { if (fieldName.match(/^motor\[/)) { return { - offset: -(sysConfig.motorOutput[1] + sysConfig.motorOutput[0]) / 2, + offset: sysConfig.fast_pwm_protocol < FAST_PROTOCOL.indexOf('DSHOT150') ? + -(ANALOG_MIN_VALUE + (sysConfig.maxthrottle - ANALOG_MIN_VALUE) / 2) : -(DSHOT_MIN_VALUE + DSHOT_RANGE / 2), power: 1.0, - inputRange: (sysConfig.motorOutput[1] - sysConfig.motorOutput[0]) / 2, - outputRange: 1.0 + inputRange: sysConfig.fast_pwm_protocol < FAST_PROTOCOL.indexOf('DSHOT150') ? (sysConfig.maxthrottle - ANALOG_MIN_VALUE) / 2 : DSHOT_RANGE / 2, + outputRange: 1.0, }; } else if (fieldName.match(/^servo\[/)) { return {