@@ -22,7 +22,14 @@ TABS.pid_tuning = {
2222 activeSubtab : 'pid' ,
2323 analyticsChanges : { } ,
2424
25- sliderRetainConfiguration : false ,
25+ retainConfiguration : false ,
26+
27+ CONFIGURATOR_PIDS : [ ] ,
28+ CONFIGURATOR_ADVANCED_TUNING : { } ,
29+ CONFIGURATOR_FILTER_CONFIG : { } ,
30+ CONFIGURATOR_RC_TUNING : { } ,
31+ CONFIGURATOR_FEATURE_CONFIG : { } ,
32+ CONFIGURATOR_TUNING_SLIDERS : { } ,
2633} ;
2734
2835TABS . pid_tuning . initialize = function ( callback ) {
@@ -1360,7 +1367,7 @@ TABS.pid_tuning.initialize = function (callback) {
13601367
13611368 $ ( '#resetPidProfile' ) . on ( 'click' , function ( ) {
13621369 self . updating = true ;
1363- self . sliderRetainConfiguration = true ;
1370+ self . retainConfiguration = true ;
13641371
13651372 MSP . promise ( MSPCodes . MSP_SET_RESET_CURR_PID ) . then ( function ( ) {
13661373 self . refresh ( function ( ) {
@@ -1895,10 +1902,10 @@ TABS.pid_tuning.initialize = function (callback) {
18951902 const sliderPidsModeSelect = $ ( '#sliderPidsModeSelect' ) ;
18961903
18971904 if ( semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
1898- if ( self . sliderRetainConfiguration ) {
1905+ if ( self . retainConfiguration ) {
18991906 self . setDirty ( true ) ;
19001907 } else {
1901- TuningSliders . saveInitialSettings ( ) ;
1908+ self . saveInitialSettings ( ) ;
19021909 }
19031910 sliderPidsModeSelect . val ( FC . TUNING_SLIDERS . slider_pids_mode ) ;
19041911 } else {
@@ -1943,6 +1950,11 @@ TABS.pid_tuning.initialize = function (callback) {
19431950 $ ( '#pid_main .YAW .pid_data input' ) . each ( function ( ) {
19441951 $ ( this ) . prop ( 'disabled' , disableY ) ;
19451952 } ) ;
1953+
1954+ if ( setMode !== self . CONFIGURATOR_TUNING_SLIDERS . slider_pids_mode ) {
1955+ self . setDirty ( true ) ;
1956+ }
1957+
19461958 } ) . trigger ( 'change' ) ;
19471959 }
19481960
@@ -2070,11 +2082,11 @@ TABS.pid_tuning.initialize = function (callback) {
20702082 $ ( 'a.buttonPidTuningSliders' ) . click ( function ( ) {
20712083 // set Slider PID mode to RP(Y) when re-enabling Sliders
20722084 if ( semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
2073- const firmwareMode = TuningSliders . initialSettings . sliderPidsMode ;
2085+ const firmwareMode = self . CONFIGURATOR_TUNING_SLIDERS . slider_pids_mode ;
20742086 const workingMode = firmwareMode === 1 ? 1 : 2 ;
20752087
20762088 if ( firmwareMode !== workingMode ) {
2077- self . sliderRetainConfiguration = true ;
2089+ self . retainConfiguration = true ;
20782090 }
20792091 sliderPidsModeSelect . val ( workingMode ) . trigger ( 'change' ) ;
20802092 }
@@ -2154,8 +2166,6 @@ TABS.pid_tuning.initialize = function (callback) {
21542166 } ) ;
21552167 // enable Filter sliders button
21562168 $ ( 'a.buttonFilterTuningSliders' ) . click ( function ( ) {
2157- self . sliderRetainConfiguration = true ;
2158-
21592169 if ( TuningSliders . GyroSliderUnavailable ) {
21602170 //set Slider mode to ON when re-enabling Sliders
21612171 if ( semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
@@ -2184,18 +2194,13 @@ TABS.pid_tuning.initialize = function (callback) {
21842194
21852195 // update on pid table inputs
21862196 $ ( '#pid_main input' ) . on ( 'input' , function ( ) {
2187- if ( semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
2188- self . sliderRetainConfiguration = true ;
2189- } else {
2197+ if ( semver . lt ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
21902198 TuningSliders . updatePidSlidersDisplay ( ) ;
21912199 self . analyticsChanges [ 'PidTuningSliders' ] = "Off" ;
21922200 }
21932201 } ) ;
21942202 // update on filter value or type changes
21952203 $ ( '.pid_filter tr:not(.newFilter) input, .pid_filter tr:not(.newFilter) select' ) . on ( 'input' , function ( ) {
2196- if ( semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
2197- self . sliderRetainConfiguration = true ;
2198- }
21992204 TuningSliders . updateFilterSlidersDisplay ( ) ;
22002205 if ( TuningSliders . GyroSliderUnavailable ) {
22012206 self . analyticsChanges [ 'GyroFilterTuningSlider' ] = "Off" ;
@@ -2268,7 +2273,7 @@ TABS.pid_tuning.initialize = function (callback) {
22682273 return MSP . promise ( MSPCodes . MSP_EEPROM_WRITE ) ;
22692274 } ) . then ( function ( ) {
22702275 self . updating = false ;
2271- self . sliderRetainConfiguration = false ;
2276+ self . retainConfiguration = false ;
22722277
22732278 self . setDirty ( false ) ;
22742279
@@ -2379,8 +2384,8 @@ TABS.pid_tuning.cleanup = function (callback) {
23792384TABS . pid_tuning . refresh = function ( callback ) {
23802385 const self = this ;
23812386
2382- if ( self . sliderRetainConfiguration && ! self . updating ) {
2383- TuningSliders . restoreInitialSettings ( ) ;
2387+ if ( self . retainConfiguration && ! self . updating ) {
2388+ self . restoreInitialSettings ( ) ;
23842389 }
23852390
23862391 GUI . tab_switch_cleanup ( function ( ) {
@@ -2394,6 +2399,41 @@ TABS.pid_tuning.refresh = function (callback) {
23942399 } ) ;
23952400} ;
23962401
2402+ TABS . pid_tuning . saveInitialSettings = function ( ) {
2403+ if ( semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
2404+ this . CONFIGURATOR_PIDS = [ ...FC . PIDS ] ;
2405+ this . CONFIGURATOR_ADVANCED_TUNING = { ...FC . ADVANCED_TUNING } ;
2406+ this . CONFIGURATOR_FILTER_CONFIG = { ...FC . FILTER_CONFIG } ;
2407+ this . CONFIGURATOR_RC_TUNING = { ...FC . RC_TUNING } ;
2408+ this . CONFIGURATOR_FEATURE_CONFIG = { ...FC . FEATURE_CONFIG } ;
2409+ this . CONFIGURATOR_TUNING_SLIDERS = { ...FC . TUNING_SLIDERS } ;
2410+ }
2411+ } ;
2412+
2413+ TABS . pid_tuning . restoreInitialSettings = function ( ) {
2414+ if ( semver . gte ( FC . CONFIG . apiVersion , API_VERSION_1_44 ) ) {
2415+ FC . PIDS = [ ...this . CONFIGURATOR_PIDS ] ;
2416+ FC . ADVANCED_TUNING = { ...this . CONFIGURATOR_ADVANCED_TUNING } ;
2417+ FC . FILTER_CONFIG = { ...this . CONFIGURATOR_FILTER_CONFIG } ;
2418+ FC . RC_TUNING = { ...this . CONFIGURATOR_RC_TUNING } ;
2419+ FC . FEATURE_CONFIG = { ...this . CONFIGURATOR_FEATURE_CONFIG } ;
2420+ FC . TUNING_SLIDERS = { ...this . CONFIGURATOR_TUNING_SLIDERS } ;
2421+
2422+ Promise . resolve ( true )
2423+ . then ( ( ) => MSP . promise ( MSPCodes . MSP_SET_PID , mspHelper . crunch ( MSPCodes . MSP_SET_PID ) ) )
2424+ . then ( ( ) => MSP . promise ( MSPCodes . MSP_SET_PID_ADVANCED , mspHelper . crunch ( MSPCodes . MSP_SET_PID_ADVANCED ) ) )
2425+ . then ( ( ) => MSP . promise ( MSPCodes . MSP_SET_FILTER_CONFIG , mspHelper . crunch ( MSPCodes . MSP_SET_FILTER_CONFIG ) ) )
2426+ . then ( ( ) => MSP . promise ( MSPCodes . MSP_SET_RC_TUNING , mspHelper . crunch ( MSPCodes . MSP_SET_RC_TUNING ) ) )
2427+ . then ( ( ) => MSP . promise ( MSPCodes . MSP_SET_FEATURE_CONFIG , mspHelper . crunch ( MSPCodes . MSP_SET_FEATURE_CONFIG ) ) )
2428+ . then ( ( ) => MSP . promise ( MSPCodes . MSP_SET_TUNING_SLIDERS , mspHelper . crunch ( MSPCodes . MSP_SET_TUNING_SLIDERS ) ) )
2429+ . then ( ( ) => {
2430+ TABS . pid_tuning . retainConfiguration = false ;
2431+
2432+ console . log ( 'Configuration restored to initial values' ) ;
2433+ } ) ;
2434+ }
2435+ } ;
2436+
23972437TABS . pid_tuning . setProfile = function ( ) {
23982438 const self = this ;
23992439
@@ -2416,6 +2456,10 @@ TABS.pid_tuning.setDirty = function (isDirty) {
24162456 if ( semver . gte ( FC . CONFIG . apiVersion , "1.20.0" ) ) {
24172457 $ ( '.tab-pid_tuning select[name="rate_profile"]' ) . prop ( 'disabled' , isDirty ) ;
24182458 }
2459+
2460+ if ( isDirty ) {
2461+ self . retainConfiguration = true ;
2462+ }
24192463} ;
24202464
24212465TABS . pid_tuning . checkUpdateProfile = function ( updateRateProfile ) {
0 commit comments