Skip to content

Commit

Permalink
Use BATTERY_STATE for cellCount (#3964)
Browse files Browse the repository at this point in the history
* Use BATTERY_STATE for cellCount

* Remove outdated comments

* Use vbatcellcount instead of 1.8V condition
  • Loading branch information
haslinghuis authored May 20, 2024
1 parent 874e1ac commit c3cb9ce
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
16 changes: 6 additions & 10 deletions src/components/quad-status/BatteryIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
</div>
</template>
<script>
const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8; // Maybe is better to add a call to MSP_BATTERY_STATE but is not available for all versions
export default {
props: {
voltage: {
Expand All @@ -30,14 +28,14 @@ export default {
type: Number,
default: 1,
},
vbatcellcount: {
type: Number,
default: 1,
},
},
computed: {
nbCells() {
let nbCells = Math.floor(this.voltage / this.vbatmaxcellvoltage) + 1;
if (this.voltage === 0) {
nbCells = 1;
}
return nbCells;
return this.voltage === 0 || this.vbatcellcount === 0 ? 1 : this.vbatcellcount;
},
min() {
return this.vbatmincellvoltage * this.nbCells;
Expand All @@ -49,9 +47,7 @@ export default {
return this.vbatwarningcellvoltage * this.nbCells;
},
isEmpty() {
return (
this.voltage < this.min && this.voltage > NO_BATTERY_VOLTAGE_MAXIMUM
);
return this.voltage < this.min && !this.voltage.vbatcellcount;
},
classes() {
if (this.batteryState) {
Expand Down
16 changes: 6 additions & 10 deletions src/components/quad-status/BatteryLegend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
</div>
</template>
<script>
const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8; // Maybe is better to add a call to MSP_BATTERY_STATE but is not available for all versions
export default {
props: {
voltage: {
Expand All @@ -16,17 +14,15 @@ export default {
type: Number,
default: 1,
},
vbatcellcount: {
type: Number,
default: 1,
},
},
computed: {
reading() {
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";
const nbCells = this.voltage === 0 || this.vbatcellcount === 0 ? 1 : this.vbatcellcount;
const cellsText = this.voltage && this.vbatcellcount ? `${nbCells}S` : "USB";
return `${this.voltage.toFixed(2)}V (${cellsText})`;
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
: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
3 changes: 2 additions & 1 deletion src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,9 @@ async function update_live_status() {

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

const nbCells = FC.ANALOG.voltage === 0 ? 1 : Math.floor(FC.ANALOG.voltage / FC.BATTERY_CONFIG.vbatmaxcellvoltage) + 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 Down
2 changes: 2 additions & 0 deletions src/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@
: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

0 comments on commit c3cb9ce

Please sign in to comment.