Least amount of code writing for IR command button presses?
vegastech
Posts: 369
I have a project with 6 sat receivers, 3 blu ray players, and 4 cable boxes. Since the IR codes are set up in a standardized fashion, I was looking for a way to easily send these codes without writing button events for every button on every device. I have started to create a button array:
IE, 10001:2:0 is the Sat DVR, 10001:3:0 is the Blu Ray, and so on. This way I would only have to create a button event for each level on the touchpanel(with copy and paste), and then be done with my IR code button events. Or, at least, that's my thought. I'm also wondering if I need to declare every button number like I did above - it's just that I'm trying to avoid typing out/declaring all 255 button numbers in the array.
VOLATILE INTEGER nBtnArray[] = //Button Array for all IR device presses { 1, 2, 3, 4, 5,And I was going to use this array with a get_last to then direct what code was being sent:
BUTTON_EVENT[dvTPMB_BluRay,nBtnArray] //Blu Ray button group { PUSH: { PULSE[BLURAY,GET_LAST(nBtnArray)] } }I don't have access to an NI currently, but will this work? I think I'm missing something. I've defined the touchpanel with a level for each device:
IE, 10001:2:0 is the Sat DVR, 10001:3:0 is the Blu Ray, and so on. This way I would only have to create a button event for each level on the touchpanel(with copy and paste), and then be done with my IR code button events. Or, at least, that's my thought. I'm also wondering if I need to declare every button number like I did above - it's just that I'm trying to avoid typing out/declaring all 255 button numbers in the array.
0
Comments
How I do this myself is make the array for the IR channels. then I copy and paste the same array below and make the IR channels comments for the button numbers I'm doing. Now make the Button Array in this copied section and rename the array to buttons or whatever.
In essense you've created a data table that relates your buttons to your IR channels.
So later if you have to change out some buttons or change the layout, it's much easier.
Just a suggestion.
I would strongly recommend you don't use PULSE on the IR device either, it's on a global timer and is difficult to tweak per device; using the SP command will let you also use CTON and CTOF to adjust the timing.
Not exactly true.
Every IR file follows the same layout of play, stop, pause, etc.
Every TP file has the button's channel number matched to the IR file.
Then using the above code I can capture everything and pass to the proper IR device.
When the customer switches out the DVD to a Bluray all I have to do is make sure the new Bluray IR is set up properly, and add any necessary buttons to the TP file.
Use a variable to track which source is currently selected and assign the channel numbers on the touch panel to directly correspond to the IR channel (you can have them be different for each source just by using different panel pages), then use 1 button event for all devices.
Something like that would handle all of your IR (0 is a wildcard for any channel, so make sure to only use that port for source IR control).
edit: I guess there were a number of responses since my phone rang.....
If there are multiple panels or dvd players, either or both of those things can be an array. For multiple decks, I use a separate set of buttons for the user to choose which deck to control, or maybe it happens transparently. In that case, dvd is an array.
And there is no need to declare all 255 buttons/functions - just do the ones you think you might need. I generally allocate 20 buttons for each type of machine, which leaves me a few spares. Since you're doing sat, blu-ray and cable, you'd end up with three sets of button/IR integer arrays (assuming all the blu-rays, etc. are the same model). Even with 20 members each, that's a lot less heinous.
Also - notice I used TO, not PULSE, to activate the IR function. DHawthorne is correct.
.
I'm going to start out small and work my way up, so please bear with me.
I define each level of the TP I want to control, with a level for each IR device, with #1 being reserved for functions, macros, etc.: Now I can create a device array to contain all of the TP's levels:
Then I create an array to store all declared button numbers: Now I can create the button event to send the IR codes: It seems to work, in that I can press and hold the satellite buttons and see my iR indicator light up. But setting the TP itself to level 8 seems iffy - I mean, I want to leave room for the always-arriving-late device that no one mentioned, so I kind of need some space here. I added a 'adbeep' to the online event of my TP, but I didn't hear it sound after the last upload...I suppose I could add a +1 to the src variable. Am I overlooking something blatantly obvious that would eventually crash my system? Not only that, but with different devices like sat and blu ray, the button #s do not line up evenly, with things like DVR, List, etc. What can I do about that?
Your code is either incomplete or you're showing only a portion of it. As for your question, look at chill's solution he shows you how to do just that. With your tp-array you can just add another tp port to it, because in the array you can specify what you want and leave out what you want.
In a sense, you have declared every button, because 0 is the shortcut for all possible buttons. However, I consider this bad practice, because you could wind up with inadvertent action taking place from a button you forgot about, or was introduced by a panel change in a module you didn't create, etc. I would much rather limit my event tables with the buttons I am actually using.
Does this essential make the equivalent of a ginormous button stack of
If that is the case, then it doesn't seem like it actually ends up being an efficient way to code. (especially since there is a limit to how many events can be in a stack.)
http://www.amxforums.com/showthread.php?5943-EVENT-TABLES&highlight=Catch
Easier on the system maybe. Having only one event may be easier on the system but I can't see how it would be easier on the programmer, and ultimately that's more important.
Paul
To me if someone wants to program anything in a concise manner, then there has to be a willingness to understand more than just hard-coding button presses - which would be the "easiest" to understand.
Thanks vining for pointing me to the other thread. It is good to know that it isn't taxing on the system.
Then just make sure your TP buttons for source control are set up on port 2, and that the channel numbers line up with the IR command you want to send out.
You only need one popup page for each type of source...show the same Sat page whenever any Sat is selected, the same Cable page when any Cable is selected, etc. i_tp_src[x] determines what to do with the button press. Creating a source page for each Sat box (each on a different TP port) is NOT an efficient way to do it.
Don't get confused that you will have 3 Play buttons (Sat, Cable, and Bluray) that are all on the same port with the same channel number! The code knows what to do!
The other thing to make sure of is that all the touch panels are in the same order in all of your arrays so get_last always points to the correct panel.
I code all of my IR (and 1-way 232) this way. I track currently select source per touch panel in a structure that also tracks which page the panel is on, which audio outputs it's controlling, which video output is selected, etc.
Then I use 1 button event for all IR and presets. A simple conditional separates IR codes from presets.
~~~ The following is for Paul ~~~~
The best part about this setup for me is that I can have an installer swap out cable boxes, bluray players, cd changers etc without them needing to touch programming. They know how to load an IR file and how to edit button text and button channels in the TPD4 file.
I am the only AMX programmer in the company, so it is a huge help for me to be hands off on simple equipment upgrades like this.
It couldn't possibly be, for exactly the reason you mention. There has to be some run-time handling of the wildcard, which meshes with what Vining says about it being easier on the master. No table lookup involved.