Skip to content

Commit

Permalink
PoC: don't convert DPT9 to int internally
Browse files Browse the repository at this point in the history
  • Loading branch information
envy authored and Waldemar Porscha committed Dec 5, 2022
1 parent 0e73652 commit 12d419c
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 89 deletions.
62 changes: 61 additions & 1 deletion src/KnxHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,64 @@ uint32_t getDelayPattern(uint16_t iParamIndex, bool iAsSeconds /* = false */) {
return 0;
break;
}
}
}

bool uValueLessThenOrEquals(uValue iLeft, uValue iRight, uint8_t iDptLeft, uint8_t iDptRight)
{
if (iDptLeft == VAL_DPT_9 && iDptRight == VAL_DPT_9)
{
return iLeft.floatValue <= iRight.floatValue;
}
else if (iDptLeft != VAL_DPT_9 && iDptRight == VAL_DPT_9)
{
return iLeft.intValue <= iRight.floatValue;
}
else if (iDptLeft == VAL_DPT_9 && iDptRight != VAL_DPT_9)
{
return iLeft.floatValue <= iRight.intValue;
}
else
{
return iLeft.intValue <= iRight.intValue;
}
};

bool uValueGreaterThenOrEquals(uValue iLeft, uValue iRight, uint8_t iDptLeft, uint8_t iDptRight)
{
if (iDptLeft == VAL_DPT_9 && iDptRight == VAL_DPT_9)
{
return iLeft.floatValue >= iRight.floatValue;
}
else if (iDptLeft != VAL_DPT_9 && iDptRight == VAL_DPT_9)
{
return iLeft.intValue >= iRight.floatValue;
}
else if (iDptLeft == VAL_DPT_9 && iDptRight != VAL_DPT_9)
{
return iLeft.floatValue >= iRight.intValue;
}
else
{
return iLeft.intValue >= iRight.intValue;
}
};

uValue uValueSubtract(uValue iLeft, uValue iRight, uint8_t iDptLeft, uint8_t iDptRight)
{
if (iDptLeft == VAL_DPT_9 && iDptRight == VAL_DPT_9)
{
return { .floatValue = iLeft.floatValue - iRight.floatValue };
}
else if (iDptLeft != VAL_DPT_9 && iDptRight == VAL_DPT_9)
{
return { .floatValue = iLeft.intValue - iRight.floatValue };
}
else if (iDptLeft == VAL_DPT_9 && iDptRight != VAL_DPT_9)
{
return { .floatValue = iLeft.floatValue - iRight.intValue };
}
else
{
return { .intValue = iLeft.intValue - iRight.intValue };
}
}
10 changes: 10 additions & 0 deletions src/KnxHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ Dpt &getDPT(uint8_t iDptIndex);
#define VAL_TIMEBASE_MASK 0xC000

uint32_t getDelayPattern(uint16_t iParamIndex, bool iAsSeconds = false);

union uValue
{
int32_t intValue;
float floatValue;
};

bool uValueLessThenOrEquals(uValue iLeft, uValue iRight, uint8_t iDptLeft, uint8_t iDptRight);
bool uValueGreaterThenOrEquals(uValue iLeft, uValue iRight, uint8_t iDptLeft, uint8_t iDptRight);
uValue uValueSubtract(uValue iLeft, uValue iRight, uint8_t iDptLeft, uint8_t iDptRight);
Loading

0 comments on commit 12d419c

Please sign in to comment.