devchan array in modules?
I'm trying to create a devchan array in a module, using a device that is passed to the module rather than declared in it.
Roger McLean
Swinburne University
MODULE_NAME='my module' (DEV vdvDevice, DEV dvDevice)
DEFINE_DEVICE
DEFINE_VARIABLE
devchan dcChannels[] = {{vdvDevice,1},{vdvDevice,2},{vdvDevice,3},{vdvDevice,4}}
The compiler keeps complaining:"Initializer is not a constant". This seems to be due to vdvDevice being externally declared rather than in the DEFINE_DEVICE section of the module. The compiler works fine if I do the following:
MODULE_NAME='my module' (DEV vdvDevice, DEV dvDevice)
DEFINE_DEVICE
vdvLocalDev = 33001:1:0
DEFINE_VARIABLE
devchan dcChannels[] = {{vdvLocalDev,1},{vdvLocalDev,2},{vdvLocalDev,3},{vdvLocalDev,4}}
However, this does not achieve what I want - namely a devchan array for several channels on the device that is passed into the module. I was hoping for a devchan array solution so that later in my code I can do the following:
channel_event[dcChannels]{
on:{
//Do something
}
off:{
//Do something else
}
}
Any clues appreciated.Roger McLean
Swinburne University
0
Comments
//OPTION 1 MODULE_NAME='my module' (DEV vdvDevice, DEV dvDevice) DEFINE_DEVICE DEFINE_VARIABLES volatile integer nChannelList[] = { 1, 2, 3, 4 } DEFINE_EVENT channel_event[vdvDevice, nChannelList] { on: { // do something with the code. } }//OPTION 2 MODULE_NAME='my module' (DEVCHAN dcChannels[], DEV dvDevice) DEFINE_DEVICE DEFINE_VARIABLES DEFINE_EVENT channel_event[dcChannels] { on: { // do something with the code. } }I think I will use your first suggestion. It achieves what I was wanting to do.
Thanks,
Roger McLean
Swinburne University
But I prefer the separate device and channel array approach as well. I have found the DEVCHAN structure to be less useful than I thought it would. It's too limited in many cases.
It should be possible to change things dynamically. But read the help about REBUILD_EVENT before doing so.