Skip to content

Parameters

Mike edited this page Jan 9, 2023 · 1 revision

Get a Parameters Value

Now you want to setup your device by the parameters the user set via ETS.
This depends on what type your value is:

paramBit

This function returns a single bit as bool.
Used for Enumerations like yes/no or active/disabled.

//Parameter at Offset 1 with Offset 1
bool option = knx.paramBit(1,1);
paramByte

This function returns one Byte as uint8_t.
Used for small numbers (0 to 255) or Enumerations or one char.

//Parameter at Offset 2
byte enu = knx.paramByte(2);
paramSignedByte

This function returns one Byte as int8_t.
Used for small numbers (-127 to 128).

//Parameter at Offset 3
int8_t enu = knx.paramSignedByte(3);
paramWord

This function returns two Bytes as uint16_t.
Used for numbers (0 to 65536) or strings (length of 2 chars).

//Parameter at Offset 4
uint16_t enu = knx.paramWord(4);
paramInt

This function returns four Bytes as int16_t.
Used for numbers (-2.147.483.647 to 2.147.483.648).

//Parameter at Offset 5
int32_t enu = knx.paramInt(5);
paramFloat

This function returns four Bytes as double.
Used for numbers (-2.147.483.647 to 2.147.483.648).

//Parameter at Offset 6
double enu = knx.paramFloat(6, ParameterFloatEncodings::Float_Enc_DPT9);
Encoding Description
DPT9 2 Byte. See Chapter 3.7.2 section 3.10 (Datapoint Types 2-Octet Float Value)
IEEE754Single 4 Byte. C++ float
IEEE754Double 8 Byte. C++ double
BitOffset

So you now know how to get a bit, byte, word, float, etc...
But how do you get the value of an enum with size 2 bits?
Dont't worry! You can use the other 6 bits for an other parameter. You can save more than one parameter in the same Byte as long as the size is maximal 8 bits.
To get only one parameter the knxprod tool (Kaenx-Creator or OpenKNXProducer) creates defines to help you.
Example hardware.h which was generated:

// Offset: 0, Size: 2 Bit, Text: Farbe
#define PARAM_color		0x0000
#define PARAM_color_Mask	0x00C0
#define PARAM_color_Shift	6
// Offset: 0, BitOffset: 2, Size: 1 Bit, Text: Blinken?
#define PARAM_blink		0x0000
#define PARAM_blink_Mask	0x0020
#define PARAM_blink_Shift	5

Now you can calculate your value:

byte colorValue = (knx.paramByte(PARAM_color) & PARAM_color_Mask) >> PARAM_color_Shift;
byte colorValue = (knx.paramByte(PARAM_blink) & PARAM_blink_Mask) >> PARAM_blink_Shift;