Skip to content

Commit

Permalink
Several fixes for compatibility with BF 3.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
basdelfos committed Jul 30, 2017
1 parent 192b3f1 commit 63af808
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 41 deletions.
39 changes: 39 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,45 @@
"configurationMagHardware": {
"message": "Magnetometer (if supported)"
},
// ---------------------------------------------
// Remove this when we officialy retire BF 3.1.x
"configurationBatteryVoltage": {
"message": "Battery Voltage"
},
"configurationBatteryCurrent": {
"message": "Battery Current"
},
"configurationBatteryMeterType": {
"message": "Battery Meter Type"
},
"configurationBatteryMinimum": {
"message": "Minimum Cell Voltage"
},
"configurationBatteryMaximum": {
"message": "Maximum Cell Voltage"
},
"configurationBatteryWarning": {
"message": "Warning Cell Voltage"
},
"configurationBatteryScale": {
"message": "Voltage Scale"
},
"configurationCurrentMeterType": {
"message": "Current Meter Type"
},
"configurationCurrent": {
"message": "Current Sensor"
},
"configurationCurrentScale": {
"message": "Scale the output voltage to milliamps [1/10th mV/A]"
},
"configurationCurrentOffset": {
"message": "Offset in millivolt steps"
},
"configurationBatteryMultiwiiCurrent": {
"message": "Enable support for legacy Multiwii MSP current output"
},
// --------------------------------------------- END
"pidTuningProfile": {
"message": "Profile"
},
Expand Down
9 changes: 9 additions & 0 deletions js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// define all the global variables that are uses to hold FC state
var CONFIG;
var BF_CONFIG; // Remove when we officialy retire BF 3.1
var FEATURE_CONFIG;
var BEEPER_CONFIG;
var MIXER_CONFIG;
Expand Down Expand Up @@ -79,6 +80,13 @@ var FC = {
boardType: 0,
};

BF_CONFIG = {
currentscale: 0,
currentoffset: 0,
currentmetertype: 0,
batterycapacity: 0,
};

FEATURE_CONFIG = {
features: 0,
};
Expand Down Expand Up @@ -228,6 +236,7 @@ var FC = {
vbatmincellvoltage: 0,
vbatmaxcellvoltage: 0,
vbatwarningcellvoltage: 0,
batterymetertype: 1, // 1=ADC, 2=ESC
};
MOTOR_CONFIG = {
minthrottle: 0,
Expand Down
96 changes: 57 additions & 39 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
}
break;
case MSPCodes.MSP_CURRENT_METERS:

