mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-25 17:25:16 +03:00
Fix sensors and battery cellcount (#4221)
This commit is contained in:
parent
8826812bb4
commit
467b6cc9f7
5 changed files with 51 additions and 36 deletions
|
@ -10,6 +10,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8;
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
voltage: {
|
voltage: {
|
||||||
|
@ -28,14 +29,14 @@ export default {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 1,
|
default: 1,
|
||||||
},
|
},
|
||||||
vbatcellcount: {
|
|
||||||
type: Number,
|
|
||||||
default: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
nbCells() {
|
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() {
|
min() {
|
||||||
return this.vbatmincellvoltage * this.nbCells;
|
return this.vbatmincellvoltage * this.nbCells;
|
||||||
|
@ -47,7 +48,7 @@ export default {
|
||||||
return this.vbatwarningcellvoltage * this.nbCells;
|
return this.vbatwarningcellvoltage * this.nbCells;
|
||||||
},
|
},
|
||||||
isEmpty() {
|
isEmpty() {
|
||||||
return this.voltage < this.min && !this.voltage.vbatcellcount;
|
return this.voltage < this.min && this.voltage > NO_BATTERY_VOLTAGE_MAXIMUM;
|
||||||
},
|
},
|
||||||
classes() {
|
classes() {
|
||||||
if (this.batteryState) {
|
if (this.batteryState) {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8;
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
voltage: {
|
voltage: {
|
||||||
|
@ -14,15 +15,14 @@ export default {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 1,
|
default: 1,
|
||||||
},
|
},
|
||||||
vbatcellcount: {
|
|
||||||
type: Number,
|
|
||||||
default: 1,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
reading() {
|
reading() {
|
||||||
const nbCells = this.voltage === 0 || this.vbatcellcount === 0 ? 1 : this.vbatcellcount;
|
let nbCells = Math.floor(this.voltage / this.vbatmaxcellvoltage) + 1;
|
||||||
const cellsText = this.voltage && this.vbatcellcount ? `${nbCells}S` : "USB";
|
if (this.voltage === 0) {
|
||||||
|
nbCells = 1;
|
||||||
|
}
|
||||||
|
const cellsText = this.voltage > NO_BATTERY_VOLTAGE_MAXIMUM ? `${nbCells}S` : "USB";
|
||||||
return `${this.voltage.toFixed(2)}V (${cellsText})`;
|
return `${this.voltage.toFixed(2)}V (${cellsText})`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,13 +42,11 @@
|
||||||
:vbatmaxcellvoltage="FC.BATTERY_CONFIG.vbatmaxcellvoltage"
|
:vbatmaxcellvoltage="FC.BATTERY_CONFIG.vbatmaxcellvoltage"
|
||||||
:vbatwarningcellvoltage="FC.BATTERY_CONFIG.vbatwarningcellvoltage"
|
:vbatwarningcellvoltage="FC.BATTERY_CONFIG.vbatwarningcellvoltage"
|
||||||
:batteryState="FC.BATTERY_STATE?.batteryState"
|
:batteryState="FC.BATTERY_STATE?.batteryState"
|
||||||
:vbatcellcount="FC.BATTERY_STATE?.cellCount"
|
|
||||||
>
|
>
|
||||||
</battery-icon>
|
</battery-icon>
|
||||||
<battery-legend
|
<battery-legend
|
||||||
:voltage="FC.ANALOG.voltage"
|
:voltage="FC.ANALOG.voltage"
|
||||||
:vbatmaxcellvoltage="FC.BATTERY_CONFIG.vbatmaxcellvoltage"
|
:vbatmaxcellvoltage="FC.BATTERY_CONFIG.vbatmaxcellvoltage"
|
||||||
:vbatcellcount="FC.BATTERY_STATE?.cellCount"
|
|
||||||
></battery-legend>
|
></battery-legend>
|
||||||
<div class="bottomStatusIcons">
|
<div class="bottomStatusIcons">
|
||||||
<div class="armedicon cf_tip" i18n_title="mainHelpArmed"></div>
|
<div class="armedicon cf_tip" i18n_title="mainHelpArmed"></div>
|
||||||
|
|
|
@ -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');
|
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_ANALOG);
|
await MSP.promise(MSPCodes.MSP_BATTERY_STATE);
|
||||||
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 min = FC.BATTERY_CONFIG.vbatmincellvoltage * nbCells;
|
||||||
const max = FC.BATTERY_CONFIG.vbatmaxcellvoltage * nbCells;
|
const max = FC.BATTERY_CONFIG.vbatmaxcellvoltage * nbCells;
|
||||||
const warn = FC.BATTERY_CONFIG.vbatwarningcellvoltage * nbCells;
|
const warn = FC.BATTERY_CONFIG.vbatwarningcellvoltage * nbCells;
|
||||||
|
@ -729,29 +734,36 @@ async function update_live_status() {
|
||||||
$(".battery-status").addClass('state-ok').removeClass('state-warning').removeClass('state-empty');
|
$(".battery-status").addClass('state-ok').removeClass('state-warning').removeClass('state-empty');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await MSP.promise(MSPCodes.MSP_BOXNAMES);
|
await MSP.promise(MSPCodes.MSP_BOXNAMES);
|
||||||
await MSP.promise(MSPCodes.MSP_STATUS_EX);
|
await MSP.promise(MSPCodes.MSP_STATUS_EX);
|
||||||
|
|
||||||
const active = (performance.now() - FC.ANALOG.last_received_timestamp) < 300;
|
const active = (performance.now() - FC.ANALOG.last_received_timestamp) < 300;
|
||||||
$(".linkicon").toggleClass('active', active);
|
$(".linkicon").toggleClass('active', active);
|
||||||
|
|
||||||
for (let i = 0; i < FC.AUX_CONFIG.length; i++) {
|
for (let i = 0; i < FC.AUX_CONFIG.length; i++) {
|
||||||
if (FC.AUX_CONFIG[i] === 'ARM') {
|
if (FC.AUX_CONFIG[i] === 'ARM') {
|
||||||
$(".armedicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
|
$(".armedicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
|
||||||
}
|
|
||||||
if (FC.AUX_CONFIG[i] === 'FAILSAFE') {
|
|
||||||
$(".failsafeicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (FC.AUX_CONFIG[i] === 'FAILSAFE') {
|
||||||
if (have_sensor(FC.CONFIG.activeSensors, 'gps')) {
|
$(".failsafeicon").toggleClass('active', bit_check(FC.CONFIG.mode, i));
|
||||||
await MSP.promise(MSPCodes.MSP_RAW_GPS);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sensor_status(FC.CONFIG.activeSensors, FC.GPS_DATA.fix);
|
if (have_sensor(FC.CONFIG.activeSensors, 'gps')) {
|
||||||
|
await MSP.promise(MSPCodes.MSP_RAW_GPS);
|
||||||
|
}
|
||||||
|
|
||||||
statuswrapper.show();
|
sensor_status(FC.CONFIG.activeSensors, FC.GPS_DATA.fix);
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -792,7 +804,7 @@ export function reinitializeConnection(callback) {
|
||||||
gui_log(i18n.getMessage('deviceReady'));
|
gui_log(i18n.getMessage('deviceReady'));
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
|
||||||
if (callback) {
|
if (callback && typeof callback === 'function') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import FC from '../../js/fc';
|
||||||
import CONFIGURATOR from '../../js/data_storage';
|
import CONFIGURATOR from '../../js/data_storage';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import FileSystem from '../../js/FileSystem';
|
import FileSystem from '../../js/FileSystem';
|
||||||
|
import { update_sensor_status } from '../../js/serial_backend';
|
||||||
|
|
||||||
import { favoritePresets } from './FavoritePresets';
|
import { favoritePresets } from './FavoritePresets';
|
||||||
import CliEngine from './CliEngine';
|
import CliEngine from './CliEngine';
|
||||||
|
@ -37,6 +38,9 @@ presets.initialize = function (callback) {
|
||||||
if (GUI.active_tab !== 'presets') {
|
if (GUI.active_tab !== 'presets') {
|
||||||
GUI.active_tab = 'presets';
|
GUI.active_tab = 'presets';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// after applying presets, update sensor status
|
||||||
|
update_sensor_status();
|
||||||
};
|
};
|
||||||
|
|
||||||
presets.readDom = function() {
|
presets.readDom = function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue