Home AMX User Forum AMX General Discussion
Options

Time - Accuracy beyond 1 second??

Okay, I fear I am in trouble but am hoping someone has an answer. I am using some Vantage Infusion keypads to control an AMX system. It is all IP and easy enough, but I would like to be able to tell if the user has "Held" a button. I get PUSH and RELEASE commands back from Vantage.

It seems Netlinx can only be accurate to a second which is a problem for checking if a button is held. For example:
if (dataValue='PRESS')
{
  pressTime = TIME
  WAIT_UNTIL (dataValue='RELEASE')		
     {
        releaseTime = TIME 
        SEND_STRING 0,"'PRESS TIME: ',pressTime,' RELEASE TIME: ',releasetime"
     }
}

This works for me, but with one second accuracy it really doesn't help. Sometimes you hold the button for under a second, but it isn't the SAME second, and holding the button for a few seconds is just silly.

Anyone had to do something similar?

Comments

  • Options
    GET_TIMER and
    SET_TIMER

    who knew... still not sure if I can make this work but it is accurate to 1/10 of a second...
  • Options
    viningvining Posts: 4,368
    On the press create a timeline that repeats every millisecond (slower or faster if desired). In a timeline event run a counter that increments on every timeline event. On release kill the timeline and tally the count then clear the counter. Base your evaluation on the tally.
  • Options
    No need to count iterations through a timeline like that. Just >start< a timeline on the push, and use TIMELINE_GET on the release to determine how many milliseconds have elapsed since the push. (You can follow up the TIMELINE_GET with a kill to reset everything) You don't even need to have a TIMELINE_EVENT handler at all.

    - Chip
  • Options
    Thanks I will give that a shot. Of course, now i was thinking, the hold should actually trigger before the release. I would expect whatever goes with the "hold" to go before I let go of the button.
  • Options
    viningvining Posts: 4,368
    TrikinCurt Wrote: i was thinking, the hold should actually trigger before the release. I would expect whatever goes with the "hold" to go before I let go of the button.
    If you could wait until the button was released then Chip's method using TIMELINE_GET would be the definitely be the better choice but if you want to evaluate the push as a hold prior to a release here are two possibilties using either method.
    if (TIMELINE_ACTIVE(TL_1))
         {
         if (TIMELINE_GET(TL_1) == 1000)
    	  {
    	  //execute hold event ;
    	  TIMELINE_KILL(TL_1) ;
    	  }
         else if(dataValue =='RELEASE')
    	  {
    	  TIMELINE_KILL(TL_1) ;
    	  }
         }
    
    Both methods require creating a TIMELINE on the "Push" string sent from Vantage KP. The above method would have to be placed in DEFINE_PROGRAM and would be evaluated on every pass.
    The Method below requires a TIMELINE_EVENT but like all events they only need be evaluated during the event itself.
    TIMELINE_EVENT[TL_1]
         {
         local_var integer nCounter ;
         
         nCounter ++;
         if (nCounter == 1000)
    	  {
    	  //execute hold event ;
    	  nCounter = 0 ;
    	  TIMELINE_KILL(TL_1) ;
    	  }
         else if(dataValue =='RELEASE')
    	  {
    	  TIMELINE_KILL(TL_1) ;
    	  }
    
         }
    
  • Options
    Thanks. I have the code working (by using the release method). I am wondering if my options are worth it for tracking a hold before release. The key is, I don't have one button to track, I have (potentially) thousands. Here is what I have now:
    if (dataTemp='PRESS')
     {
      TimeArray[1] = 10000
      TIMELINE_CREATE(ATOI(dataIndex),TimeArray,1000,TIMELINE_RELATIVE,TIMELINE_ONCE)
     }
    else if (dataTemp='RELEASE')
    {
      IF(TIMELINE_ACTIVE(ATOI(dataIndex))) 
      {
        if (timeline_get(ATOI(dataIndex)) > BUTTON_HOLD_TIME)
          SEND_STRING 0,'Button was held and released'
        else 
         SEND_STRING 0,'Button was not held'
        TIMELINE_KILL(ATOI(dataIndex))
      }
      else 
         SEND_STRING 0,'Timeline Ended, button was held for a long long time'
    }
    

    So while I could potentially have multiple timelines going (if someone magically pressed every button at once), odds are very few are going at once. If I had to create timeline event handlers for every potential timeline, that would be some crazy code.

    With that said, any suggestions to make the above code work without having to wait for the release?
  • Options
    viningvining Posts: 4,368
    Accually in the example I previously posted only one button can be active at a time. The push starts the timeline and the release stops it and if you hold the timeline will run until the predetermined hold time is reach. So just as two pushes can't be issued at the same time, actually I don't know Vantage so it may be possible to push and hold one button and push another button at the same time.

    Determine what Vantage can do, can you in fact push multiple buttons at the same time or at least hold one button, then push another and have that second button send a string while the first button is still being pressed. If it does you'll have to assign a different strings for the each of the buttons and in your data_event string handler create a queue to hold these values so they can processed one at a time but that can start getting a little tricky as strings will probably arrive out of sequence. (push_1;push_2;push_3;release_1;push_4;release_2) for example.

    The simple solution regardless of what the Vantage does is just allow one event at a time. If the time_line is active disregard everything until the matching release is received which will kill it. Then you're ready for another push.
    The key is, I don't have one button to track, I have (potentially) thousands.
    So while I could potentially have multiple timelines going (if someone magically pressed every button at once), odds are very few are going at once
    Are you talking from one keypad at a time or dozens of keypads with all having the potential of being used simultaneously.

    If the potential of multiple keypads being I might think about setting up for multiple timelines depending on the likely hood of being used at the same time and create a "roll over" sequence so if TL_1 is active use TL_2 using a SELECT ACTIVE like below where the first available timeline will be used.
    SELECT
         {
         ACTIVE (!timeline_active(TL_1)):
    	  {
    	  //code
    	  }
         ACTIVE (!timeline_active(TL_2)):
    	  {
    	  //code
    	  }
         ACTIVE (!timeline_active(TL_3)):
    	  {
    	  //code
    	  }
         ACTIVE (!timeline_active(TL_4)):
    	  {
    	  //code
    	  }
         ACTIVE (!timeline_active(TL_5)):
    	  {
    	  //code
    	  }
         ACTIVE (1):
    	  {
    	  SEND_STRING 0,"'Vantage Handler : Sorry all TimeLines are busy helping other client!',CRLF" ;
    	  SEND_STRING 0,"'Please try again later!',CRLF" ;
    	  }
         }
    
    Out of curiosity what are you actually trying to do with these Vantage buttons any way, audio? I've done that with HomeWorks but never really gave simultaneous usage much thought, maybe I should have but I didn't.

    I've never touch Get_Timer so I can't help with that.

    In your code example the Timeline_get is only evaluated when the data_event string handler sees "release" so if you keep holding nothing will happen and could get annoying if you keep releasing to soon.

    My previous example allow you to evaluate for a hold with out a release.
  • Options
    Audio is what I am doing. So on an 8 button keypad the left 4 are lighting scenes, the right 4 are power, source and volume up/down. I would like it when you hold a button it selects a preset (like XM, channel 80, etc). The Netstreams Keylinx does this (for just audio) and it works great.

    It the Vantage world every button has a VID and that is what they send data for, not keypads at all. So, in this example I have something like 300 buttons doing various stuff.

    Vantage just sends push and release commands and it is certainly possible to push and hold a button, and push/release another while the first is held (even on the same keypad).

    The code I am using can handle all of that without anything complicated so it seems that just making it that the hold does not issue until the release is my best route out.

    Maybe I will get some time and play with your latest idea later, but I have enough to keep me busy right now!

    Thanks for all the help,

    Curt
Sign In or Register to comment.