zunoAppendChannelHandler()
This functions binds handler to Z-Uno channel. This function is used for "dynamic" channel defintion. You have to bind handler to channel each time you power your device.
zunoAppendChannelHandler(ch, value_size, type, *handler)
ch
Z-Uno channel number in range [0;31]. Every time you call zunoAddChannel it adds one more channel with index starting from 0.
value_size
Size of values in getter/setter (or for mapped variables) in bytes.
type
type of needed handler
- CHANNEL_HANDLER_SINGLE_GETTER
binds single-instance getter function to the desired channel. Is suitable for sensors.
- CHANNEL_HANDLER_SINGLE_GETTERSETTER
binds single-instance getter and setter functions to the desired channel. Is suitable for relay/dimmers and etc.
- CHANNEL_HANDLER_SINGLE_VALUEMAPPER
binds single-variable to the desired channel. Is suitable for sensors.
- CHANNEL_HANDLER_MULTI_GETTER
binds multi-instance getter function to the desired channel. You can handle many channels in one function. Number of channel is passed as the first parameter. Is suitable for multi-instance sensors. For example if you have a number of temperature sensors this approach will reduce your code size and gives good code visualization.
- CHANNEL_HANDLER_MULTI_GETTERSETTER
binds multi-instance getter and setter functions to the desired channel. Is suitable for something like multi relays/ multi dimmer devices. Reduces code size.
- CHANNEL_HANDLER_SINGLE_GETTERSETTER_2P
binds single-instance getter and setter for 2 parameters command class. Is suitable for command classes like SwitchColor.
- CHANNEL_HANDLER_MULTI_GETTERSETTER_2P
binds multi-instance getter and setter for 2 parameters command class. Is suitable for command classes like SwitchColor. Multi-instance version.
- CHANNEL_HANDLER_SINGLE_THERMOSTAT
binds single-instance getter and setter to thermostat command class.
- CHANNEL_HANDLER_MULTI_THERMOSTAT
binds multi-instance getter and setter to thermostat command class. Multi-instance version.
handler
Pointer to structure/function-type pointer
CHANNEL_HANDLER_SINGLE_VALUEMAPPER - Use a direct variable mapping without getter/setter function.
byte dimmerValue = 99;
// Immitates static declaration like this
//ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_MULTILEVEL(dimmerValue, NULL));
void setup() {
// ...
// Here you have to start configuration / define channel / commit configuration
// ...
// Just a variable binding
zunoAppendChannelHandler( 0, 1, CHANNEL_HANDLER_SINGLE_VALUEMAPPER, (void*)&dimmerValue); // direct pointer to value that is mapped to this channel
}
CHANNEL_HANDLER_SINGLE_GETTER Binding getter function to the channel
byte dimmerValue = 99;
// Immitates static declaration like this
//ZUNO_SETUP_CHANNELS(ZUNO_SENSOR_BINARY_MOTION(getterFunctionSensorBinary));
void setup() {
// ...
// Here you have to start configuration / define channel / commit configuration
// ...
zunoAppendChannelHandler( 0, 1, CHANNEL_HANDLER_SINGLE_GETTER, (void*)&getterFunctionSensorBinary);// Direct pointer to getter function
}
BYTE getterFunctionSensorBinary() {
return dimmerValue; // We can return any value here. Just shows a proxy getter for "dimmerValue"
}
CHANNEL_HANDLER_SINGLE_GETTERSETTER Binding for getter и setter functions.
byte dimmerValue = 99;
// Immitates static declaration like this
//ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_MULTILEVEL(getSwitchMultilevelValue, setSwitchMultilevelValue));
// We use special proxy-structure to fill both pointers
zuno_handler_single_gettersetter_t gettersetter={(void*)&getSwitchMultilevelValue,(void*)&setSwitchMultilevelValue};
void setup() {
// ...
// Here you have to start configuration / define channel / commit configuration
// ...
zunoAppendChannelHandler( 0, 1, CHANNEL_HANDLER_SINGLE_GETTERSETTER, (void*)&gettersetter); // Translate structure instance to core-side
}
// Simple getter/setter for dimmerValue variable
// Just for example
void setSwitchMultilevelValue(byte newValue) {
dimmerValue = newValue;
}
byte getSwitchMultilevelValue(void) {
return dimmerValue;
}
CHANNEL_HANDLER_SINGLE_GETTERSETTER_2P is used when command class requires some extra parameter in getter/setter compared to common CHANNEL_HANDLER_SINGLE_GETTERSETTER.
uint8_t _color[10] = {0};
// Immitates static declaration like this
//ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_COLOR(SWITCH_COLOR_FLAGS_RED|SWITCH_COLOR_FLAGS_GREEN|SWITCH_COLOR_FLAGS_BLUE, getterFunctionColor, setterFunctionColor));
// We use special proxy-structure to fill both pointers
zuno_handler_single_gettersetter_t color_gettersetter={(void*)&getterFunctionColor,(void*)&setterFunctionColor};
void setup() {
zunoAppendChannelHandler( 0, 1, CHANNEL_HANDLER_SINGLE_GETTERSETTER_2P, (void*)&color_gettersetter);// Translate structure pointer here
}
// proxy getter/setter for _color array
BYTE getterFunctionColor(BYTE component) {
return (_color[component]);
}
void setterFunctionColor(BYTE component, BYTE newValue) {
_color[component] = newValue;
}
CHANNEL_HANDLER_SINGLE_THERMOSTAT specific thermostat command class hadler.
// Thermostat requires variables for current mode and its temperature
BYTE g_therm_mode = THERMOSTAT_MODE_OFF;
int g_therm_point;
BYTE g_update = FALSE;
// Immitates static declaration like this
//ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_COLOR(SWITCH_COLOR_FLAGS_RED|SWITCH_COLOR_FLAGS_GREEN|SWITCH_COLOR_FLAGS_BLUE, getterFunctionColor, setterFunctionColor));
// Fill structure instance
zuno_handler_single_thermostat_t thermostat_handler = {(void*)&thermModeGetterC, (void*)&thermModeSetterC, (void*)&thermPointGetterC, (void*)&thermPointSetterC};
void setup() {
// bind structure to channel
zunoAppendChannelHandler( 0, 1, CHANNEL_HANDLER_SINGLE_THERMOSTAT, (void*)&thermostat_handler);// translate pointer to structure
}
// Calls when user requests mode from Z-Wave controller
BYTE thermModeGetterC(){
return g_therm_mode;
}
// Calls when user changes mode (Heat/Cool/Off and etc) from Z-Wave controller
void thermModeSetterC(BYTE mode){
g_therm_mode = mode;
g_update = TRUE;
}
// Calls when user requests temperature for desired mode from Z-Wave controller
WORD thermPointGetterC(BYTE mode){
return g_therm_point;
(void)mode;
}
// Calls when user changes temperature for desired mode from Z-Wave controller
void thermPointSetterC(BYTE mode,WORD point){
g_update = TRUE;
g_therm_point = point;
(void)mode;
}
Multiinstance example. Lets try to imagine we have 2 montion sensor in one z-wave device.
zuno_handler_multi_getter_t multi_sen_getter={(void*)&getterFunctionSensorBinary,0}; // 0 is the index of first channel
// Immitates static declaration like this
//ZUNO_SETUP_CHANNELS(ZUNO_SENSOR_BINARY_MOTION(getterFunctionSensorBinary), ZUNO_SENSOR_BINARY_MOTION(getterFunctionSensorBinary));
void setup() {
zunoAppendChannelHandler( 0, 1, CHANNEL_HANDLER_MULTI_GETTER, (void*)&multi_sen_getter);// Use the same pointer to the same structure
zunoAppendChannelHandler( 1, 1, CHANNEL_HANDLER_MULTI_GETTER, (void*)&multi_sen_getter);// Use the same pointer to the same structure
}
BYTE getterFunctionSensorBinary(byte ch) {
// Just a stub. Always returns idle. You can add any logic you want :)
return (0x0);
}
Table of required types
Handler type |
Translating variable type |
CHANNEL_HANDLER_SINGLE_GETTER |
Function pointer. |
CHANNEL_HANDLER_SINGLE_GETTERSETTER |
zuno_handler_single_gettersetter_t |
CHANNEL_HANDLER_SINGLE_VALUEMAPPER |
Variable pointer. |
CHANNEL_HANDLER_MULTI_GETTER |
zuno_handler_multi_getter_t |
CHANNEL_HANDLER_MULTI_GETTERSETTER |
zuno_handler_multi_gettersetter_t |
CHANNEL_HANDLER_SINGLE_GETTERSETTER_2P |
zuno_handler_single_gettersetter_t |
CHANNEL_HANDLER_MULTI_GETTERSETTER_2P |
zuno_handler_multi_gettersetter_t |
CHANNEL_HANDLER_SINGLE_THERMOSTAT |
zuno_handler_single_thermostat_t |
CHANNEL_HANDLER_MULTI_THERMOSTAT |
zuno_handler_multi_thermostat_t |
Structures types are defined here ZUNO_SysTypes.h.
Common examples of channel definitions you are able to find here zunoStartDeviceConfiguration.