1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-14 03:49:53 +03:00

Add support for battery profiles

This commit is contained in:
Michel Pastor 2018-06-15 16:42:00 +02:00
parent a1b807fc4b
commit e945c0749c
11 changed files with 131 additions and 8 deletions

View file

@ -705,6 +705,24 @@
"configurationBatteryCurrent": {
"message": "Battery Current"
},
"configurationVoltageSource": {
"message": "Voltage source to use for alarms and telemetry"
},
"configurationVoltageSourceHelp": {
"message": "Raw voltage is the voltage read directly from the battery. Sag compensated voltage is the calculated voltage the battery should be at without load (simulates ideal battery and should remove false alarms provoked by high loads)"
},
"configurationBatteryCells": {
"message": "Number of cells (0 = auto)"
},
"configurationBatteryCellsHelp": {
"message": "Set this to the number of cells of your battery to disable automatic cell count detection or to make the automatic switching of battery profiles possible"
},
"configurationBatteryCellDetectVoltage": {
"message": "Maximum cell voltage for cell count detection"
},
"configurationBatteryCellDetectVoltageHelp": {
"message": "Maximum cell voltage used for cell count autodetection. Should be higher than maximum cell voltage to take into account possible drift in measured voltage and keep cell count detection accurate"
},
"configurationBatteryMinimum": {
"message": "Minimum Cell Voltage"
},
@ -919,6 +937,9 @@
"pidTuningLoadedProfile": {
"message": "Loaded Profile: <strong style=\"color: #37a8db\">$1</strong>"
},
"loadedBatteryProfile": {
"message": "Loaded Battery Profile: <strong style=\"color: #37a8db\">$1</strong>"
},
"pidTuningDataRefreshed": {
"message": "PID data <strong>refreshed</strong>"
},

View file

