Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Input_4_20mA.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#include <math.h>
#include <stdint.h>

#include "ErrorHandling.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ float calculateSensorValueLinearFunction(uint8_t channel2, float a, float b)
float calculateSensorValueLinearFunction2(uint8_t channel2, uint8_t p1y, int16_t p1x, int16_t p2x)
{
float store = p2x - p1x;
if (store == 0) // 4mA- and 20mA-points equal (e.g. both unconfigured) -> avoid div by zero / NaN
return 0;
float m = (20 - p1y) / store;
float b = p1y - (m * p1x);
return ((getAdcVoltage_BOT(channel2)) - b) / m;
Expand Down Expand Up @@ -167,7 +170,7 @@ void processInput_4_20mA(bool readyFlag)
lAbsolute = (knx.paramWord(getParCUR(CUR_CHSendenAbsolut2, channel2)));

// STEP 2b: Check if Change detected
if (lAbsolute > 0 && (abs(value2.ladcValue - valueOld2.ladcValue[channel2])) >= lAbsolute)
if (lAbsolute > 0 && (fabsf(value2.ladcValue - valueOld2.ladcValue[channel2])) >= lAbsolute)
{
lSend = true;
#ifdef Input_4_20mA_Output
Expand All @@ -176,7 +179,7 @@ void processInput_4_20mA(bool readyFlag)
}
// STEP 3: Check value Change "Releative"
// STEP 3a: read Parameter DPT Format
switch (knx.paramByte(getParCUR(CUR_CHSensorType2, channel2)))
switch (knx.paramByte(getParCUR(CUR_CHSensorTypes2, channel2)))
{
case SensorType_humidity:
lAbsolute = 100;
Expand All @@ -191,7 +194,7 @@ void processInput_4_20mA(bool readyFlag)
break;
}
// STEP 3b: Check if Change detected
if (lAbsolute > 0 && value2.ladcValue > 0.2 && roundf(abs(value2.ladcValue - valueOld2.ladcValue[channel2])) >= value2.ladcValue / 100 * lAbsolute)
if (lAbsolute > 0 && value2.ladcValue > 0.2 && roundf(fabsf(value2.ladcValue - valueOld2.ladcValue[channel2])) >= value2.ladcValue / 100 * lAbsolute)
{
lSend = true;
#ifdef Input_4_20mA_Output
Expand Down