Skip to content

Commit

Permalink
Merge pull request #2786 from PascalLuginbuehl/fix-battery-calibration
Browse files Browse the repository at this point in the history
fix: battery calibration in power tab
  • Loading branch information
blckmn committed Jan 31, 2022
2 parents 3018ac3 + 78c34ed commit 340087a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/js/tabs/power.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,14 @@ TABS.power.initialize = function (callback) {

let vbatscalechanged = false;
let amperagescalechanged = false;
let vbatnewscale = 0;
let amperagenewscale = 0;

$('a.calibrate').click(function() {
if (FC.BATTERY_CONFIG.voltageMeterSource == 1) {
const vbatcalibration = parseFloat($('input[name="vbatcalibration"]').val());
if (vbatcalibration != 0) {
const vbatnewscale = Math.round(FC.VOLTAGE_METER_CONFIGS[0].vbatscale * (vbatcalibration / FC.VOLTAGE_METERS[0].voltage));
vbatnewscale = Math.round(FC.VOLTAGE_METER_CONFIGS[0].vbatscale * (vbatcalibration / FC.VOLTAGE_METERS[0].voltage));
if (vbatnewscale >= 10 && vbatnewscale <= 255) {
FC.VOLTAGE_METER_CONFIGS[0].vbatscale = vbatnewscale;
vbatscalechanged = true;
Expand All @@ -413,7 +416,7 @@ TABS.power.initialize = function (callback) {
const amperageoffset = FC.CURRENT_METER_CONFIGS[ampsource - 1].offset / 1000;
if (amperagecalibration != 0) {
if (FC.CURRENT_METERS[ampsource - 1].amperage != amperageoffset && amperagecalibration != amperageoffset) {
const amperagenewscale = Math.round(FC.CURRENT_METER_CONFIGS[ampsource - 1].scale *
amperagenewscale = Math.round(FC.CURRENT_METER_CONFIGS[ampsource - 1].scale *
((FC.CURRENT_METERS[ampsource - 1].amperage - amperageoffset) / (amperagecalibration - amperageoffset)));
if (amperagenewscale > -16000 && amperagenewscale < 16000 && amperagenewscale != 0) {
FC.CURRENT_METER_CONFIGS[ampsource - 1].scale = amperagenewscale;
Expand Down

0 comments on commit 340087a

Please sign in to comment.