1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-16 04:45:18 +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

@ -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,7 +2550,10 @@ var mspHelper = (function (gui) {
};
self.queryFcStatus = function (callback) {
MSP.send_message(MSPCodes.MSP_STATUS_EX, false, false, 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);
};
self.loadMisc = function (callback) {

View file

@ -123,7 +123,12 @@ helper.periodicStatusUpdater = (function () {
MSP.send_message(MSPCodes.MSP_SENSOR_STATUS, false, false);
}
MSP.send_message(MSPCodes.MSP_STATUS_EX, 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')) {