Skip to content

Commit dc285d7

Browse files
committed
Changes as per review comments
1 parent 5fede9f commit dc285d7

File tree

4 files changed

+74
-18
lines changed

4 files changed

+74
-18
lines changed

js/flightlog.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ function FlightLog(logData) {
255255
found = false;
256256

257257
var refVoltage;
258-
if((sysConfig.firmwareType == FIRMWARE_TYPE_BETAFLIGHT && semver.gte(sysConfig.firmwareVersion, '3.1.0')) ||
259-
(sysConfig.firmwareType == FIRMWARE_TYPE_CLEANFLIGHT && semver.gte(sysConfig.firmwareVersion, '2.0.0'))) {
258+
if(firmwareGreaterOrEqual(sysConfig, '3.1.0', '2.0.0')) {
260259
refVoltage = sysConfig.vbatref;
261260
} else {
262261
refVoltage = that.vbatADCToMillivolts(sysConfig.vbatref) / 100;
@@ -968,7 +967,7 @@ FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis, curre
968967

969968
var sysConfig = this.getSysConfig();
970969

971-
if(sysConfig.firmware >= 3.0 || (sysConfig.firmwareType == FIRMWARE_TYPE_CLEANFLIGHT && sysConfig.firmware >= 2.0)) {
970+
if(firmwareGreaterOrEqual(sysConfig, '3.0.0', '2.0.0')) {
972971

973972
const RC_RATE_INCREMENTAL = 14.54;
974973
const RC_EXPO_POWER = 3;
@@ -980,12 +979,30 @@ FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis, curre
980979
var angleRate, rcRate, rcSuperfactor, rcCommandf;
981980
var rcExpo;
982981

983-
if (axis != AXIS.YAW) {
984-
rcExpo = sysConfig.rcExpo;
985-
rcRate = sysConfig.rcRate / 100.0;
986-
} else {
987-
rcExpo = sysConfig.rcYawExpo;
988-
rcRate = sysConfig.rcYawRate / 100.0;
982+
if (firmwareGreaterOrEqual(sysConfig, '3.3.0', '2.3.0')) {
983+
switch(axis) {
984+
case AXIS.ROLL:
985+
rcExpo = sysConfig["rc_expo"][0];
986+
rcRate = sysConfig["rc_rates"][0] / 100.0;
987+
break;
988+
case AXIS.PITCH:
989+
rcExpo = sysConfig["rc_expo"][1];
990+
rcRate = sysConfig["rc_rates"][1] / 100.0;
991+
break;
992+
case AXIS.YAW:
993+
rcExpo = sysConfig["rc_expo"][2];
994+
rcRate = sysConfig["rc_rates"][2] / 100.0;
995+
break;
996+
}
997+
}
998+
else {
999+
if (axis != AXIS.YAW) {
1000+
rcExpo = sysConfig.rcExpo;
1001+
rcRate = sysConfig.rcRate / 100.0;
1002+
} else {
1003+
rcExpo = sysConfig.rcYawExpo;
1004+
rcRate = sysConfig.rcYawRate / 100.0;
1005+
}
9891006
}
9901007

9911008
if (rcRate > 2.0) rcRate = rcRate + (RC_RATE_INCREMENTAL * (rcRate - 2.0));
@@ -1019,7 +1036,7 @@ FlightLog.prototype.rcCommandRawToDegreesPerSecond = function(value, axis, curre
10191036
return calculateSetpointRate(axis, value);
10201037

10211038
}
1022-
else if(sysConfig.firmwareType == FIRMWARE_TYPE_BETAFLIGHT && sysConfig.firmware >= 2.8) {
1039+
else if(firmwareGreaterOrEqual(sysConfig, '2.8.0')) {
10231040

10241041
var that = this;
10251042

js/flightlog_parser.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,15 @@ var FlightLogParser = function(logData) {
490490
that.sysConfig.rcYawRate = parseInt(fieldValue, 10);
491491
break
492492
case "rc_expo":
493-
if(fieldValue.match(/.*,.*/)!=null) {
493+
if(stringHasComma(fieldValue)) {
494494
var expos = parseCommaSeparatedString(fieldValue);
495495
that.sysConfig[fieldName] = expos
496496
that.sysConfig.rcExpo = expos[0];
497-
that.sysConfig.rcYawExpo = expos[1];
497+
if (firmwareGreaterOrEqual(that.sysConfig, '3.3.0', '2.3.0')) {
498+
that.sysConfig.rcYawExpo = expos[2];
499+
} else {
500+
that.sysConfig.rcYawExpo = expos[1];
501+
}
498502
} else {
499503
that.sysConfig.rcExpo = parseInt(fieldValue, 10);
500504
}
@@ -588,7 +592,7 @@ var FlightLogParser = function(logData) {
588592
/** End of cleanflight only log headers **/
589593

590594
case "superExpoFactor":
591-
if(fieldValue.match(/.*,.*/)!=null) {
595+
if(stringHasComma(fieldValue)) {
592596
var expoParams = parseCommaSeparatedString(fieldValue);
593597
that.sysConfig.superExpoFactor = expoParams[0];
594598
that.sysConfig.superExpoFactorYaw = expoParams[1];
@@ -623,7 +627,11 @@ var FlightLogParser = function(logData) {
623627
var rc_rates = parseCommaSeparatedString(fieldValue);
624628
that.sysConfig[fieldName] = rc_rates
625629
that.sysConfig.rcRate = rc_rates[0];
626-
that.sysConfig.rcYawRate = rc_rates[1];
630+
if (firmwareGreaterOrEqual(that.sysConfig, '3.3.0', '2.3.0')) {
631+
that.sysConfig.rcYawRate = rc_rates[2];
632+
} else {
633+
that.sysConfig.rcYawRate = rc_rates[1];
634+
}
627635
break;
628636
case "magPID":
629637
that.sysConfig.magPID = parseCommaSeparatedString(fieldValue,3); //[parseInt(fieldValue, 10), null, null];

js/header_dialog.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ function HeaderDialog(dialog, onSave) {
5858
{name:'setpointRelaxRatio' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.1.0', max:'999.9.9'},
5959
{name:'antiGravityGain' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.1.0', max:'999.9.9'},
6060
{name:'antiGravityThreshold' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.1.0', max:'999.9.9'},
61-
{name:'itermWindupPointPercent' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.1.0', max:'999.9.9'},
62-
{name:'pidSumLimit' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.3.0', max:'999.9.9'},
61+
{name:'itermWindupPointPercent' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.1.0', max:'999.9.9'},
62+
{name:'pidSumLimit' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.3.0', max:'999.9.9'},
6363
{name:'pidSumLimitYaw' , type:FIRMWARE_TYPE_BETAFLIGHT, min:'3.3.0', max:'999.9.9'}
6464
];
6565

@@ -225,7 +225,7 @@ function HeaderDialog(dialog, onSave) {
225225
{bit: 16, group: 'other', name: 'LED_STRIP', description: 'Addressible RGB LED strip support'},
226226
{bit: 17, group: 'other', name: 'DISPLAY', description: 'OLED Screen Display'},
227227
{bit: 20, group: 'other', name: 'CHANNEL_FORWARDING', description: 'Forward aux channels to servo outputs'},
228-
{bit: 21, group: 'other', name: 'TRANSPONDER', description: 'Race Transponder'},
228+
{bit: 21, group: 'other', name: 'TRANSPONDER', description: 'Race Transponder'},
229229
];
230230

231231

js/tools.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ function memmem(haystack, needle, startIndex) {
102102
return -1;
103103
}
104104

105+
function stringHasComma(string) {
106+
/***
107+
* Checks if the string contains at least one comma.
108+
*
109+
* string is the string to check
110+
*
111+
* returns true if at least one comma is found.
112+
* false if no comma is found.
113+
***/
114+
return string.match(/.*,.*/) != null;
115+
}
116+
105117
function parseCommaSeparatedString(string, length) {
106118
/***
107119
* Parse a comma separated string for individual values.
@@ -416,4 +428,23 @@ var mouseNotification = {
416428

417429
return true;
418430
}
419-
};
431+
};
432+
433+
function firmwareGreaterOrEqual(sysConfig, bf_version, cf_version) {
434+
/***
435+
* Check if firmware version is higher or equal to requested version
436+
*
437+
* sysConfig System config structure
438+
* bf_version Betaflight version to check, e.g. '3.1.0' (string)
439+
* cf_version Cleanflight version to check, e.g. '2.3.0' (optional, string)
440+
*
441+
* returns True when firmware version is higher or equal to requested version
442+
* False when firmware version is lower than the requested version
443+
***/
444+
if (cf_version === undefined) {
445+
return (sysConfig.firmwareType == FIRMWARE_TYPE_BETAFLIGHT && semver.gte(sysConfig.firmwareVersion, bf_version));
446+
} else {
447+
return (sysConfig.firmwareType == FIRMWARE_TYPE_BETAFLIGHT && semver.gte(sysConfig.firmwareVersion, bf_version)) ||
448+
(sysConfig.firmwareType == FIRMWARE_TYPE_CLEANFLIGHT && semver.gte(sysConfig.firmwareVersion, cf_version));
449+
}
450+
}

0 commit comments

Comments
 (0)