Add voltage and amperage scale calibration (#1439)

Add voltage and amperage scale calibration
10.7.0-preview
Michael Keller 2019-05-28 21:19:29 +12:00 committed by GitHub
commit 56e2ce600f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 299 additions and 32 deletions

View File

@ -3390,12 +3390,45 @@
"powerBatteryWarning": {
"message": "Warning Cell Voltage"
},
"powerCalibrationManagerButton": {
"message": "Calibration"
},
"powerCalibrationManagerHelp": {
"message": "To calibrate, use a multimeter to measure the actual voltage / current draw on your craft (with a battery plugged in), and enter the values below. Then, with the same battery still plugged in, click [Calibrate]."
},
"powerCalibrationManagerNote": {
"message": "<strong>Note:</strong> Before calibrating the scale make sure that divider and multiplier for voltage and offset for amperage is set properly.<br>Leaving the values at 0 will not apply calibration.</br><strong>Remember to remove propellers before plugging in a battery!</strong>"
},
"powerCalibrationManagerWarning": {
"message": "<span class=\"message-negative\">Warning:</span> The battery <span class=\"message-negative\">is not plugged in</span> or voltage and amperage meter sources are <span class=\"message-negative\">not set properly.</span> Make sure that the voltage and/or amperage are reading a value above 0. Otherwise you will not be able to calibrate using this tool."
},
"powerCalibrationManagerSourceNote": {
"message": "<span class=\"message-negative\">Warning:</span> Voltage and/or amperage meter sources <strong>have been changed but not saved.</strong> Please set the correct meter sources and save them before trying to calibrate."
},
"powerCalibrationSave": {
"message": "Calibrate"
},
"powerCalibrationApply": {
"message": "Apply Calibration"
},
"powerCalibrationDiscard": {
"message": "Discard Calibration"
},
"powerCalibrationConfirmHelp": {
"message": "New calibrated scales are shown here. <br>Applying them will set the scales but <strong>will not save them.</strong></br> <br>After saving make sure that the new voltage and current are correct.</br>"
},
"powerVoltageHead": {
"message": "Voltage Meter"
},
"powerVoltageValue": {
"message": "$1 V"
},
"powerVoltageCalibration": {
"message": "Measured Voltage"
},
"powerVoltageCalibratedScale": {
"message": "Calibrated Voltage Scale:"
},
"powerAmperageValue": {
"message": "$1 A"
},
@ -3541,6 +3574,12 @@
"powerAmperageOffset": {
"message": "Offset [mA]"
},
"powerAmperageCalibration": {
"message": "Measured Amperage"
},
"powerAmperageCalibratedScale": {
"message": "Calibrated Amperage Scale:"
},
"powerBatteryHead": {
"message": "Battery"

View File

@ -1019,7 +1019,7 @@ dialog {
background-color: #fff7cd;
border: 1px solid #ffe55f;
margin-bottom: 7px;
margin-top: 3px;
margin-top: 0px;
border-radius: 3px;
font-size: 11px;
font-family: 'open_sansregular', Arial;
@ -1359,6 +1359,10 @@ dialog {
box-shadow: inset 0px 1px 5px rgba(0, 0, 0, 0.35);
}
.margin-top5 {
margin-top: 5px;
}
.regular-button {
margin-top: 8px;
margin-bottom: 8px;

View File

@ -13,6 +13,13 @@ TABS.power.initialize = function (callback) {
//googleAnalytics.sendAppView('Power');
}
if (GUI.calibrationManager) {
GUI.calibrationManager.destroy();
}
if (GUI.calibrationManagerConfirmation) {
GUI.calibrationManagerConfirmation.destroy();
}
function load_status() {
MSP.send_message(MSPCodes.MSP_STATUS, false, false, load_voltage_meters);
}
@ -156,6 +163,12 @@ TABS.power.initialize = function (callback) {
$('input[name="amperagescale-' + index + '"]').val(currentDataSource[index].scale);
$('input[name="amperageoffset-' + index + '"]').val(currentDataSource[index].offset);
}
if(BATTERY_CONFIG.voltageMeterSource == 1 || BATTERY_CONFIG.currentMeterSource == 1 || BATTERY_CONFIG.currentMeterSource == 2) {
$('.calibration').show();
} else {
$('.calibration').hide();
}
}
function initDisplay() {
@ -233,11 +246,14 @@ TABS.power.initialize = function (callback) {
updateDisplay(VOLTAGE_METER_CONFIGS, CURRENT_METER_CONFIGS);
var batteryMeterType_e = $('select.batterymetersource');
var sourceschanged = false;
batteryMeterType_e.val(BATTERY_CONFIG.voltageMeterSource);
batteryMeterType_e.change(function () {
BATTERY_CONFIG.voltageMeterSource = parseInt($(this).val());
updateDisplay();
sourceschanged = true;
});
var currentMeterType_e = $('select.currentmetersource');
@ -246,6 +262,7 @@ TABS.power.initialize = function (callback) {
BATTERY_CONFIG.currentMeterSource = parseInt($(this).val());
updateDisplay();
sourceschanged = true;
});
function get_slow_data() {
@ -281,6 +298,128 @@ TABS.power.initialize = function (callback) {
}
//calibration manager
var calibrationconfirmed = false;
GUI.calibrationManager = new jBox('Modal', {
width: 400,
height: 230,
closeButton: 'title',
animation: false,
attach: $('#calibrationmanager'),
title: 'Calibration Manager',
content: $('#calibrationmanagercontent'),
onCloseComplete: function() {
if (!calibrationconfirmed) {
TABS.power.initialize();
}
},
});
GUI.calibrationManagerConfirmation = new jBox('Modal', {
width: 400,
height: 230,
closeButton: 'title',
animation: false,
attach: $('#calibrate'),
title: 'Calibration Manager Confirmation',
content: $('#calibrationmanagerconfirmcontent'),
onCloseComplete: function() {
GUI.calibrationManager.close();
},
});
$('a.calibrationmanager').click(function() {
if (BATTERY_CONFIG.voltageMeterSource == 1 && BATTERY_STATE.voltage > 0.1){
$('.vbatcalibration').show();
} else {
$('.vbatcalibration').hide();
}
if ((BATTERY_CONFIG.currentMeterSource == 1 || BATTERY_CONFIG.currentMeterSource == 2) && BATTERY_STATE.amperage > 0.1) {
$('.amperagecalibration').show();
} else {
$('.amperagecalibration').hide();
}
if (BATTERY_STATE.cellCount == 0) {
$('.vbatcalibration').hide();
$('.amperagecalibration').hide();
$('.calibrate').hide();
$('.nocalib').show();
} else {
$('.calibrate').show();
$('.nocalib').hide();
}
if (sourceschanged) {
$('.srcchange').show();
$('.vbatcalibration').hide();
$('.amperagecalibration').hide();
$('.calibrate').hide();
$('.nocalib').hide();
} else {
$('.srcchange').hide();
}
});
$('input[name="vbatcalibration"]').val(0);
$('input[name="amperagecalibration"]').val(0);
var vbatscalechanged = false;
var amperagescalechanged = false;
$('a.calibrate').click(function() {
if (BATTERY_CONFIG.voltageMeterSource == 1) {
var vbatcalibration = parseFloat($('input[name="vbatcalibration"]').val());
if (vbatcalibration != 0) {
var vbatnewscale = Math.round(VOLTAGE_METER_CONFIGS[0].vbatscale * (vbatcalibration / VOLTAGE_METERS[0].voltage));
if (vbatnewscale >= 10 && vbatnewscale <= 255) {
VOLTAGE_METER_CONFIGS[0].vbatscale = vbatnewscale;
vbatscalechanged = true;
}
}
}
var ampsource = BATTERY_CONFIG.currentMeterSource;
if (ampsource == 1 || ampsource == 2) {
var amperagecalibration = parseFloat($('input[name="amperagecalibration"]').val());
var amperageoffset = CURRENT_METER_CONFIGS[ampsource - 1].offset / 1000;
if (amperagecalibration != 0) {
if (CURRENT_METERS[ampsource - 1].amperage != amperageoffset && amperagecalibration != amperageoffset) {
var amperagenewscale = Math.round(CURRENT_METER_CONFIGS[ampsource - 1].scale *
((CURRENT_METERS[ampsource - 1].amperage - amperageoffset) / (amperagecalibration - amperageoffset)));
if (amperagenewscale > -16000 && amperagenewscale < 16000 && amperagenewscale != 0) {
CURRENT_METER_CONFIGS[ampsource - 1].scale = amperagenewscale;
amperagescalechanged = true;
}
}
}
}
if (vbatscalechanged || amperagescalechanged) {
if (vbatscalechanged) {
$('.vbatcalibration').show();
} else {
$('.vbatcalibration').hide();
}
if (amperagescalechanged) {
$('.amperagecalibration').show();
} else {
$('.amperagecalibration').hide();
}
$('output[name="vbatnewscale"').val(vbatnewscale);
$('output[name="amperagenewscale"').val(amperagenewscale);
$('a.applycalibration').click(function() {
calibrationconfirmed = true;
GUI.calibrationManagerConfirmation.close();
updateDisplay(VOLTAGE_METER_CONFIGS, CURRENT_METER_CONFIGS);
$('.calibration').hide();
});
$('a.discardcalibration').click(function() {
GUI.calibrationManagerConfirmation.close();
});
} else {
GUI.calibrationManagerConfirmation.close();
}
});
$('a.save').click(function () {
for (var index = 0; index < VOLTAGE_METER_CONFIGS.length; index++) {
VOLTAGE_METER_CONFIGS[index].vbatscale = parseInt($('input[name="vbatscale-' + index + '"]').val());
@ -298,42 +437,46 @@ TABS.power.initialize = function (callback) {
BATTERY_CONFIG.vbatwarningcellvoltage = parseFloat($('input[name="warningcellvoltage"]').val());
BATTERY_CONFIG.capacity = parseInt($('input[name="capacity"]').val());
function save_battery_config() {
MSP.send_message(MSPCodes.MSP_SET_BATTERY_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BATTERY_CONFIG), false, save_voltage_config);
}
function save_voltage_config() {
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
mspHelper.sendVoltageConfig(save_amperage_config);
} else {
MSP.send_message(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG), false, save_amperage_config);
}
}
function save_amperage_config() {
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
mspHelper.sendCurrentConfig(save_to_eeprom);
} else {
MSP.send_message(MSPCodes.MSP_SET_CURRENT_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_CURRENT_METER_CONFIG), false, save_to_eeprom);
}
}
function save_to_eeprom() {
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, save_completed);
}
function save_completed() {
GUI.log(i18n.getMessage('configurationEepromSaved'));
TABS.power.initialize();
}
save_battery_config();
save_power_config();
});
GUI.interval_add('setup_data_pull_slow', get_slow_data, 200, true); // 5hz
}
function save_power_config() {
function save_battery_config() {
MSP.send_message(MSPCodes.MSP_SET_BATTERY_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BATTERY_CONFIG), false, save_voltage_config);
}
function save_voltage_config() {
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
mspHelper.sendVoltageConfig(save_amperage_config);
} else {
MSP.send_message(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG), false, save_amperage_config);
}
}
function save_amperage_config() {
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
mspHelper.sendCurrentConfig(save_to_eeprom);
} else {
MSP.send_message(MSPCodes.MSP_SET_CURRENT_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_CURRENT_METER_CONFIG), false, save_to_eeprom);
}
}
function save_to_eeprom() {
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, save_completed);
}
function save_completed() {
GUI.log(i18n.getMessage('configurationEepromSaved'));
TABS.power.initialize();
}
save_battery_config();
}
function process_html() {
initDisplay();
@ -346,4 +489,11 @@ TABS.power.initialize = function (callback) {
TABS.power.cleanup = function (callback) {
if (callback) callback();
if (GUI.calibrationManager) {
GUI.calibrationManager.destroy();
}
if (GUI.calibrationManagerConfirmation) {
GUI.calibrationManagerConfirmation.destroy();
}
};

View File

@ -95,6 +95,9 @@
<div class="btn save_btn">
<a class="save" href="#" i18n="powerButtonSave"></a>
</div>
<div class="btn calibration">
<a class="calibrationmanager" id="calibrationmanager" href="#" i18n="powerCalibrationManagerButton" />
</div>
</div>
</div>
@ -207,3 +210,74 @@
</div>
</div>
</div>
<div class="tab-power" id="calibrationmanagercontent">
<div class = "note">
<div class="note_spacer">
<p i18n="powerCalibrationManagerHelp"></p>
</div>
</div>
<div class = "note">
<div class="note_spacer">
<p i18n="powerCalibrationManagerNote"></p>
</div>
</div>
<div class = "note nocalib">
<div class="note_spacer">
<p i18n="powerCalibrationManagerWarning"></p>
</div>
</div>
<div class = "note srcchange">
<div class="note_spacer">
<p i18n="powerCalibrationManagerSourceNote"></p>
</div>
</div>
<div class="vbatcalibration">
<div class="number">
<label> <input type="number" name="vbatcalibration" step="0.01" min="0" max="255" /> <span
i18n="powerVoltageCalibration"></span>
</label>
</div>
</div>
<div class="amperagecalibration">
<div class="number">
<label> <input type="number" name="amperagecalibration" step="0.01" min="0" max="255" /> <span
i18n="powerAmperageCalibration"></span>
</label>
</div>
</div>
<div class="default_btn margin-top5">
<a class="calibrate" id="calibrate" href="#" i18n="powerCalibrationSave" />
</div>
</div>
<div class="tab-power" id="calibrationmanagerconfirmcontent">
<div class = "note">
<div class="note_spacer">
<p i18n="powerCalibrationConfirmHelp"></p>
</div>
</div>
<div class="vbatcalibration">
<div class="number tab_title">
<label>
<span i18n="powerVoltageCalibratedScale"></span>
<output type="number" name="vbatnewscale"></output>
</label>
</div>
</div>
<div class="amperagecalibration">
<div class="number tab_title">
<label>
<span i18n="powerAmperageCalibratedScale"></span>
<output type="number" name="amperagenewscale"></output>
</label>
</div>
</div>
<div class="default_btn margin-top5">
<a class="applycalibration" id="applycalibration" href="#" i18n="powerCalibrationApply" />
</div>
<div class="default_btn">
<a class="discardcalibration" id="discardcalibration" href="#" i18n="powerCalibrationDiscard" />
</div>
</div>