Skip to content

Commit

Permalink
Merge pull request #10471 from etracer65/current_meter_div0_fix
Browse files Browse the repository at this point in the history
Fix possible div-by-zero in current meter
  • Loading branch information
mikeller committed Oct 3, 2021
1 parent 4f41a95 commit 3827a62
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/sensors/current.c
Expand Up @@ -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);
Expand Down

0 comments on commit 3827a62

Please sign in to comment.