CURRENT_METERS = [];
var currentMeterLength = 5;
for (var i = 0; i < (data.byteLength / currentMeterLength); i++) {
Expand All @@ -192,46 +193,63 @@ MspHelper.prototype.process_data = function(dataHandler) {
break;

case MSPCodes.MSP_VOLTAGE_METER_CONFIG:
VOLTAGE_METER_CONFIGS = [];
var voltage_meter_count = data.readU8();

for (var i = 0; i < voltage_meter_count; i++) {
var subframe_length = data.readU8();
if (subframe_length != 5) {
for (var j = 0; j < subframe_length; j++) {
data.readU8();
if (semver.lt(CONFIG.apiVersion, "1.36.0")) {
MISC.vbatscale = data.readU8(); // 10-200
MISC.vbatmincellvoltage = data.readU8() / 10; // 10-50
MISC.vbatmaxcellvoltage = data.readU8() / 10; // 10-50
MISC.vbatwarningcellvoltage = data.readU8() / 10; // 10-50
if (semver.gte(CONFIG.apiVersion, "1.23.0")) {
MISC.batterymetertype = data.readU8();
}
} else {
VOLTAGE_METER_CONFIGS = [];
var voltage_meter_count = data.readU8();

for (var i = 0; i < voltage_meter_count; i++) {
var subframe_length = data.readU8();
if (subframe_length != 5) {
for (var j = 0; j < subframe_length; j++) {
data.readU8();
}
} else {
var voltageMeterConfig = {};
voltageMeterConfig.id = data.readU8();
voltageMeterConfig.sensorType = data.readU8();
voltageMeterConfig.vbatscale = data.readU8();
voltageMeterConfig.vbatresdivval = data.readU8();
voltageMeterConfig.vbatresdivmultiplier = data.readU8();

VOLTAGE_METER_CONFIGS.push(voltageMeterConfig);
}
} else {
var voltageMeterConfig = {};
voltageMeterConfig.id = data.readU8();
voltageMeterConfig.sensorType = data.readU8();
voltageMeterConfig.vbatscale = data.readU8();
voltageMeterConfig.vbatresdivval = data.readU8();
voltageMeterConfig.vbatresdivmultiplier = data.readU8();

VOLTAGE_METER_CONFIGS.push(voltageMeterConfig);
}
}
break;
case MSPCodes.MSP_CURRENT_METER_CONFIG:
var offset = 0;
CURRENT_METER_CONFIGS = [];
var current_meter_count = data.readU8();
for (var i = 0; i < current_meter_count; i++) {
var currentMeterConfig = {};
var subframe_length = data.readU8();

if (subframe_length != 6) {
for (var j = 0; j < subframe_length; j++) {
data.readU8();
}
} else {
currentMeterConfig.id = data.readU8();
currentMeterConfig.sensorType = data.readU8();
currentMeterConfig.scale = data.readU16();
currentMeterConfig.offset = data.readU16();
if (semver.lt(CONFIG.apiVersion, "1.36.0")) {
BF_CONFIG.currentscale = data.read16();
BF_CONFIG.currentoffset = data.read16();
BF_CONFIG.currentmetertype = data.readU8();
BF_CONFIG.batterycapacity = data.readU16();
} else {
var offset = 0;
CURRENT_METER_CONFIGS = [];
var current_meter_count = data.readU8();
for (var i = 0; i < current_meter_count; i++) {
var currentMeterConfig = {};
var subframe_length = data.readU8();

if (subframe_length != 6) {
for (var j = 0; j < subframe_length; j++) {
data.readU8();
}
} else {
currentMeterConfig.id = data.readU8();
currentMeterConfig.sensorType = data.readU8();
currentMeterConfig.scale = data.readU16();
currentMeterConfig.offset = data.readU16();

CURRENT_METER_CONFIGS.push(currentMeterConfig);
CURRENT_METER_CONFIGS.push(currentMeterConfig);
}
}
}
break;
Expand Down Expand Up @@ -1273,19 +1291,19 @@ MspHelper.prototype.crunch = function(code) {
case MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG:
if (semver.lt(CONFIG.apiVersion, "1.36.0")) {
buffer.push8(MISC.vbatscale)
.push8(Math.round(BATTERY_CONFIG.vbatmincellvoltage * 10))
.push8(Math.round(BATTERY_CONFIG.vbatmaxcellvoltage * 10))
.push8(Math.round(BATTERY_CONFIG.vbatwarningcellvoltage * 10));
.push8(Math.round(MISC.vbatmincellvoltage * 10))
.push8(Math.round(MISC.vbatmaxcellvoltage * 10))
.push8(Math.round(MISC.vbatwarningcellvoltage * 10));
if (semver.gte(CONFIG.apiVersion, "1.23.0")) {
buffer.push8(BATTERY_CONFIG.voltageMeterSource);
buffer.push8(MISC.batterymetertype);
}
}
break;
case MSPCodes.MSP_SET_CURRENT_METER_CONFIG:
if (semver.lt(CONFIG.apiVersion, "1.36.0")) {
buffer.push16(BF_CONFIG.currentscale)
.push16(BF_CONFIG.currentoffset)
.push8(BATTERY_CONFIG.currentMeterSource)
.push8(BF_CONFIG.currentmetertype)
.push16(BF_CONFIG.batterycapacity)
}
break;
Expand Down
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,18 @@ function updateTabList(features) {
} else {
$('#tabs ul.mode-connected li.tab_transponder').hide();
}

if (features.isEnabled('OSD')) {
$('#tabs ul.mode-connected li.tab_osd').show();
} else {
$('#tabs ul.mode-connected li.tab_osd').hide();
}

if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
$('#tabs ul.mode-connected li.tab_power').show();
} else {
$('#tabs ul.mode-connected li.tab_power').hide();
}
}

function zeroPad(value, width) {
Expand Down
10 changes: 9 additions & 1 deletion tabs/configuration.css
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,21 @@
width: 150px;
}

.tab-configuration .currentMeterSource {
.tab-configuration .currentmetertype {
border: 1px solid silver;
margin-right: 5px;
float: left;
width: 150px;
}

.tab-configuration .vbatmonitoring {
margin-top: 5px;
}

.tab-configuration .currentMonitoring {
margin-top: 5px;
}

.tab-configuration .rssi td:nth-child(2) {
width: 30px;
}
Expand Down
139 changes: 139 additions & 0 deletions tabs/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,150 @@
</div>
</div>
</div>
<<<<<<< HEAD

</td>
</tr>
</table>

=======
</div>
</div>
<div class="clear-both"></div>
</div>


<!-- -------------------------------------------------------- -->
<!-- Remove this part when we officialy retire BF 3.1.x -->
<div class="rightWrapper current voltage oldBatteryConfig">
<div class="gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="configurationBatteryVoltage"></div>
</div>
<div class="spacer_box">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th i18n="configurationFeatureEnabled"></th>
<th i18n="configurationFeatureDescription"></th>
<th i18n="configurationFeatureName"></th>
</tr>
</thead>
<tbody class="features batteryVoltage">
<!-- table generated here -->
</tbody>
</table>
<div class="select batterymetertype vbatmonitoring">
<label>
<select class="batterymetertype"><!-- list generated here --></select>
<span i18n="configurationBatteryMeterType"></span>
</label>
</div>
<div class="number vbatmonitoring">
<label> <input type="number" name="mincellvoltage" step="0.1" min="1" max="5" /> <span
i18n="configurationBatteryMinimum"></span>
</label>
</div>
<div class="number vbatmonitoring">
<label> <input type="number" name="maxcellvoltage" step="0.1" min="1" max="5" /> <span
i18n="configurationBatteryMaximum"></span>
</label>
</div>
<div class="number vbatmonitoring">
<label> <input type="number" name="warningcellvoltage" step="0.1" min="1" max="5" /> <span
i18n="configurationBatteryWarning"></span>
</label>
</div>
<div class="number vbatmonitoring vbatCalibration">
<label> <input type="number" name="voltagescale" step="1" min="10" max="255" /> <span
i18n="configurationBatteryScale"></span>
</label>
</div>
<div class="number vbatmonitoring">
<label> <input type="text" name="batteryvoltage" readonly class="disabled" /> <span
i18n="configurationBatteryVoltage"></span>
</label>
</div>
</div>
</div>
<div class="gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="configurationCurrent"></div>
</div>
<div class="spacer_box">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th i18n="configurationFeatureEnabled"></th>
<th i18n="configurationFeatureDescription"></th>
<th i18n="configurationFeatureName"></th>
</tr>
</thead>
<tbody class="features batteryCurrent">
<!-- table generated here -->
</tbody>
</table>
<div class="select currentMonitoring">
<label>
<select class="currentmetertype"><!-- list generated here --></select>
<span i18n="configurationCurrentMeterType"></span>
</label>
</div>
<div class="number currentMonitoring currentCalibration">
<label> <input type="number" name="currentscale" step="1" min="-16000" max="16000" /> <span
i18n="configurationCurrentScale"></span>
</label>
</div>
<div class="number currentMonitoring currentCalibration">
<label> <input type="number" name="currentoffset" step="1" min="-1600" max="16000" /> <span
i18n="configurationCurrentOffset"></span>
</label>
</div>
<div class="number currentMonitoring currentOutput">
<label>
<input type="text" name="batterycurrent" readonly class="disabled" /> <span
i18n="configurationBatteryCurrent"></span>
</label>
</div>
<div class="checkbox currentMonitoring currentOutput">
<div class="numberspacer">
<input type="checkbox" name="multiwiicurrentoutput" class="toggle" />
</div>
<label> <span i18n="configurationBatteryMultiwiiCurrent"></span>
</label>
</div>
</div>
</div>
</div>
<!-- -------------------------------------------------------- -->

<div class="leftWrapper beepers" style="width: calc(100% - 20px);">
<div class="gui_box grey" style="margin-top:10px;">
<div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="configurationBeeper"></div>
</div>
<div class="spacer_box">
<table cellpadding="0" cellspacing="0">
<tbody class="beeper-configuration" id="noline">
<tr class="beeper-template" style="display:none">
<td>
<input class="beeper toggle" id="" name="" title="" type="checkbox" />
</td>
<td>
<label for=""></label>
</td>
<td>
<span i18n=""></span>
</td>
</tr>
<!-- table generated here -->
</tbody>
</table>
</div>
</div>
</div>
<div class="clear-both"></div>
>>>>>>> Several fixes for compatibility with BF 3.1.x
<div class="content_toolbar">
<div class="btn save_btn">
<a class="save" href="#" i18n="configurationButtonSave"></a>
Expand Down
Loading

0 comments on commit 63af808

Please sign in to comment.