@ -97,6 +97,7 @@ var FC = {
activeSensors: 0,
mode: [],
profile: 0,
battery_profile: 0,
uid: [0, 0, 0],
accelerometerTrims: [0, 0],
armingFlags: 0
@ -271,6 +272,7 @@ var FC = {
rssi_channel: 0,
placeholder2: 0,
mag_declination: 0, // not checked
battery_cells: 0,
vbatscale: 0,
vbatdetectcellvoltage: 0,
vbatmincellvoltage: 0,

View file

@ -202,6 +202,7 @@ GUI_control.prototype.updateStatusBar = function() {
GUI_control.prototype.updateProfileChange = function() {
$('#profilechange').val(CONFIG.profile);
$('#batteryprofilechange').val(CONFIG.battery_profile);
};
GUI_control.prototype.fillSelect = function ($element, values, currentValue, unit) {

View file

@ -180,4 +180,6 @@ var MSPCodes = {
MSP2_INAV_OSD_SET_ALARMS: 0x2015,
MSP2_INAV_OSD_PREFERENCES: 0x2016,
MSP2_INAV_OSD_SET_PREFERENCES: 0x2017,
MSP2_INAV_SELECT_BATTERY_PROFILE: 0x2018
};

View file

@ -121,6 +121,24 @@ var mspHelper = (function (gui) {
gui.updateProfileChange();
break;
case MSPCodes.MSPV2_INAV_STATUS:
CONFIG.cycleTime = data.getUint16(offset, true);
offset += 2;
CONFIG.i2cError = data.getUint16(offset, true);
offset += 2;
CONFIG.activeSensors = data.getUint16(offset, true);
offset += 2;
CONFIG.cpuload = data.getUint16(offset, true);
offset += 2;
profile_byte = data.getUint8(offset++)
CONFIG.profile = profile_byte & 0x0F;
CONFIG.battery_profile = (profile_byte & 0xF0) >> 4;
CONFIG.armingFlags = data.getUint32(offset, true);
offset += 4;
gui.updateStatusBar();
gui.updateProfileChange();
break;
case MSPCodes.MSP_ACTIVEBOXES:
var words = dataHandler.message_length_expected / 4;
@ -356,6 +374,8 @@ var mspHelper = (function (gui) {
MISC.vbatscale = data.getUint16(offset, true);
offset += 2;
if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) {
MISC.voltage_source = data.getUint8(offset++);
MISC.battery_cells = data.getUint8(offset++);
MISC.vbatdetectcellvoltage = data.getUint16(offset, true) / 100;
offset += 2;
}
@ -377,6 +397,8 @@ var mspHelper = (function (gui) {
BATTERY_CONFIG.vbatscale = data.getUint16(offset, true);
offset += 2;
if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) {
BATTERY_CONFIG.voltage_source = data.getUint8(offset++);
BATTERY_CONFIG.battery_cells = data.getUint8(offset++);
BATTERY_CONFIG.vbatdetectcellvoltage = data.getUint16(offset, true) / 100;
offset += 2;
}
@ -1499,6 +1521,8 @@ var mspHelper = (function (gui) {
buffer.push(lowByte(MISC.vbatscale));
buffer.push(highByte(MISC.vbatscale));
if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) {
buffer.push(MISC.voltage_source);
buffer.push(MISC.battery_cells);
buffer.push(lowByte(Math.round(MISC.vbatdetectcellvoltage * 100)));
buffer.push(highByte(Math.round(MISC.vbatdetectcellvoltage * 100)));
}
@ -1520,6 +1544,8 @@ var mspHelper = (function (gui) {
buffer.push(lowByte(BATTERY_CONFIG.vbatscale));
buffer.push(highByte(BATTERY_CONFIG.vbatscale));
if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) {
buffer.push(BATTERY_CONFIG.voltage_source);
buffer.push(BATTERY_CONFIG.battery_cells);
buffer.push(lowByte(Math.round(BATTERY_CONFIG.vbatdetectcellvoltage * 100)));
buffer.push(highByte(Math.round(BATTERY_CONFIG.vbatdetectcellvoltage * 100)));
}
@ -2524,6 +2550,9 @@ var mspHelper = (function (gui) {
};
self.queryFcStatus = function (callback) {
if (semver.gte(CONFIG.flightControllerVersion, '2.0.0'))
MSP.send_message(MSPCodes.MSPV2_INAV_STATUS, false, false, callback);
else
MSP.send_message(MSPCodes.MSP_STATUS_EX, false, false, callback);
};

View file

@ -123,7 +123,12 @@ helper.periodicStatusUpdater = (function () {
MSP.send_message(MSPCodes.MSP_SENSOR_STATUS, false, false);
}
if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) {
MSP.send_message(MSPCodes.MSPV2_INAV_STATUS, false, false);
} else {
MSP.send_message(MSPCodes.MSP_STATUS_EX, false, false);
}
MSP.send_message(MSPCodes.MSP_ACTIVEBOXES, false, false);
if (semver.gte(CONFIG.flightControllerVersion, '1.8.1')) {

View file

@ -1609,7 +1609,7 @@ dialog {
color: white;
font-size: 10px;
margin-top: 20px;
width: 125px;
width: 269px;
float: right;
margin-right: 10px;
line-height: 12px;
@ -1627,7 +1627,16 @@ dialog {
#profile_change {
color: white;
margin-top: 16px;
width: 125px;
width: 130px;
float: left;
margin-right: 0;
line-height: 12px;
}
#battery_profile_change {
color: white;
margin-top: 16px;
width: 130px;
float: right;
margin-right: 0;
line-height: 12px;

View file

@ -103,6 +103,18 @@
</form>
</div>
</div>
<div id="battery_profile_change">
<div class="dropdown dropdown-dark">
<form name="battery-profile-change" id="battery-profile-change">
<!--suppress HtmlFormInputWithoutLabel -->
<select class="dropdown-select" id="batteryprofilechange">
<option value="0">Battery profile 1</option>
<option value="1">Battery profile 2</option>
<option value="2">Battery profile 3</option>
</select>
</form>
</div>
</div>
</div>
<div id="sensor-status" class="sensor_state mode-connected">
<ul>

16
main.js
View file

@ -109,6 +109,12 @@ $(document).ready(function () {
var tab = tabClass.substring(4);
var tabName = $(self).text();
if (CONFIGURATOR.connectionValid && semver.lt(CONFIG.flightControllerVersion, "2.0.0")) {
$('#battery_profile_change').hide();
$('#profile_change').css('width', '125px');
$('#dataflash_wrapper_global').css('width', '125px');
}
if (tabRequiresConnection && !CONFIGURATOR.connectionValid) {
GUI.log(chrome.i18n.getMessage('tabSwitchConnectionRequired'));
return;
@ -412,6 +418,16 @@ $(document).ready(function () {
updateActivatedTab();
});
});
var batteryprofile_e = $('#batteryprofilechange');
batteryprofile_e.change(function () {
var batteryprofile = parseInt($(this).val());
MSP.send_message(MSPCodes.MSP2_INAV_SELECT_BATTERY_PROFILE, [batteryprofile], false, function () {
GUI.log(chrome.i18n.getMessage('loadedBatteryProfile', [batteryprofile + 1]));
updateActivatedTab();
});
});
});
function catch_startup_time(startTime) {

View file

@ -56,7 +56,7 @@
<label for="sensor-rangefinder"> <span data-i18n="sensorRangefinder"></span></label>
</div>
<div class="select requires-v2_0">
<div class="select requires-v2_0_0">
<select id="sensor-opflow"></select>
<label for="sensor-opflow"> <span data-i18n="sensorOpflow"></span></label>
</div>
@ -378,6 +378,26 @@
<div class="features batteryVoltage"></div>
<!--list of generated features goes here-->
<div class="select requires-v2_0_0">
<select id="voltagesource" class="voltagesource">
<option value="0">Raw</option>
<option value="1">Sag compensated</option>
</select>
<label for="voltagesource">
<span data-i18n="configurationVoltageSource"></span>
</label>
<div class="helpicon cf_tip" data-i18n_title="configurationVoltageSourceHelp"></div>
</div>
<div class="number requires-v2_0_0">
<input type="number" id="cells" name="cells" step="1" min="0" max="8" />
<label for="cells"><span data-i18n="configurationBatteryCells"></span></label>
<div class="helpicon cf_tip" data-i18n_title="configurationBatteryCellsHelp"></div>
</div>
<div class="number requires-v2_0_0">
<input type="number" id="celldetectvoltage" name="celldetectvoltage" step="0.01" min="1" max="5" />
<label for="celldetectvoltage"><span data-i18n="configurationBatteryCellDetectVoltage"></span></label>
<div class="helpicon cf_tip" data-i18n_title="configurationBatteryCellDetectVoltageHelp"></div>
</div>
<div class="number">
<input type="number" id="mincellvoltage" name="mincellvoltage" step="0.01" min="1" max="5" />
<label for="mincellvoltage"><span data-i18n="configurationBatteryMinimum"></span></label>

View file

@ -334,6 +334,9 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
// fill battery voltage
$('#voltagesource').val(MISC.voltage_source);
$('#cells').val(MISC.battery_cells);
$('#celldetectvoltage').val(MISC.vbatdetectcellvoltage);
$('#mincellvoltage').val(MISC.vbatmincellvoltage);
$('#maxcellvoltage').val(MISC.vbatmaxcellvoltage);
$('#warningcellvoltage').val(MISC.vbatwarningcellvoltage);
@ -590,9 +593,9 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) {
$(".requires-v2_0").show();
$(".requires-v2_0_0").show();
} else {
$(".requires-v2_0").hide();
$(".requires-v2_0_0").hide();
}
$('#3ddeadbandlow').val(_3D.deadband3d_low);
@ -666,6 +669,9 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
MISC.maxthrottle = parseInt($('#maxthrottle').val());
MISC.mincommand = parseInt($('#mincommand').val());
MISC.battery_cells = parseInt($('#cells').val());
MISC.voltage_source = parseInt($('#voltagesource').val());
MISC.vbatdetectcellvoltage = parseFloat($('#celldetectvoltage').val());
MISC.vbatmincellvoltage = parseFloat($('#mincellvoltage').val());
MISC.vbatmaxcellvoltage = parseFloat($('#maxcellvoltage').val());
MISC.vbatwarningcellvoltage = parseFloat($('#warningcellvoltage').val());