Skip to content

Commit

Permalink
Fix sensors and battery cellcount
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Oct 23, 2024
1 parent 8826812 commit e741f7f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
13 changes: 7 additions & 6 deletions src/components/quad-status/BatteryIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</div>
</template>
<script>
const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8;
export default {
props: {
voltage: {
Expand All @@ -28,14 +29,14 @@ export default {
type: Number,
default: 1,
},
vbatcellcount: {
type: Number,
default: 1,
},
},
computed: {
nbCells() {
return this.voltage === 0 || this.vbatcellcount === 0 ? 1 : this.vbatcellcount;
let nbCells = Math.floor(this.voltage / this.vbatmaxcellvoltage) + 1;
if (this.voltage === 0) {
nbCells = 1;
}
return nbCells;
},
min() {
return this.vbatmincellvoltage * this.nbCells;
Expand All @@ -47,7 +48,7 @@ export default {
return this.vbatwarningcellvoltage * this.nbCells;
},
isEmpty() {
return this.voltage < this.min && !this.voltage.vbatcellcount;
return this.voltage < this.min && this.voltage > NO_BATTERY_VOLTAGE_MAXIMUM;
},
classes() {
if (this.batteryState) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/quad-status/BatteryLegend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</div>
</template>
<script>
const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8;
export default {
props: {
voltage: {
Expand All @@ -14,15 +15,14 @@ export default {
type: Number,
default: 1,
},
vbatcellcount: {
type: Number,
default: 1,
},
},
computed: {
reading() {
const nbCells = this.voltage === 0 || this.vbatcellcount === 0 ? 1 : this.vbatcellcount;
const cellsText = this.voltage && this.vbatcellcount ? `${nbCells}S` : "USB";
let nbCells = Math.floor(this.voltage / this.vbatmaxcellvoltage) + 1;
if (this.voltage === 0) {
nbCells = 1;
}
const cellsText = this.voltage > NO_BATTERY_VOLTAGE_MAXIMUM ? `${nbCells}S` : "USB";
return `${this.voltage.toFixed(2)}V (${cellsText})`;
},
},
Expand Down
2 changes: 0 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@
:vbatmaxcellvoltage="FC.BATTERY_CONFIG.vbatmaxcellvoltage"
:vbatwarningcellvoltage="FC.BATTERY_CONFIG.vbatwarningcellvoltage"
:batteryState="FC.BATTERY_STATE?.batteryState"
:vbatcellcount="FC.BATTERY_STATE?.cellCount"
>
</battery-icon>
<battery-legend
:voltage="FC.ANALOG.voltage"
:vbatmaxcellvoltage="FC.BATTERY_CONFIG.vbatmaxcellvoltage"
:vbatcellcount="FC.BATTERY_STATE?.cellCount"
></battery-legend>
<div class="bottomStatusIcons">
<div class="armedicon cf_tip" i18n_title="mainHelpArmed"></div>
Expand Down
56 changes: 34 additions & 22 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,14 +704,19 @@ export function read_serial(info) {
}
}

async function update_live_status() {
export async function update_sensor_status() {
const statuswrapper = $('#quad-status_wrapper');

if (GUI.active_tab !== 'cli' && GUI.active_tab !== 'presets') {
await MSP.promise(MSPCodes.MSP_ANALOG);
await MSP.promise(MSPCodes.MSP_BATTERY_STATE);
await MSP.promise(MSPCodes.MSP_ANALOG);
await MSP.promise(MSPCodes.MSP_BATTERY_STATE);

if (FC.ANALOG !== undefined) {
let nbCells = Math.floor(FC.ANALOG.voltage / FC.BATTERY_CONFIG.vbatmaxcellvoltage) + 1;

if (FC.ANALOG.voltage == 0) {
nbCells = 1;
}

const nbCells = FC.ANALOG.voltage === 0 || FC.BATTERY_STATE.cellCount === 0 ? 1 : FC.BATTERY_STATE.cellCount;
const min = FC.BATTERY_CONFIG.vbatmincellvoltage * nbCells;
const max = FC.BATTERY_CONFIG.vbatmaxcellvoltage * nbCells;
const warn = FC.BATTERY_CONFIG.vbatwarningcellvoltage * nbCells;
Expand All @@ -729,29 +734,36 @@ async function update_live_status() {
$(".battery-status").addClass('state-ok').removeClass('state-warning').removeClass('state-empty');
}
}
}

await MSP.promise(MSPCodes.MSP_BOXNAMES);
await MSP.promise(MSPCodes.MSP_STATUS_EX);
await MSP.promise(MSPCodes.MSP_BOXNAMES);
await MSP.promise(MSPCodes.MSP_STATUS_EX);

const active = (performance.now() - FC.ANALOG.last_received_timestamp) < 300;
$(".linkicon").toggleClass('active', active);
const active = (performance.now() - FC.ANALOG.last_received_timestamp) < 300;
$(".linkicon").toggleClass('active', active);

for (let i = 0; i < FC.AUX_CONFIG.length; i++) {
if (FC.AUX_CONFIG[i] === 'ARM') {
$(".armedicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
}
if (FC.AUX_CONFIG[i] === 'FAILSAFE') {
$(".failsafeicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
}
for (let i = 0; i < FC.AUX_CONFIG.length; i++) {
if (FC.AUX_CONFIG[i] === 'ARM') {
$(".armedicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
}

if (have_sensor(FC.CONFIG.activeSensors, 'gps')) {
await MSP.promise(MSPCodes.MSP_RAW_GPS);
if (FC.AUX_CONFIG[i] === 'FAILSAFE') {
$(".failsafeicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
}
}

if (have_sensor(FC.CONFIG.activeSensors, 'gps')) {
await MSP.promise(MSPCodes.MSP_RAW_GPS);
}

sensor_status(FC.CONFIG.activeSensors, FC.GPS_DATA.fix);
sensor_status(FC.CONFIG.activeSensors, FC.GPS_DATA.fix);

statuswrapper.show();
statuswrapper.show();
}

async function update_live_status() {
// cli or presets tab do not use MSP connection
if (GUI.active_tab !== 'cli' && GUI.active_tab !== 'presets') {
await update_sensor_status();
}
}

Expand Down Expand Up @@ -792,7 +804,7 @@ export function reinitializeConnection(callback) {
gui_log(i18n.getMessage('deviceReady'));
}, 2000);

if (callback) {
if (callback && typeof callback === 'function') {
callback();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/tabs/presets/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FC from '../../js/fc';
import CONFIGURATOR from '../../js/data_storage';
import $ from 'jquery';
import FileSystem from '../../js/FileSystem';
import { update_sensor_status } from '../../js/serial_backend';

import { favoritePresets } from './FavoritePresets';
import CliEngine from './CliEngine';
Expand Down Expand Up @@ -37,6 +38,9 @@ presets.initialize = function (callback) {
if (GUI.active_tab !== 'presets') {
GUI.active_tab = 'presets';
}

// after applying presets, update sensor status
update_sensor_status();
};

presets.readDom = function() {
Expand Down

0 comments on commit e741f7f

Please sign in to comment.