Skip to content

Commit d918362

Browse files
committed
Added copy profile to another profile in PID Tuning tab
1 parent 05426a3 commit d918362

File tree

7 files changed

+209
-4
lines changed

7 files changed

+209
-4
lines changed

_locales/en/messages.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,24 @@
10211021
"pidTuningControllerHead": {
10221022
"message": "PID Controller"
10231023
},
1024+
"pidTuningCopyProfile": {
1025+
"message": "Copy profile values"
1026+
},
1027+
"pidTuningCopyRateProfile": {
1028+
"message": "Copy rateprofile values"
1029+
},
1030+
"dialogCopyProfileTitle": {
1031+
"message": "Copy Profile Values"
1032+
},
1033+
"dialogCopyProfileNote": {
1034+
"message": "All values on the destination profile will be wiped and overwritten"
1035+
},
1036+
"dialogCopyProfileConfirm": {
1037+
"message": "Copy"
1038+
},
1039+
"dialogCopyProfileClose": {
1040+
"message": "Cancel"
1041+
},
10241042
"pidTuningResetProfile": {
10251043
"message": "Reset all profile values"
10261044
},

js/fc.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var PID_ADVANCED_CONFIG;
5555
var FILTER_CONFIG;
5656
var ADVANCED_TUNING;
5757
var SENSOR_CONFIG;
58+
var COPY_PROFILE;
5859

5960
var FC = {
6061
resetState: function() {
@@ -81,12 +82,18 @@ var FC = {
8182
};
8283

8384
BF_CONFIG = {
84-
currentscale: 0,
85-
currentoffset: 0,
86-
currentmetertype: 0,
87-
batterycapacity: 0,
85+
currentscale: 0,
86+
currentoffset: 0,
87+
currentmetertype: 0,
88+
batterycapacity: 0,
8889
};
8990

91+
COPY_PROFILE = {
92+
type: 0,
93+
dstProfile: 0,
94+
srcProfile: 0,
95+
};
96+
9097
FEATURE_CONFIG = {
9198
features: 0,
9299
};

js/msp/MSPCodes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ var MSPCodes = {
117117

118118
MSP_DISPLAYPORT: 182,
119119

120+
MSP_COPY_PROFILE: 183,
121+
120122
MSP_BEEPER_CONFIG: 184,
121123
MSP_SET_BEEPER_CONFIG: 185,
122124

js/msp/MSPHelper.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ MspHelper.prototype.process_data = function(dataHandler) {
11371137
case MSPCodes.MSP_SET_SENSOR_CONFIG:
11381138
console.log('Sensor config parameters set');
11391139
break;
1140+
case MSPCodes.MSP_COPY_PROFILE:
1141+
console.log('Copy profile');
1142+
break;
11401143
default:
11411144
console.log('Unknown code detected: ' + code);
11421145
} else {
@@ -1490,6 +1493,12 @@ MspHelper.prototype.crunch = function(code) {
14901493
.push8(BLACKBOX.blackboxRateDenom);
14911494
break;
14921495

1496+
case MSPCodes.MSP_COPY_PROFILE:
1497+
buffer.push8(COPY_PROFILE.type)
1498+
.push8(COPY_PROFILE.dstProfile)
1499+
.push8(COPY_PROFILE.srcProfile)
1500+
break;
1501+
14931502
default:
14941503
return false;
14951504
}

tabs/pid_tuning.css

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,18 @@
548548
float: right;
549549
}
550550

551+
.tab-pid_tuning .copyprofilebtn {
552+
width: 150px;
553+
float: right;
554+
margin-right:10px;
555+
}
556+
557+
.tab-pid_tuning .copyrateprofilebtn {
558+
width: 150px;
559+
float: right;
560+
margin-right:10px;
561+
}
562+
551563
.tab-pid_tuning .right {
552564
float: right;
553565
}
@@ -753,3 +765,61 @@ width: 40%;
753765
border-top: 0px solid silver;
754766
background: #f9f9f9;
755767
}
768+
769+
.tab-pid_tuning dialog {
770+
width: 40em;
771+
border-radius: 5px;
772+
}
773+
774+
.tab-pid_tuning dialog .buttons {
775+
position: static;
776+
margin-top: 2em;
777+
}
778+
779+
.tab-pid_tuning dialog h3 {
780+
margin-bottom: 0.5em;
781+
}
782+
783+
.tab-pid_tuning .regular-button {
784+
margin-top: 8px;
785+
margin-bottom: 8px;
786+
margin-right: 10px;
787+
background-color: #ffbb00;
788+
border-radius: 3px;
789+
border: 1px solid #dba718;
790+
color: #000;
791+
font-family: 'open_sansbold', Arial;
792+
font-size: 12px;
793+
text-shadow: 0px 1px rgba(255, 255, 255, 0.25);
794+
display: inline-block;
795+
cursor: pointer;
796+
transition: all ease 0.2s;
797+
padding: 0px;
798+
padding-left: 9px;
799+
padding-right: 9px;
800+
line-height: 28px;
801+
}
802+
.tab-pid_tuning .regular-button:hover {
803+
background-color: #ffcc3e;
804+
transition: all ease 0.2s;
805+
}
806+
.tab-pid_tuning .regular-button:active {
807+
background-color: #ffcc3e;
808+
transition: all ease 0.0s;
809+
box-shadow: inset 0px 1px 5px rgba(0, 0, 0, 0.35);
810+
}
811+
.tab-pid_tuning .regular-button.disabled {
812+
cursor: default;
813+
color: #fff;
814+
background-color: #AFAFAF;
815+
border: 1px solid #AFAFAF;
816+
pointer-events: none;
817+
text-shadow: none;
818+
opacity: 0.5;
819+
}
820+
821+
.tab-pid_tuning dialog select {
822+
border: 1px solid silver;
823+
margin-left: 5px;
824+
width: 120px;
825+
}

tabs/pid_tuning.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<div class="default_btn resetbt">
4444
<a href="#" id="resetProfile" i18n="pidTuningResetProfile"></a>
4545
</div>
46+
<div class="default_btn copyrateprofilebtn">
47+
<a href="#" id="copyRateProfile" i18n="pidTuningCopyRateProfile"></a>
48+
</div>
49+
<div class="default_btn copyprofilebtn">
50+
<a href="#" id="copyProfile" i18n="pidTuningCopyProfile"></a>
51+
</div>
4652
</div>
4753
</div>
4854
<div class="tab_container" style="background-color: #fff;">
@@ -617,4 +623,29 @@
617623
<a class="refresh" href="#" i18n="pidTuningButtonRefresh"></a>
618624
</div>
619625
</div>
626+
627+
<dialog class="dialogCopyProfile">
628+
<h3 i18n="dialogCopyProfileTitle"></h3>
629+
<div class="content">
630+
<div i18n="dialogCopyProfileNote" style="margin-top: 10px"></div>
631+
632+
<div class="contentProfile" style="margin-top:20px;">
633+
<div>
634+
Copy values from current profile to <select class="selectProfile"></select>
635+
</div>
636+
</div>
637+
638+
<div class="contentRateProfile" style="margin-top:20px;">
639+
<div>
640+
Copy values from current rateprofile to <select class="selectRateProfile"></select>
641+
</div>
642+
</div>
643+
644+
</div>
645+
<div class="buttons">
646+
<a href="#" class="dialogCopyProfile-confirmbtn regular-button" i18n="dialogCopyProfileConfirm"></a>
647+
<a href="#" class="dialogCopyProfile-cancelbtn regular-button" i18n="dialogCopyProfileClose"></a>
648+
</div>
649+
</dialog>
650+
620651
</div>

tabs/pid_tuning.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,74 @@ TABS.pid_tuning.initialize = function (callback) {
826826
}
827827
});
828828

