diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 378f30cc..5178fef7 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -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: $1" }, + "loadedBatteryProfile": { + "message": "Loaded Battery Profile: $1" + }, "pidTuningDataRefreshed": { "message": "PID data refreshed" }, diff --git a/js/fc.js b/js/fc.js index a4643b71..1c89f233 100644 --- a/js/fc.js +++ b/js/fc.js @@ -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, diff --git a/js/gui.js b/js/gui.js index 2f39332d..41e1d248 100644 --- a/js/gui.js +++ b/js/gui.js @@ -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) { diff --git a/js/msp/MSPCodes.js b/js/msp/MSPCodes.js index 9b5a3982..3f6b4237 100644 --- a/js/msp/MSPCodes.js +++ b/js/msp/MSPCodes.js @@ -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 }; diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 5fc95b12..424f6def 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -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) { diff --git a/js/periodicStatusUpdater.js b/js/periodicStatusUpdater.js index 24e870fb..f2e2f1b6 100644 --- a/js/periodicStatusUpdater.js +++ b/js/periodicStatusUpdater.js @@ -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')) { diff --git a/main.css b/main.css index b5de12da..85899c73 100644 --- a/main.css +++ b/main.css @@ -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; @@ -2035,4 +2044,4 @@ select { .text-center { text-align: center; -} \ No newline at end of file +} diff --git a/main.html b/main.html index 1934c27e..5cc80b9b 100755 --- a/main.html +++ b/main.html @@ -103,6 +103,18 @@ +