-
Notifications
You must be signed in to change notification settings - Fork 53
Types
typedef void (*callback_fptr_t)(message_t const &msg, void *arg);This type spedifies the signature of callback functions. A callback function shall return void and take two arguments:
-
message_t const &msgA reference to amessage_t. -
void *argIf during registration withregister_callbackthe optionalargparameter was set, then this value will be passed into the function.
typedef struct __message
{
knx_command_type_t ct;
address_t received_on;
uint8_t data_len;
uint8_t *data;
} message_t;A struct representing a received KNX telegram. A reference to an instance of this type is passed to callbacks.
Members:
-
ctThe command type of the message, seeknx_command_type_t. -
received_onThe group address this message was received on. -
data_lenThe length of thedataarray. -
dataAuint8_tarray containing the message payload.
typedef enum __knx_command_type
{
KNX_CT_READ = 0x00,
KNX_CT_ANSWER = 0x01,
KNX_CT_WRITE = 0x02,
// ...
} knx_command_type_t;KNX message command types. The most common are shown above.
typedef void (*feedback_action_fptr_t)(void *arg);typedef bool (*enable_condition_t)(void);Some functions have an optional argument of type enable_condition_t, normally called cond.
This argument can point to a function with signature bool (*)() to control if
- the callback shall be enabled.
- the config option shall be enabled.
- the feedback value shall be shown.
Essentially, everytime the web UI is rendered, the library checks if a enable condition function has been set and, if true, calls the function.
If the function returns true, the callback/config option/feedback is shown. If it returns false, it is hidden.
In the case of callbacks, the condition is also checked when receiving a KNX telegram and, if disabled, will not call the callback.
typedef struct __option_entry
{
char *name;
uint8_t value;
} option_entry_t;It is possible to register a config option of type option that presents the user a set of predefined option values to choose from instead of the free text fields presented normally.
config_register_options expects a pointer to an array of type option_entry_t that describes the available options.
All items have a name and a integer representation.
Please notice, how the function does not need to know the length of the array. It expects the last item in the array to have name pointing to nullptr (or NULL or 0).
An example:
option_entry_t my_options[] = {
{"My first option", 1},
{"My second option", 2},
{"My third option", 42}, // The values can be arbitrary and don't need to be consecutive. They only need to be unique in this array.
{"My fourth option", 21},
{nullptr, 0} // This item represents the end of the array.
}Registering is then done so:
knx.config_register_options("My Options", my_options, 1);