829+
var dialogCopyProfile = $('.dialogCopyProfile')[0];
830+
var DIALOG_MODE_PROFILE = 0;
831+
var DIALOG_MODE_RATEPROFILE = 1;
832+
var dialogCopyProfileMode;
833+
834+
var selectProfileValues = { "0": "Profile 1", "1": "Profile 2", "2": "Profile 3" };
835+
var selectRateProfileValues = { "0": "Rateprofile 1", "1": "Rateprofile 2", "2": "Rateprofile 3" };
836+
837+
var selectProfile = $('.selectProfile');
838+
var selectRateProfile = $('.selectRateProfile');
839+
840+
$.each(selectProfileValues, function(key, value) {
841+
if (key != CONFIG.profile)
842+
selectProfile.append(new Option(value, key));
843+
});
844+
$.each(selectRateProfileValues, function(key, value) {
845+
if (key != CONFIG.rateProfile)
846+
selectRateProfile.append(new Option(value, key));
847+
});
848+
849+
$('.copyprofilebtn').click(function() {
850+
$('.dialogCopyProfile').find('.contentProfile').show();
851+
$('.dialogCopyProfile').find('.contentRateProfile').hide();
852+
dialogCopyProfileMode = DIALOG_MODE_PROFILE;
853+
dialogCopyProfile.showModal();
854+
});
855+
856+
$('.copyrateprofilebtn').click(function() {
857+
$('.dialogCopyProfile').find('.contentProfile').hide();
858+
$('.dialogCopyProfile').find('.contentRateProfile').show();
859+
dialogCopyProfileMode = DIALOG_MODE_RATEPROFILE;
860+
dialogCopyProfile.showModal();
861+
});
862+
863+
$('.dialogCopyProfile-cancelbtn').click(function() {
864+
dialogCopyProfile.close();
865+
});
866+
867+
$('.dialogCopyProfile-confirmbtn').click(function() {
868+
switch(dialogCopyProfileMode) {
869+
case DIALOG_MODE_PROFILE:
870+
COPY_PROFILE.type = DIALOG_MODE_PROFILE; // 0 = pid profile
871+
COPY_PROFILE.dstProfile = parseInt(selectProfile.val());
872+
COPY_PROFILE.srcProfile = CONFIG.profile;
873+
874+
MSP.send_message(MSPCodes.MSP_COPY_PROFILE, mspHelper.crunch(MSPCodes.MSP_COPY_PROFILE), false, close_dialog);
875+
876+
break;
877+
878+
case DIALOG_MODE_RATEPROFILE:
879+
COPY_PROFILE.type = DIALOG_MODE_RATEPROFILE; // 1 = rate profile
880+
COPY_PROFILE.dstProfile = parseInt(selectRateProfile.val());
881+
COPY_PROFILE.srcProfile = CONFIG.profile;
882+
883+
MSP.send_message(MSPCodes.MSP_COPY_PROFILE, mspHelper.crunch(MSPCodes.MSP_COPY_PROFILE), false, close_dialog);
884+
885+
break;
886+
887+
default:
888+
close_dialog();
889+
break;
890+
}
891+
892+
function close_dialog() {
893+
dialogCopyProfile.close();
894+
}
895+
});
896+
829897
if (semver.gte(CONFIG.apiVersion, "1.16.0")) {
830898
$('#pid-tuning .delta select').change(function() {
831899
self.setDirty(true);

0 commit comments

Comments
 (0)