Home AMX User Forum AMX Technical Discussion

Button events && - I'm stuck :o(

Hi All,

I am fairly new at the programming but I have been getting on not too bad at modding an original programme.
(going on my AMX training soon!)

I am a little stuck, and not sure why this doesn't compile. Could someone please help?

BUTTON_EVENT[DIGITALIO,MAT_3] // Other WB mat
{PUSH:
{SEND_STRING CAM1,CAM_PRESET4}} // other board shot (more on lecturer than board)

Above works ok

BUTTON_EVENT[DIGITALIO,MAT_1 && DIGITALIO,MAT_2]
{PUSH:
{SEND_STRING CAM1,CAM_PRESET1}} //wide shot covering lectern and desk

That doesn't work

Weirdly it says it doesn't like the line with Push on it??

I am currently trying to get moving cameras for lecture capture and want to go to a wide shot if it detects inputs on more than 1 of the pressure mats.

Comments

  • banobano Posts: 173
    Dubbledex wrote: »
    Hi All,

    I am fairly new at the programming but I have been getting on not too bad at modding an original programme.
    (going on my AMX training soon!)

    I am a little stuck, and not sure why this doesn't compile. Could someone please help?

    BUTTON_EVENT[DIGITALIO,MAT_3] // Other WB mat
    {PUSH:
    {SEND_STRING CAM1,CAM_PRESET4}} // other board shot (more on lecturer than board)

    Above works ok

    BUTTON_EVENT[DIGITALIO,MAT_1 && DIGITALIO,MAT_2]
    {PUSH:
    {SEND_STRING CAM1,CAM_PRESET1}} //wide shot covering lectern and desk

    That doesn't work

    Weirdly it says it doesn't like the line with Push on it??

    I am currently trying to get moving cameras for lecture capture and want to go to a wide shot if it detects inputs on more than 1 of the pressure mats.

    Try stacking your button events

    BUTTON_EVENT[DIGITALIO,MAT_1]
    BUTTON_EVENT[DIGITALIO,MAT_2]
    {PUSH:
    {SEND_STRING CAM1,CAM_PRESET1}} //wide shot covering lectern and desk
  • viningvining Posts: 4,368
    Even if you could use && in a button event like that it wouldn't work anyway since the TPs only allow one push at a time (unless x panel?).

    Either stack as Bano suggested or you could use an array of the two or more channels or 0 to catch all.
  • DubbledexDubbledex Posts: 17
    Thanks for that! Compile Zero errors!!

    The stcking thing worked a treat, I will test it on my "test" ni3100

    I should have said the button event is actually the digital IO coming on.
    I tested this using a 3100 on my desk and switched relays on and off instead of sending camera strings (didn't have a spare ptz camera).
    I'm sure there is a better way, but I will learn :O)
  • DubbledexDubbledex Posts: 17
    Further testing

    I tried this with my relay setup, but using the stacked buttons it triggered the "wide shot" as soon as one of the two buttons were pressed (as weill as triggering it's usual relay "lectern shot". it really has to have both those "buttons" (digital IOs) on to trigger the "wide shot" otherwise it will send both "lectern shot" and "wide shot" to the camera at the same time.
    I have devised this in case there is more than 1 speaker standing on the pressure pads in any given lecture.

    Cheers,

    David
  • ericmedleyericmedley Posts: 4,177
    One way to approach this would be to put the IO in a channel event. Then in the channel event would set a flag to 1 when on and 0 when off.

    Then in the button event only do the send when the flag is 1

    Something like this...
    channel_event[myIOs,1]
    {
    On:{
      IOFlag=1
      }
    Off:{
      IOFlag=0
      }
    }
    
    
    button_event[MyTP,1]
    {
    Push:{
      if(IOFLag) {
        // send the command
        }
      }
    }
    

    This method will only fire if both the IO is lit and the hit the button.
  • ericmedleyericmedley Posts: 4,177
    Use a channel event to set a flag to in or off for the IO. Then in the button event only send the command when the flag is equal to 1. That way both cases need to be 'on' to make it fire
  • DubbledexDubbledex Posts: 17
    Tried and Failed!

    HI Eric,

    I tried the IOFlag idea.. I could get it to build, but when I tried it on my test system it didn't work. When I have mat 1&2 together it should trigger relay8, but this doesn't happen.

    Here is all my code (for my test system) There is some random stuff at the start as I copy pasted to get started:

    PROGRAM_NAME='Test'
    (***********************************************************)
    (***********************************************************)
    (* FILE_LAST_MODIFIED_ON: 04/05/2006 AT: 09:00:25 *)
    (***********************************************************)
    (* System Type : NetLinx *)
    (***********************************************************)
    (* REV HISTORY: *)
    (***********************************************************)
    (*
    $History: $
    *)
    (***********************************************************)
    (* DEVICE NUMBER DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_CONSTANT

    (*************** Change System Details Here *****************)
    CHAR SYSTEM = 99



    DEFINE_DEVICE

    PROJ1 = 5001:1:SYSTEM
    PROJ2 = 5001:2:SYSTEM
    //VIDMATRIX = 5001:3:SYSTEM
    CAM3 = 5001:3:SYSTEM // TEST FOR CAMERA CONTROL
    AUD = 5001:4:SYSTEM
    DOCCAM = 5001:5:SYSTEM
    DVD = 5001:6:SYSTEM
    CVMATRIX = 5001:7:SYSTEM
    RELAYS = 5001:8:SYSTEM // 1 Up 2 Down 3 Up 4 Down 5 Power
    SCALER = 5001:9:SYSTEM
    TPISERIAL = 5001:10:SYSTEM
    DIGITALIO = 5001:17:SYSTEM // 3 4 &5 are mat presses

    LIGHTS = 1538:1:SYSTEM
    CAM1 = 1538:2:SYSTEM // dip switch setting 1-7 off 8-on (1536) + card slot
    CAM2 = 1539:2:SYSTEM

    (**** Fake Devices ****)
    AUDMATRIX = 5002:1:SYSTEM
    RECORDER = 5002:2:SYSTEM
    SLIDE1 = 5002:4:SYSTEM
    SLIDE2 = 5002:5:SYSTEM


    (***********************************************************)
    (* CONSTANT DEFINITIONS GO BELOW *)
    (***********************************************************)

    DEFINE_CONSTANT



    (**** Relay Control ****)
    CAMERA_SWITCH1 = 1
    CAMERA_SWITCH2 = 2
    CAMERA_SWITCH3 = 3
    CAMERA_SWITCH4 = 8


    (*** Digital IO Constants ***)
    MAT_1 = 3
    MAT_2 = 4
    MAT_3 = 5

    (***********************************************************)
    (* DATA TYPE DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_TYPE

    (***********************************************************)
    (* VARIABLE DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_VARIABLE

    //camera variables

    CHAR CAM_PRESET2[100]
    CHAR IOFLAG_MAT1 [20]
    CHAR IOFLAG_MAT2 [20]
    CHAR IOFLAG_MAT3 [20]


    (***********************************************************)
    (* LATCHING DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_LATCHING

    (***********************************************************)
    (* MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_MUTUALLY_EXCLUSIVE

    ([RELAYS,CAMERA_SWITCH1]..[RELAYS,CAMERA_SWITCH2])
    ([RELAYS,CAMERA_SWITCH1]..[RELAYS,CAMERA_SWITCH3])
    ([RELAYS,CAMERA_SWITCH2]..[RELAYS,CAMERA_SWITCH3])


    (***********************************************************)
    (* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
    (***********************************************************)
    (* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
    (* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)

    (***********************************************************)
    (* STARTUP CODE GOES BELOW *)
    (***********************************************************)
    DEFINE_START

    //INCLUDE 'Camera Config'

    CALL 'Set CAM3 Port'
    CALL 'Set Camera 3 Variables'





    (***********************************************************)
    (* THE EVENTS GO BELOW *)
    (***********************************************************)
    DEFINE_CONSTANT

    INCLUDE 'Camera Config'
    DEFINE_EVENT

    data_event[DIGITALIO]
    {
    online :
    {

    send_command DIGITALIO,"'SET INPUT ',MAT_1,' LOW'"
    send_command DIGITALIO,"'SET INPUT ',MAT_2,' LOW'"
    send_command DIGITALIO,"'SET INPUT ',MAT_3,' LOW'"
    }
    }



    CHANNEL_EVENT[DIGITALIO,MAT_1] // LECTERN MAT 1
    {ON:
    {IOFLAG_MAT1=1
    ON[RELAYS,CAMERA_SWITCH1]}

    OFF: {IOFLAG_MAT1=0} }



    CHANNEL_EVENT[DIGITALIO,MAT_2] // LECTERN MAT 2
    {ON:
    {IOFLAG_MAT2=1
    ON[RELAYS,CAMERA_SWITCH2]}

    OFF: {IOFLAG_MAT2=0} }

    CHANNEL_EVENT[DIGITALIO,MAT_3] // LECTERN MAT 3
    {ON:
    {IOFLAG_MAT3=1
    ON[RELAYS,CAMERA_SWITCH3]}

    OFF: {IOFLAG_MAT3=0} }

    BUTTON_EVENT[DIGITALIO,MAT_1] // Lectern Mat
    {PUSH:{
    IF(IOFLAG_MAT2)
    ON[RELAYS,CAMERA_SWITCH4]
    }}



    (***********************************************************)
    (* THE ACTUAL PROGRAM GOES BELOW *)
    (***********************************************************)
    DEFINE_PROGRAM

    (***********************************************************)
    (* END OF PROGRAM *)
    (* DO NOT PUT ANY CODE BELOW THIS COMMENT *)
    (***********************************************************)


    Any help would be appreciated
  • HedbergHedberg Posts: 671
    You can do this all with a couple or three button_events, depending. Or, you can put your IO channels in an array and do it all with one button_event.

    As you have been noticing from the previous discussion, when an IO port is shorted to ground it does two things. One thing is it triggers a button event for the IO port affected. Second, the IO ports feedback channel is turned on. So, it's true, as Vining says, that you can only have one push handler running at a time, so long as the IO port remains shorted, the feedback channel will remain ON (i.e. true or == to 1).

    So, if you have two mats you can do something like this:
    BUTTON_EVENT[DIGITALIO,MAT_1] // Lectern Mat  This button press will happen when someone stands on mat 1.
    {
      PUSH:
      {
         IF([DIGITALIO,MAT_2])//test to see if the IO port mat_2 is on -- when someone is on mat 2.
         {
             ON[RELAYS,CAMERA_SWITCH4]//this is what you want when both mat 1 and mat 2 are active
         }
         else  //here, mat1 is on because we got a button press on IO 1, but, mat 2 is inactive.
         {
          //  do whatever you want when mat 1 is active but not mat 2
          }
       }
       release{ // do whatever when mat 1 goes inactive.}
    }
    

    You can code a button press for mat 2 in a similar manner. Or, you can put it all in a single button_event with a channel array and sort it out with get_last and stuff. That's probably the way you should plan on doing these sorts of things because you can limit your code "litter" and make it easier and more compact.

    Be sure to read up on IOs acting "HIGH" and "LOW" to see how IOs behave as both inputs and outputs.

    Another thing you might want to do is look into what a device,channel structure is and how a logical operator can't work on structures which will explain why your first attempt (structure1 && structure2) didn't work. To write good Netlinx code, you need to have a good understanding of the DPS thing and the device channel structures and how they work in different contexts. You'll get all this stuff when you go to the class, but if you're familiar with it when you go, you'll be better prepared to learn a bunch more stuff.
  • DubbledexDubbledex Posts: 17
    Getting there...

    Hi Harold,

    Thanks for that, it should keep my code a little neater.
    Only thing is, I have 3 mats, not 2. I was trying to use an ELSE IF statement, but compiler is not liking something...

    BUTTON_EVENT[DIGITALIO,MAT_1] // Lectern Mat
    {PUSH:{
    IF([DIGITALIO,MAT_2])
    ON[RELAYS,CAMERA_SWITCH4]}
    ELSE {IF ([DIGITALIO,MAT_3])
    ON[RELAYS,CAMERA_SWITCH5]}
    ELSE {
    ON[RELAYS,CAMERA_SWITCH1]
    }}


    Any ideas?
  • HedbergHedberg Posts: 671
    I think you have a syntax problem with if..else. Also, your braces are fubar.

    try this:
    BUTTON_EVENT[DIGITALIO,MAT_1] // Lectern Mat
      {
         PUSH:
        {
            IF([DIGITALIO,MAT_2])
            {
              ON[RELAYS,CAMERA_SWITCH4]
            }
            ELSE IF ([DIGITALIO,MAT_3])
            {
               ON[RELAYS,CAMERA_SWITCH5]
            }
            ELSE
            {
               ON[RELAYS,CAMERA_SWITCH1]
            }
        }
    }
    
  • DubbledexDubbledex Posts: 17
    Arggh brackets!

    Thanks, that sorted it out, I was pretty close!

    Okay, bad news is that is still didn't work. I think it is because of this:
    //([RELAYS,CAMERA_SWITCH1]..[RELAYS,CAMERA_SWITCH2])
    //([RELAYS,CAMERA_SWITCH1]..[RELAYS,CAMERA_SWITCH3])
    //([RELAYS,CAMERA_SWITCH2]..[RELAYS,CAMERA_SWITCH3])

    As you can see I have now // them out, and it works.

    I will also have to write the reverse of the code you gave me...
    i.e. it works if someone is on mat 2 and then mat 1 comes on, but it doesn't work vice versa. I guess i can just code it for that in that specific button push :o)

    Cheers

    David
  • HedbergHedberg Posts: 671
    Dubbledex wrote: »
    Thanks, that sorted it out, I was pretty close!

    Okay, bad news is that is still didn't work. I think it is because of this:
    //([RELAYS,CAMERA_SWITCH1]..[RELAYS,CAMERA_SWITCH2])
    //([RELAYS,CAMERA_SWITCH1]..[RELAYS,CAMERA_SWITCH3])
    //([RELAYS,CAMERA_SWITCH2]..[RELAYS,CAMERA_SWITCH3])

    As you can see I have now // them out, and it works.

    I will also have to write the reverse of the code you gave me...
    i.e. it works if someone is on mat 2 and then mat 1 comes on, but it doesn't work vice versa. I guess i can just code it for that in that specific button push :o)

    Cheers

    David

    You can put it all in one button press as described earlier. Also, you have to program a release: handler so you can account for someone stepping off a mat while another remains occupied. To keep it cleaner and make re-using your code easier, you might want to use some stack variables, or local, as you prefer.
Sign In or Register to comment.