Home AMX User Forum NetLinx Studio
Options

Best way to SWITCH:CASE from a get_last

The more system's I do the more I'm trying to be more efficient with my code.

I've moved to less buttons, SWITCH:CASE'ing the room's source to deterine what to do. IE, transport is the same 7 buttons for every source.

Now I want to group all of the devices that have these buttons togther. IE, buttons 1-7 will be transport for every device on every source.

What's the best way to use GET.LAST to SWITCH:CASE a variable based on what the last input was?

I guess I could send the get_last to a function that returns which source variable to SWITCH:CASE. Something like:
define_function integer current_room (integer last_device)
{
    SWITCH (last_device)
    {
          case ir_living:
          {
               return source_audio_living
          }
    }
}

SWITCH (current_room (get_last(button.input.device.number)))
{
    case output_audio_sat1:
    {}
}



Sound good?

Kevin D.

Comments

  • Options
    DHawthorneDHawthorne Posts: 4,584
    I keep my input devices and the button channels in seperate arrays. I will set variables based on what device sent the push, using GET_LAST on the device array, then a switch statement on the button channel that initiates like this: SWITCH(GET_LAST(nButtonChannelArray)). At this point I know what panel sent the PUSH, and can react accordingly.

    For IR remote mapping, I go even simpler. I'll make a generic channel array that has the values 29-100 in it (I treat transports, volume, channel up/down seperately for feedback purposes, besides the fact some devices tap for forward/reverse, others need you to hold the button - it's easier to break it away from this bigger grouping). When my source is selected, I store it's device number in a variable, generally dvDeck. When I get a button press on my panel within that 29-100 range, all the PUSH handler (or RELEASE, as it may be) has is SEND_COMMAND dvDeck, "'SP', BUTTON.INPUT.CHANNEL", which queues the IR of the same channel to that device. Then it's just a matter of making sure my generic control pages for each device have channel numbers that agree with the IR file (like the menu IR channel being 29, and the button for menu also having channel 29). If the device changes, I only have to edit the panel file, and no underlying code changes are needed - really handy for G3 panels you can edit right on the panel.
  • Options
    pauldpauld Posts: 106
    In the past, I have used "Button.input.device" with success to determine which touchpanel from an array had trigged the Event. That will return the d:P:S for the device that set off Button Event.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Except when mapping IR channels directly to button channels, I prefer to use GET_LAST on an integer array or device array to determine my device or button channel. The reason for this is that I can set up corressponding constant arrays as look-up tables. For example, if my button event uses a panel array, and I have an array of panels, GET_LAST will return what index the panel that generated the event has. If it's panel 3 in my array, I can have another array that uses the same index scheme for default audio zones, where nDefualtZone[3] = ZONE_FAMILY_RM, or something of that nature. If my zones change, I only have to edit the arrays, not the code. In some cases, only the constants need to be adjusted, especially if I take it a step further by giving all my indices constant values, like PANEL_FAMILY_RM = 2, and ZONE_FAMILY_RM = 5, etc. This makes it entirely transparent to the code where everything is, and easy to adjust. This is useful when you hare a panel among three rooms, then a year later the customer adds one for his own convenience - you just need to update the constants and the arrays, no support code changes needed.
Sign In or Register to comment.