Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions
Options

Joystick-Button

Hello,
who can help me with programming an Joysick-Button?
Wow will it designed in TP4 and programmed in NetLinx-Studio?
Has someone an example for me?

so long

Comments

  • Options
    DHawthorneDHawthorne Posts: 4,584
    A joystick button has two levels associated with it, as well as it's channel. So it generates a regular BUTTON_EVENT on press/hold/release, just like any other button, but it also generates two level events; the level data will be the X/Y coordinates of where the button was last touched relative to it's border. I will generally link some variables to those levels for easy access, and trigger my processing on the release.
    DEFINE_VARIABLE
    
    VOLATILE INTEGER iJoystickX ;
    VOLATILE INTEGER iJoystickY ;
    
    DEFINE_START
    
    CREATE_LEVEL dvTP, XLevel, iJoystickX ;
    CREATE_LEVEL dvTP, YLevel, iJoysitckY ;
    
    BUTTON_EVENT[dvTP, JoyStickButton]
    {
         RELEASE :
         {
              // Button was released: X = iJoystickX and Y = iJoystickY; do stuff
         }
    }
    

    You could as easily work from LEVEL_EVENTS on those levels, but to my mind you run into a lot of uneccesary processing if someone is just gliding their finger around on the button. If you need your device to track that (like a PTZ control), then that is what you want. If you only care where they end up, what I listed above is fine. I will sometimes put in a small timeline, like a 2-second one, for anti-bounce control, so that the code on my release won't fire ten times in succession if they lifted their finger in a less than clean fashion.
  • Options
    Joystick-Button

    Dave,

    I have done a couple of joystick buttons (Escient X,Y protocol command for example). It was my understanding (and I coded accordingly and it seems to work) that the X and Y levels associated with the joystick button are limited to a range of 0-255. Hence, if you are setting up a 720x480 button as would be the case with an Escient X,Y passthru window, the x and y level values you get back would not be actual coordinates but instead need to be mapped into the coordinates based on the scale of the window. I have a formula I use that determines the scale factor for X and Y and then the level values for the joystick are manipulated using the scale factor to convert them into actual coordinates. Is this also your understanding?

    Reese
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Actually, you can set your level ranges in TPD4 on the Programming tab of the properties window. Both levels have to be scaled the same, but if you can make them match your target device no scaling is needed. I've never actually done this with values larger than 255, but I've gone the other way without issue (like making it 0-100). TPD4 allows larger values without complaining - I just put one in for 0-2048 and it was accepted. For the Escient, you will still need to do some of the scaling you described, because their target window isn't square; one of those values will still need to be adjusted if I'm remembering it correctly.
  • Options
    Joystick-Button

    Dave,

    Thanks for the info -- the TPD4 documentation still indicates that the level range permitted on the joystick button is 0-255. This may be a documentation error or worse, TPD4 lets you specify a level range larger than 255 but it does not work. Since I coded my joystick modules to adhere to the documentation, I have never tried a level range larger than 255. However, since the level range can not be set individually for X and Y, you are correct that for anything other than a square window, scaling is still required.

    Reese
  • Options
    How looks a Projekt in TP4 with joystick-Buttons?
  • Options
    DHawthorneDHawthorne Posts: 4,584
    1stfreak wrote:
    How looks a Projekt in TP4 with joystick-Buttons?
    The button looks like anything you want it to look like. It's simply the button type you apply in the properties under General. Your level properties go in the Programming section.

    The one that Reese talks about using, for example, is to control an Escient product - the button takes up the entire screen, and is a video window. What you see on the button is the GUI from the Escient video output, and touching the button is just like clicking on the Escient display. Your events just send the Escient the XY coords of your touch so it can act on it.

    For something like a PTZ control, you can put whatever graphic or shape you like on the button, presumably something with aroows or some other hint of direction, so when they push it, or move their fingers on it, you translate the movement to the camera or codex.
  • Options
    Joystick-Button

    Maybe the attached file will help tie it together for you. It is a sample MVP-8400 touchpanel file with a Main Page that has one button - a joystick button. As Dave described, there are many uses for a joystick button and many ways to configure it. The most common, as he described, is for manipulation of cameras or user interfaces where they can be provided on the touchpanel within a video window. The joystick button then acts as an overlay that when touched, can be used to obtain x,y coordinates relative to the window and in turn the coordinates can be translated as needed and sent to a device for control or alternately used to control a device directly.

    In the sample file, the joystick button is a 320 by 240 pixel button and has an address port of 10, a channel port of 10, and a level port of 10. If your touchpanel device is 10001, then you would build EVENT handlers for 10001:10:0 or 10001:10:[your system number]. The address port would be used if you want to send variable text to the button or to alter the appearance of the button dynamically. The channel port, as Dave said, can be used when the joystick button is pressed to trigger a BUTTON_EVENT. Under this event, you would obtain the level values from the joystick (having done a CREATE_LEVEL previously for the touchpanel device and the two levels). The joystick button itself also has two levels associated with it, x and y. You configure the level port and first level (x) and TPD4 assumes that the second level (y) is the next sequential level. In my sample, port 10 is used for the level and the x level is 1 and the y level is 2.

    By doing a CREATE_LEVEL using 10001:10:0 level 1 and 10001:10:0 level 2 and associating these with an integer variable, whenever the BUTTON_EVENT is triggered, you can obtain the current X and Y values from the variables and do whatever actions you desire. I left the level ranges set as 0-255 and in this sample, touching the button in the top left corner will generate a BUTTON_EVENT at which point the x,y levels will be 0,0. If you touch the very center of the button, the levels will 128,128 (roughly). If you touch the very bottom right corner of the window, the level values will be 255,255. Scaling would be needed to convert the x,y values into actual window coordinates for the button if the button is not square or if the level range does not match the actual dimensions of the button. For example, 128 would be roughly 50% of the level range for X which would translate into 50% of the X dimension (in this case 50% of 320 which is an X coordinate of 160). Basically you would be using the level to determine the relative position of the joystick cursor and then converting that value into an absolute coordinate.

    Hope this helps --

    Reese
  • Options
    Here is my example of an joystick-button.

    Thank you all for help.

    so long
Sign In or Register to comment.