Are there any examples of creating a module?
winstonma
Posts: 45
I am a newbie on AMX programming. I would like to know if module is similar to class in C++? So I can create a class(module) and then later on create an instance for it? If yes are there any possible sample to show me how to create/call a module?
0
Comments
For example if I have a touchpanel button, once the button is actived. DVD and projector will be both turned on. So I wonder if I can write a module which can provide function call.
Welcome winstonma...
We Call this a Macro , so no need to write modules
if your button channel code is 1
button_event [TP,1]
{
Push:
{
On[dvPROJECTOR]
On[dvDVDPLAYER]
}
}
of course you should do some changes in this code.. i don't know how your devices being controled (IR, RS232,...etc)
I have never been working with C classes, but generally you can do whatever you want in modules.. anything applies to the main code applies to the modules
to make things clear.. modules are separate programs that can run simultaneously with your main program , and you can make run more than one instance of your module.
Finally .. as long as you can write your own netlinx code.. you can write your own modules
DEFINE_CALL 'DEVICE POWER' (INTEGER nPWR)
{
SWITCH(nPWR)
{
CASE 0: //OFF
{
PULSE[dvTV,28]
PULSE[dvDVD,28]
PULSE[dvVCR,28]
}
CASE 1: //ALL ON
{
PULSE[dvTV,27]
PULSE[dvDVD,27]
PULSE[dvVCR,27]
}
CASE 2: //AUDIO ONLY
{
PULSE[dvDVD,27]
PULSE[dvVCR,27]
}
}
}
DEFINE_FUNCTION INTEGER DEVICE_POWER(INTEGER nPWR)
{
SWITCH(nPWR)
{
CASE 0: //OFF
{
PULSE[dvTV,28]
PULSE[dvDVD,28]
PULSE[dvVCR,28]
}
CASE 1: //ALL ON
{
PULSE[dvTV,27]
PULSE[dvDVD,27]
PULSE[dvVCR,27]
}
CASE 2: //AUDIO ONLY
{
PULSE[dvDVD,27]
PULSE[dvVCR,27]
}
}
RETURN 1;
}
If you need to use these functions in a lot of projects, just put them in a seperate include file and include that file in all projects.
Jeff
So when you want to do a Power On or a Power Off how do you assign the properly value to the nPWR variable?
The simplest way is to have three buttons: system off, watch tv and listen to music (shown below in array positions 1,2,3) and just to confuse matters I chose the random channel number values for the buttons in those positions and on a button push:
The button index position that is returned by the GET_LAST system function - 1 when button channel 12, 14 or 32 is pushed gets passed to the function "DEVICE_POWER" where it is referenced as nPWR.
Note that this works on the index postion of the pushed button's channel value not the actual button channel it self.
Ok there is something that I don't understand.
GET_LAST (nCH_BtnArry) -1. How does this work in plain english?
Never mind. I figured it out. Thanks for the example.
a netlinx module is something like a class in C.
You can indeed make an instance of it, but you can't reference to variable, functions, calls, whatever from another class/mainline.
Unfortunately, not like in C++.
being unable to call module functions is a huge disadvantage and a major hole in the design of AMX module system...