Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix battery values #500

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
"initialSetupInfoHead": {
"message": "Info"
},
"initialSetupBattery": {
"initialSetupBatteryVoltage": {
"message": "Battery voltage:"
},
"initialSetupBatteryDetectedCells": {
Expand Down Expand Up @@ -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": {
Expand Down
63 changes: 43 additions & 20 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions tabs/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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>
Expand Down
12 changes: 7 additions & 5 deletions tabs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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';
Expand All @@ -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);

Expand Down