mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-15 12:25:13 +03:00
Fix battery values
Allow negative values of power, mAh drawn and mWh drawn
This commit is contained in:
parent
8331b7d034
commit
2ee946c358
4 changed files with 67 additions and 32 deletions
|
@ -406,7 +406,7 @@
|
|||
"initialSetupInfoHead": {
|
||||
"message": "Info"
|
||||
},
|
||||
"initialSetupBattery": {
|
||||
"initialSetupBatteryVoltage": {
|
||||
"message": "Battery voltage:"
|
||||
},
|
||||
"initialSetupBatteryDetectedCells": {
|
||||
|
@ -445,19 +445,25 @@
|
|||
"initialSetup_Wh_drawnValue": {
|
||||
"message": "$1 Wh"
|
||||
},
|
||||
"initialSetupBatteryValue": {
|
||||
"initialSetupBatteryVoltageValue": {
|
||||
"message": "$1 V"
|
||||
},
|
||||
"initialSetupDrawn": {
|
||||
"message": "Capacity drawn:"
|
||||
},
|
||||
"initialSetupDrawing": {
|
||||
"initialSetupCurrentDraw": {
|
||||
"message": "Current draw:"
|
||||
},
|
||||
"initialSetupPowerDraw": {
|
||||
"message": "Power draw:"
|
||||
},
|
||||
"initialSetupPowerDrawValue": {
|
||||
"message": "$1 W"
|
||||
},
|
||||
"initialSetupBatteryMahValue": {
|
||||
"message": "$1 mAh"
|
||||
},
|
||||
"initialSetupBatteryAValue": {
|
||||
"initialSetupCurrentDrawValue": {
|
||||
"message": "$1 A"
|
||||
},
|
||||
"initialSetupRSSI": {
|
||||
|
|
|
@ -251,26 +251,49 @@ var mspHelper = (function (gui) {
|
|||
ANALOG.amperage = data.getInt16(5, true) / 100; // A
|
||||
break;
|
||||
case MSPCodes.MSPV2_INAV_ANALOG:
|
||||
ANALOG.voltage = data.getUint16(offset, true) / 100.0;
|
||||
offset += 2;
|
||||
ANALOG.cell_count = data.getUint8(offset++);
|
||||
ANALOG.battery_percentage = data.getUint8(offset++);
|
||||
ANALOG.power = data.getUint16(offset, true);
|
||||
offset += 2;
|
||||
ANALOG.mAhdrawn = data.getUint16(offset, true);
|
||||
offset += 2;
|
||||
ANALOG.mWhdrawn = data.getUint16(offset, true);
|
||||
offset += 2;
|
||||
ANALOG.rssi = data.getUint16(offset, true); // 0-1023
|
||||
offset += 2;
|
||||
ANALOG.amperage = data.getInt16(offset, true) / 100; // A
|
||||
offset += 2;
|
||||
var battery_flags = data.getUint8(offset++);
|
||||
ANALOG.battery_full_when_plugged_in = (battery_flags & 1 ? true : false);
|
||||
ANALOG.use_capacity_thresholds = ((battery_flags & 2) >> 1 ? true : false);
|
||||
ANALOG.battery_state = (battery_flags & 12) >> 2;
|
||||
ANALOG.battery_remaining_capacity = data.getUint32(offset, true);
|
||||
offset += 4;
|
||||
if (semver.gte(CONFIG.flightControllerVersion, "2.0.0")) {
|
||||
var tmp = data.getUint8(offset++);
|
||||
ANALOG.battery_full_when_plugged_in = (tmp & 1 ? true : false);
|
||||
ANALOG.use_capacity_thresholds = ((tmp & 2) >> 1 ? true : false);
|
||||
ANALOG.battery_state = (tmp & 12) >> 2;
|
||||
ANALOG.cell_count = (tmp & 0xF0) >> 4;
|
||||
ANALOG.voltage = data.getUint16(offset, true) / 100.0;
|
||||
offset += 2;
|
||||
ANALOG.amperage = data.getInt16(offset, true) / 100; // A
|
||||
offset += 2;
|
||||
ANALOG.power = data.getInt32(offset, true) / 100.0;
|
||||
offset += 4;
|
||||
ANALOG.mAhdrawn = data.getInt32(offset, true);
|
||||
offset += 4;
|
||||
ANALOG.mWhdrawn = data.getInt32(offset, true);
|
||||
offset += 4;
|
||||
ANALOG.battery_remaining_capacity = data.getUint32(offset, true);
|
||||
offset += 4;
|
||||
ANALOG.battery_percentage = data.getUint8(offset++);
|
||||
ANALOG.rssi = data.getUint16(offset, true); // 0-1023
|
||||
offset += 2;
|
||||
} else {
|
||||
ANALOG.voltage = data.getUint16(offset, true) / 100.0;
|
||||
offset += 2;
|
||||
ANALOG.cell_count = data.getUint8(offset++);
|
||||
ANALOG.battery_percentage = data.getUint8(offset++);
|
||||
ANALOG.power = data.getUint16(offset, true);
|
||||
offset += 2;
|
||||
ANALOG.mAhdrawn = data.getUint16(offset, true);
|
||||
offset += 2;
|
||||
ANALOG.mWhdrawn = data.getUint16(offset, true);
|
||||
offset += 2;
|
||||
ANALOG.rssi = data.getUint16(offset, true); // 0-1023
|
||||
offset += 2;
|
||||
ANALOG.amperage = data.getInt16(offset, true) / 100; // A
|
||||
offset += 2;
|
||||
var battery_flags = data.getUint8(offset++);
|
||||
ANALOG.battery_full_when_plugged_in = (battery_flags & 1 ? true : false);
|
||||
ANALOG.use_capacity_thresholds = ((battery_flags & 2) >> 1 ? true : false);
|
||||
ANALOG.battery_state = (battery_flags & 12) >> 2;
|
||||
ANALOG.battery_remaining_capacity = data.getUint32(offset, true);
|
||||
offset += 4;
|
||||
}
|
||||
//noinspection JSValidateTypes
|
||||
dataHandler.analog_last_received_timestamp = Date.now();
|
||||
break;
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
<td class="bat-cells">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-i18n="initialSetupBattery"></td>
|
||||
<td data-i18n="initialSetupBatteryVoltage"></td>
|
||||
<td class="bat-voltage">0 V</td>
|
||||
</tr>
|
||||
<tr class="requires-v1_8_1">
|
||||
|
@ -114,8 +114,12 @@
|
|||
<td class="bat-thresh">0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-i18n="initialSetupDrawing"></td>
|
||||
<td class="bat-mah-drawing">0.00 A</td>
|
||||
<td data-i18n="initialSetupCurrentDraw"></td>
|
||||
<td class="bat-current-draw">0.00 A</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-i18n="initialSetupPowerDraw"></td>
|
||||
<td class="bat-power-draw">0.00 W</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td data-i18n="initialSetupDrawn"></td>
|
||||
|
|
|
@ -93,8 +93,9 @@ TABS.setup.initialize = function (callback) {
|
|||
bat_thresh_e = $('.bat-thresh'),
|
||||
bat_full_e = $('.bat-full'),
|
||||
bat_mah_drawn_e = $('.bat-mah-drawn'),
|
||||
bat_mwh_drawn_e = $('.bat-mwh-drawn'),
|
||||
bat_mah_drawing_e = $('.bat-mah-drawing'),
|
||||
bat_wh_drawn_e = $('.bat-mwh-drawn'),
|
||||
bat_current_draw_e = $('.bat-current-draw'),
|
||||
bat_power_draw_e = $('.bat-power-draw'),
|
||||
rssi_e = $('.rssi'),
|
||||
gpsFix_e = $('.gpsFixType'),
|
||||
gpsSats_e = $('.gpsSats'),
|
||||
|
@ -155,7 +156,7 @@ TABS.setup.initialize = function (callback) {
|
|||
|
||||
helper.interval.add('gui_analog_update', function () {
|
||||
bat_cells_e.text(chrome.i18n.getMessage('initialSetupBatteryDetectedCellsValue', [ANALOG.cell_count]));
|
||||
bat_voltage_e.text(chrome.i18n.getMessage('initialSetupBatteryValue', [ANALOG.voltage]));
|
||||
bat_voltage_e.text(chrome.i18n.getMessage('initialSetupBatteryVoltageValue', [ANALOG.voltage]));
|
||||
remaining_capacity_wh_decimals = ANALOG.battery_remaining_capacity.toString().length < 5 ? 3 : (7 - ANALOG.battery_remaining_capacity.toString().length);
|
||||
remaining_capacity_value = MISC.battery_capacity_unit == 'mAh' ? ANALOG.battery_remaining_capacity : (ANALOG.battery_remaining_capacity / 1000).toFixed(remaining_capacity_wh_decimals < 0 ? 0 : remaining_capacity_wh_decimals);
|
||||
remaining_capacity_unit = MISC.battery_capacity_unit == 'mAh' ? 'mAh' : 'Wh';
|
||||
|
@ -165,8 +166,9 @@ TABS.setup.initialize = function (callback) {
|
|||
bat_thresh_e.text(chrome.i18n.getMessage('initialSetupBatteryThresholdsValue', [ANALOG.use_capacity_thresholds]));
|
||||
bat_mah_drawn_e.text(chrome.i18n.getMessage('initialSetupBatteryMahValue', [ANALOG.mAhdrawn]));
|
||||
capacity_drawn_decimals = ANALOG.mWhdrawn.toString().length < 5 ? 3 : (7 - ANALOG.mWhdrawn.toString().length);
|
||||
bat_mwh_drawn_e.text(chrome.i18n.getMessage('initialSetup_Wh_drawnValue', [(ANALOG.mWhdrawn / 1000).toFixed(capacity_drawn_decimals < 0 ? 0 : capacity_drawn_decimals)]));
|
||||
bat_mah_drawing_e.text(chrome.i18n.getMessage('initialSetupBatteryAValue', [ANALOG.amperage.toFixed(2)]));
|
||||
bat_wh_drawn_e.text(chrome.i18n.getMessage('initialSetup_Wh_drawnValue', [(ANALOG.mWhdrawn / 1000).toFixed(capacity_drawn_decimals < 0 ? 0 : capacity_drawn_decimals)]));
|
||||
bat_current_draw_e.text(chrome.i18n.getMessage('initialSetupCurrentDrawValue', [ANALOG.amperage.toFixed(2)]));
|
||||
bat_power_draw_e.text(chrome.i18n.getMessage('initialSetupPowerDrawValue', [ANALOG.power.toFixed(2)]));
|
||||
rssi_e.text(chrome.i18n.getMessage('initialSetupRSSIValue', [((ANALOG.rssi / 1023) * 100).toFixed(0)]));
|
||||
}, 100, true);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue