To array or not to array...
staticattic
Posts: 200
I've got a noob question. I am thinking there has got to be a better way to write this. I was thinking some sort of arrays or other way to combine all of these so as not to use so many lines of code.
TOUCHPANEL = DEV TOUCHPANEL[] = {dvTP1, dvTP2, dvTP3}.
If it wasn't for each TP having a confidence monitor requiring a change on the Extron switches, this would be easy. The way it is right now, it works just fine, I just can't help but think there has got to be a better way to code this. My buttons covered in these events are mutually exclusive, so turning one on automatically turns the others off on the perspective touch panel. It just seems to me that I am writing the same thing over and over and I should be able to stack them or something. Thanks in advance for the help...
TOUCHPANEL = DEV TOUCHPANEL[] = {dvTP1, dvTP2, dvTP3}.
If it wasn't for each TP having a confidence monitor requiring a change on the Extron switches, this would be easy. The way it is right now, it works just fine, I just can't help but think there has got to be a better way to code this. My buttons covered in these events are mutually exclusive, so turning one on automatically turns the others off on the perspective touch panel. It just seems to me that I am writing the same thing over and over and I should be able to stack them or something. Thanks in advance for the help...
BUTTON_EVENT[TOUCHPANEL,26] //Cam 1 Controls Popup { PUSH: { SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPA-'" SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPN-Camera Control 1'" IF (BUTTON.INPUT.DEVICE = dvTP1) { SEND_STRING dvMAV,'15*17!' nTP1 = 15 nSrc_MAV = 1 nSrc_CPT = 0 nCameraLocation = 1 ON [dvTP1,26] } IF (BUTTON.INPUT.DEVICE = dvTP2) { SEND_STRING dvMAV,'15*19!' nTP2 = 15 nSrc_MAV = 1 nSrc_CPT = 0 nCameraLocation = 1 ON [dvTP2,26] } IF (BUTTON.INPUT.DEVICE = dvTP3) { SEND_STRING dvMAV,'15*15!' nTP3 = 15 nSrc_MAV = 1 nSrc_CPT = 0 nCameraLocation = 1 ON [dvTP3,26] } nMAV_IN = 15 nTransmitCPT = 999 } } BUTTON_EVENT[TOUCHPANEL,27] //Cam 2 Controls Popup { PUSH: { SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPA-'" SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPN-Camera Control 2'" IF (BUTTON.INPUT.DEVICE = dvTP1) { SEND_STRING dvMAV,'16*17!' nTP1 = 16 nCameraLocation = 2 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP1,27] } IF (BUTTON.INPUT.DEVICE = dvTP2) { SEND_STRING dvMAV,'16*19!' nTP2 = 16 nCameraLocation = 2 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP2,27] } IF (BUTTON.INPUT.DEVICE = dvTP3) { SEND_STRING dvMAV,'16*15!' nTP3 = 16 nCameraLocation = 2 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP3,27] } nMAV_IN = 16 nTransmitCPT = 999 } } BUTTON_EVENT[TOUCHPANEL,28] //Cam 3 Controls Popup { PUSH: { SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPA-'" SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPN-Camera Control 3'" IF (BUTTON.INPUT.DEVICE = dvTP1) { SEND_STRING dvMAV,'17*17!' nTP1 = 17 nCameraLocation = 3 nSrc_MAV = 1 nSrc_CPT = 0 nTransmitCPT = 999 ON [dvTP1,28] } IF (BUTTON.INPUT.DEVICE = dvTP2) { SEND_STRING dvMAV,'17*19!' nTP2 = 17 nCameraLocation = 3 nSrc_MAV = 1 nSrc_CPT = 0 nTransmitCPT = 999 ON [dvTP2,28] } IF (BUTTON.INPUT.DEVICE = dvTP3) { SEND_STRING dvMAV,'17*15!' nTP3 = 17 nCameraLocation = 3 nSrc_MAV = 1 nSrc_CPT = 0 nTransmitCPT = 999 ON [dvTP3,28] } nMAV_IN = 17 nTransmitCPT = 999 } } BUTTON_EVENT[TOUCHPANEL,29] //Doc Cam Controls Popup { PUSH: { SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPA-'" SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPN-Doc Cam Controls'" IF (BUTTON.INPUT.DEVICE = dvTP1) { SEND_STRING dvMAV,'18*17!' nTP1 = 18 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP1,29] } IF (BUTTON.INPUT.DEVICE = dvTP2) { SEND_STRING dvMAV,'18*19!' nTP2 = 18 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP2,29] } IF (BUTTON.INPUT.DEVICE = dvTP3) { SEND_STRING dvMAV,'18*15!' nTP3 =18 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP3,29] } nMAV_IN = 18 nTransmitCPT = 999 } } BUTTON_EVENT[TOUCHPANEL,30] //DVD Controls Popup { PUSH: { SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPA-'" SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPN-DVD Controls'" IF (BUTTON.INPUT.DEVICE = dvTP1) { SEND_STRING dvMAV,'1*17!' nTP1 = 1 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP1,30] } IF (BUTTON.INPUT.DEVICE = dvTP2) { SEND_STRING dvMAV,'1*19!' nTP2 = 1 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP2,30] } IF (BUTTON.INPUT.DEVICE = dvTP3) { SEND_STRING dvMAV,'1*15!' nTP3 = 1 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP3,30] } nMAV_IN = 1 nTransmitCPT = 999 } } BUTTON_EVENT[TOUCHPANEL,31] //VCR 1 Controls Popup { PUSH: { SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPA-'" SEND_COMMAND BUTTON.INPUT.DEVICE,"'@PPN-VCR 1 Controls'" IF (BUTTON.INPUT.DEVICE = dvTP1) { SEND_STRING dvMAV,'2*17!' nTP1 = 2 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP1,31] } IF (BUTTON.INPUT.DEVICE = dvTP2) { SEND_STRING dvMAV,'2*19!' nTP2 = 2 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP2,31] } IF (BUTTON.INPUT.DEVICE = dvTP3) { SEND_STRING dvMAV,'2*15!' nTP3 = 2 nSrc_MAV = 1 nSrc_CPT = 0 ON [dvTP3,31] } nMAV_IN = 2 nTransmitCPT = 999 } }
0
Comments
With Dev arrays you can use GET_LAST. Using lookup tables you can shorten you code, and make it easy to modify. This code seems to do the exact same functionality as your code does. Do not even begin to understand why you are using some of those variables, but it will do the same functionality.
Thanks for the reply. That code is pretty sloppy. I wrote it as my very first job, fresh out of the academy. When I got my Programmer Cert, my company decided since I was already on the payroll and held a security clearance, it was far cheaper for me to do any upcoming programming jobs as compared to hiring a sub-contractor. Needless to say, I barely had time to hang my certificate in my cubicle when I was informed they had canceled the planned sub-contractor for our new conference room and decided I was going to do it. No worries except for the fact that the job was already behind schedule and I had ZERO experience outside of a classroom environment. The job included three TP's that needed to act independently from each other, act as computer monitors when needed, display a confidence monitor, and send various sources to our projectors depending on which TP initiated the event and what that TP was looking at. To top that off, I had the head integrator sit right beside me the entire time asking questions. Such as,"Why did you do that?", "What does that do?", "I noticed you put an IF statement for this scenario. Do you need one for that scenario?", "I decided I don't like the arrangement of buttons for this section, can you remove them and put them on a pop-up?", "I like that you made the buttons look like glass. So there is no confusion, can you wrap each button with a bright yellow border?", "Now that I have had time to think about it, I don't like that yellow border. How about a thin black one instead?", etc. That on top of the fact that I did not have any time to finger fiddle made the job very stressful. That being the case, I did what I knew and felt comfortable with. I knew PUSH, HOLD, and RELEASE, and IF...ELSE statements. All of the variables for the moving parts such as the Extron switches and KVM's, I hard coded. That is where all of those crazy variables come from. As time has gone on and I have learned new tricks, from time to time, I like to go back to that code and incorporate better things such as arrays, buffers, string manipulations, etc. I know it is ugly and believe it or not, there are sections that are much uglier, but there was a method to my madness. Even though I go back and laugh at some of my crazy coding, bottom line, it does what it needs to do, so I do take a little pride in that. I still have a lot to learn. Thanks again for the reply and example.
The "proper" way to do this is to use an array of structures. This example is a fairly trivial use of a structure but to me the big advantage is that it lets you collect all of your declarations of information into one place - the SetSomething calls at the bottom of this code. This helps with:
(a) Debugging - it's very easy to declare the wrong switcher input, for instance, and this allows you to see the associations in one glance
(b) Adapting to a different site - changing names and ports is trivial and difficult to get wrong
(c) Expanding - adding another piece of information to the struct is very easy