Skip to content

Commit

Permalink
Increment minimal supported API to 1_44 (firmware 4.3) (2/4) (#4009)
Browse files Browse the repository at this point in the history
* Update version for motor tab

* More cleanup
  • Loading branch information
haslinghuis authored Jun 7, 2024
1 parent a75275f commit 4e07b52
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 67 deletions.
3 changes: 0 additions & 3 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6770,9 +6770,6 @@
"message": "ESC/Motor protocol"
},
"configurationEscProtocolHelp": {
"message": "Select your motor protocol. <br>Make sure to verify the protocol is supported by your ESC, this information should be on the makers website. <br> <b>Be carefull using DSHOT900 and DSHOT1200 as not many ESC's support it!</b>"
},
"configurationEscProtocolHelpNoDSHOT1200": {
"message": "Select your motor protocol. <br>Make sure to verify the protocol is supported by your ESC, this information should be on the makers website."
},
"configurationunsyndePwm": {
Expand Down
112 changes: 48 additions & 64 deletions src/js/tabs/motors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import FC from "../fc";
import MSP from "../msp";
import { mixerList } from "../model";
import MSPCodes from "../msp/MSPCodes";
import { API_VERSION_1_42, API_VERSION_1_44 } from "../data_storage";
import EscProtocols from "../utils/EscProtocols";
import { updateTabList } from "../utils/updateTabList";
import { isInt, getMixerImageSrc } from "../utils/common";
import semver from 'semver';
import * as d3 from 'd3';
import $ from 'jquery';

Expand Down Expand Up @@ -92,9 +90,7 @@ motors.initialize = async function (callback) {
await MSP.promise(MSPCodes.MSP_MOTOR_3D_CONFIG);
await MSP.promise(MSPCodes.MSP2_MOTOR_OUTPUT_REORDERING);
await MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
await MSP.promise(MSPCodes.MSP_FILTER_CONFIG);
}
await MSP.promise(MSPCodes.MSP_FILTER_CONFIG);
await MSP.promise(MSPCodes.MSP_ARMING_CONFIG);

load_html();
Expand Down Expand Up @@ -261,7 +257,7 @@ motors.initialize = async function (callback) {

motorsEnableTestModeElement.prop('checked', self.armed);

if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42) || !(FC.MOTOR_CONFIG.use_dshot_telemetry || FC.MOTOR_CONFIG.use_esc_sensor)) {
if (!(FC.MOTOR_CONFIG.use_dshot_telemetry || FC.MOTOR_CONFIG.use_esc_sensor)) {
$(".motor_testing .telemetry").hide();
}

Expand Down Expand Up @@ -341,7 +337,7 @@ motors.initialize = async function (callback) {
}

// Add EventListener for configuration changes
document.querySelectorAll('.configuration').forEach(elem => elem.addEventListener('change', disableHandler));
document.querySelector('.configuration').addEventListener('change', disableHandler);

/*
* MIXER
Expand Down Expand Up @@ -696,57 +692,50 @@ motors.initialize = async function (callback) {
$('input[name="digitalIdlePercent"]').val(FC.PID_ADVANCED_CONFIG.digitalIdlePercent);
$('input[name="idleMinRpm"]').val(FC.ADVANCED_TUNING.idleMinRpm);

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
dshotBidirElement.prop('checked', FC.MOTOR_CONFIG.use_dshot_telemetry).trigger("change");

self.previousDshotBidir = FC.MOTOR_CONFIG.use_dshot_telemetry;
self.previousFilterDynQ = FC.FILTER_CONFIG.dyn_notch_q;
self.previousFilterDynCount = FC.FILTER_CONFIG.dyn_notch_count;

dshotBidirElement.on("change", function () {
const value = dshotBidirElement.is(':checked');
const newValue = (value !== FC.MOTOR_CONFIG.use_dshot_telemetry) ? 'On' : 'Off';
self.analyticsChanges['BidirectionalDshot'] = newValue;
FC.MOTOR_CONFIG.use_dshot_telemetry = value;

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_44)) {
const rpmFilterIsDisabled = FC.FILTER_CONFIG.gyro_rpm_notch_harmonics === 0;
FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount;
FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ;

const dialogDynFilterSettings = {
title: i18n.getMessage("dialogDynFiltersChangeTitle"),
text: i18n.getMessage("dialogDynFiltersChangeNote"),
buttonYesText: i18n.getMessage("presetsWarningDialogYesButton"),
buttonNoText: i18n.getMessage("presetsWarningDialogNoButton"),
buttonYesCallback: () => _dynFilterChange(),
buttonNoCallback: null,
};

const _dynFilterChange = function() {
if (FC.MOTOR_CONFIG.use_dshot_telemetry && !self.previousDshotBidir) {
FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count_rpm;
FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q_rpm;
} else if (!FC.MOTOR_CONFIG.use_dshot_telemetry && self.previousDshotBidir) {
FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count;
FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q;
}
};

if ((FC.MOTOR_CONFIG.use_dshot_telemetry !== self.previousDshotBidir) && !(rpmFilterIsDisabled)) {
GUI.showYesNoDialog(dialogDynFilterSettings);
} else {
FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount;
FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ;
}
dshotBidirElement.prop('checked', FC.MOTOR_CONFIG.use_dshot_telemetry).trigger("change");

self.previousDshotBidir = FC.MOTOR_CONFIG.use_dshot_telemetry;
self.previousFilterDynQ = FC.FILTER_CONFIG.dyn_notch_q;
self.previousFilterDynCount = FC.FILTER_CONFIG.dyn_notch_count;

dshotBidirElement.on("change", function () {
const value = dshotBidirElement.is(':checked');
const newValue = (value !== FC.MOTOR_CONFIG.use_dshot_telemetry) ? 'On' : 'Off';
self.analyticsChanges['BidirectionalDshot'] = newValue;
FC.MOTOR_CONFIG.use_dshot_telemetry = value;

const rpmFilterIsDisabled = FC.FILTER_CONFIG.gyro_rpm_notch_harmonics === 0;
FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount;
FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ;

const dialogDynFilterSettings = {
title: i18n.getMessage("dialogDynFiltersChangeTitle"),
text: i18n.getMessage("dialogDynFiltersChangeNote"),
buttonYesText: i18n.getMessage("presetsWarningDialogYesButton"),
buttonNoText: i18n.getMessage("presetsWarningDialogNoButton"),
buttonYesCallback: () => _dynFilterChange(),
buttonNoCallback: null,
};

const _dynFilterChange = function() {
if (FC.MOTOR_CONFIG.use_dshot_telemetry && !self.previousDshotBidir) {
FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count_rpm;
FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q_rpm;
} else if (!FC.MOTOR_CONFIG.use_dshot_telemetry && self.previousDshotBidir) {
FC.FILTER_CONFIG.dyn_notch_count = FILTER_DEFAULT.dyn_notch_count;
FC.FILTER_CONFIG.dyn_notch_q = FILTER_DEFAULT.dyn_notch_q;
}
});
};

$('input[name="motorPoles"]').val(FC.MOTOR_CONFIG.motor_poles);
}
if ((FC.MOTOR_CONFIG.use_dshot_telemetry !== self.previousDshotBidir) && !(rpmFilterIsDisabled)) {
GUI.showYesNoDialog(dialogDynFilterSettings);
} else {
FC.FILTER_CONFIG.dyn_notch_count = self.previousFilterDynCount;
FC.FILTER_CONFIG.dyn_notch_q = self.previousFilterDynQ;
}
});

$('#escProtocolTooltip').toggle(semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42));
$('#escProtocolTooltipNoDSHOT1200').toggle(semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42));
$('input[name="motorPoles"]').val(FC.MOTOR_CONFIG.motor_poles);

function updateVisibility() {
// Hide unused settings
Expand All @@ -757,7 +746,6 @@ motors.initialize = async function (callback) {
case 'DSHOT150':
case 'DSHOT300':
case 'DSHOT600':
case 'DSHOT1200':
case 'PROSHOT1000':
digitalProtocol = true;

Expand All @@ -782,8 +770,8 @@ motors.initialize = async function (callback) {

$('.escSensor').toggle(protocolConfigured && digitalProtocol);

$('div.checkboxDshotBidir').toggle(protocolConfigured && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42) && digitalProtocol);
$('div.motorPoles').toggle(protocolConfigured && rpmFeaturesVisible && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42));
$('div.checkboxDshotBidir').toggle(protocolConfigured && digitalProtocol);
$('div.motorPoles').toggle(protocolConfigured && rpmFeaturesVisible);

$('.escMotorStop').toggle(protocolConfigured);

Expand Down Expand Up @@ -1151,9 +1139,7 @@ motors.initialize = async function (callback) {
FC.MOTOR_CONFIG.maxthrottle = parseInt($('input[name="maxthrottle"]').val());
FC.MOTOR_CONFIG.mincommand = parseInt($('input[name="mincommand"]').val());

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
FC.MOTOR_CONFIG.motor_poles = parseInt($('input[name="motorPoles"]').val());
}
FC.MOTOR_CONFIG.motor_poles = parseInt($('input[name="motorPoles"]').val());

FC.MOTOR_3D_CONFIG.deadband3d_low = parseInt($('input[name="_3ddeadbandlow"]').val());
FC.MOTOR_3D_CONFIG.deadband3d_high = parseInt($('input[name="_3ddeadbandhigh"]').val());
Expand All @@ -1171,9 +1157,7 @@ motors.initialize = async function (callback) {
await MSP.promise(MSPCodes.MSP_SET_ADVANCED_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ADVANCED_CONFIG));
await MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG));

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
await MSP.promise(MSPCodes.MSP_SET_FILTER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FILTER_CONFIG));
}
await MSP.promise(MSPCodes.MSP_SET_FILTER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FILTER_CONFIG));

tracking.sendSaveAndChangeEvents(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges, 'motors');
self.analyticsChanges = {};
Expand Down

0 comments on commit 4e07b52

Please sign in to comment.