1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 20:35:33 +03:00

Merge pull request #10471 from etracer65/current_meter_div0_fix

Fix possible div-by-zero in current meter
This commit is contained in:
Michael Keller 2021-01-12 20:08:53 +08:00
parent 4f41a952cd
commit 3827a62685

View file

@ -116,7 +116,7 @@ static int32_t currentMeterADCToCentiamps(const uint16_t src)
int32_t millivolts = ((uint32_t)src * getVrefMv()) / 4096;
// y=x/m+b m is scale in (mV/10A) and b is offset in (mA)
int32_t centiAmps = (millivolts * 10000 / (int32_t)config->scale + (int32_t)config->offset) / 10;
int32_t centiAmps = config->scale ? (millivolts * 10000 / (int32_t)config->scale + (int32_t)config->offset) / 10 : 0;
DEBUG_SET(DEBUG_CURRENT_SENSOR, 0, millivolts);
DEBUG_SET(DEBUG_CURRENT_SENSOR, 1, centiAmps);