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

Fix possible div-by-zero in current meter

Prevents div-by-zero if current meter scale is set to 0. Can't prevent with parameter ranges because scale ranges from -16000 to 16000.
This commit is contained in:
Bruce Luckcuck 2021-01-10 10:43:35 -05:00
parent b19434c9cb
commit 175e6200b4

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);