Skip to content

Commit

Permalink
Fix calibration (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
giedriuslt authored Jan 17, 2025
1 parent f4b50fe commit d0a056e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/driver/drv_pwrCal.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "drv_pwrCal.h"

#include <math.h>
#include "../cmnds/cmd_public.h"
#include "../logging/logging.h"
#include "../new_cfg.h"
Expand Down Expand Up @@ -33,10 +34,16 @@ static commandResult_t Calibrate(const char *cmd, const char *args, float raw,
#define VERY_SMALL_VAL 0.001f
if (raw > -VERY_SMALL_VAL && raw < VERY_SMALL_VAL) {
ADDLOG_ERROR(LOG_FEATURE_ENERGYMETER, "Calibration incorrect - connect load first.");
return CMD_RES_ERROR;
}


*cal = (cal_type == PWR_CAL_MULTIPLY ? real / raw : raw / real);
if (isnan(*cal) || ((*cal) > -VERY_SMALL_VAL && (*cal) < VERY_SMALL_VAL))
{
ADDLOG_ERROR(LOG_FEATURE_ENERGYMETER, "Calibration incorrect - value is zero");
return CMD_RES_ERROR;
}
CFG_SetPowerMeasurementCalibrationFloat(cfg_index, *cal);

#ifdef PWRCAL_DEBUG
Expand Down

0 comments on commit d0a056e

Please sign in to comment.