Skip to content

Commit e0438d2

Browse files
authored
Merge pull request #566 from basdelfos/copy-profile
Added copy profile to another profile in PID Tuning tab
2 parents e6739a3 + aed739f commit e0438d2

File tree

7 files changed

+215
-4
lines changed

7 files changed

+215
-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
@@ -1138,6 +1138,9 @@ MspHelper.prototype.process_data = function(dataHandler) {
11381138
case MSPCodes.MSP_SET_SENSOR_CONFIG:
11391139
console.log('Sensor config parameters set');
11401140
break;
1141+
case MSPCodes.MSP_COPY_PROFILE:
1142+
console.log('Copy profile');
1143+
break;
11411144
default:
11421145
console.log('Unknown code detected: ' + code);
11431146
} else {
@@ -1494,6 +1497,12 @@ MspHelper.prototype.crunch = function(code) {
14941497
}
14951498
break;
14961499

1500+
case MSPCodes.MSP_COPY_PROFILE:
1501+
buffer.push8(COPY_PROFILE.type)
1502+
.push8(COPY_PROFILE.dstProfile)
1503+
.push8(COPY_PROFILE.srcProfile)
1504+
break;
1505+
14971506
default:
14981507
return false;
14991508
}

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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,80 @@ TABS.pid_tuning.initialize = function (callback) {
834834
}
835835
});
836836

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

0 commit comments

Comments
 (0)