Home AMX User Forum AMX General Discussion

Button.Holdtime % 600 == 0?

For some reason I'm having problems with button.holdtime using the % (modulos). In the code below the 1st and 3rd ACTIVE's don't fire while the 2nd & 4th do.
 HOLD [2,REPEAT]:
	  {
	  STACK_VAR INTEGER nUI_Indx ;
	 
	  nUI_Indx = GET_LAST(dvUI_Arry) ;
	  if(nUI_TypeArry[nUI_Indx] >= UI_TYPE_G4)
	       {
	       STACK_VAR INTEGER nBTN ;
	       nBTN = BUTTON.INPUT.CHANNEL ;
	       
	       SELECT
		    {
		    ACTIVE(nBtn >= 19 && nBtn <= 22 && BUTTON.HOLDTIME % 600 == 0):
			 {
			 fnMalpesoAdjustClock(nUI_indx,nBtn) ;
			 }
		    ACTIVE((nBtn == 23 || nBtn == 24) && BUTTON.HOLDTIME >= 4000):
			 {
			 fnMalpesoAdjustClock(nUI_indx,nBtn) ;
			 }
		    ACTIVE((nBtn == 23 || nBtn == 24) && BUTTON.HOLDTIME % 600 == 0):
			 {
			 fnMalpesoAdjustClock(nUI_indx,nBtn) ;
			 }
		    ACTIVE(nBTN == 80 && BUTTON.HOLDTIME >= 5000)://close VAV clean screen pop up
			 {
			 DO_RELEASE(dvUI_Arry[nUI_Indx],BUTTON.INPUT.CHANNEL) ;
			 SEND_COMMAND BUTTON.INPUT.DEVICE,"'PPOF-VAV'" ;
			 }
		    }
	       }
	  }
button.holdtime is expressed in milliseconds while the hold,repeat is in 10th of seconds. The code is intended to fire every 600 ms when btn 19 to 24 is held and then if buttons 23 or 24 is held longer than 4 seconds they will then fire every 200 ms. It's something insanely stupid I'm doing wrong but I can't finger it. The 2/10 goes into 600 evenly so it should work. I guess I'll put in some send_string 0's in to verify the .holdtime on every repeat to make sure they jive but in my head it should just work. Hmmm. Anybody see the obvious that I don't?

Comments

  • viningvining Posts: 4,368
    Well, not what I expected.
    if(nUI_TypeArry[nUI_Indx] >= UI_TYPE_G4)
    	       {
    	       STACK_VAR INTEGER nBTN ;
    	       nBTN = BUTTON.INPUT.CHANNEL ;
    	       
    	       fnUI_DeBug("'BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=',itoa(nUI_Indx),', BTN=',itoa(nBTN),', HOLDTIME=',itoa(BUTTON.HOLDTIME),' :DEBUG <',ITOA(__LINE__),'>'") ;
    	       fnUI_DeBug("'BUTTON.HOLDTIME % 600 =',itoa(BUTTON.HOLDTIME % 600),' :DEBUG <',ITOA(__LINE__),'>'") ;
    	  
    	       SELECT
    		    {
    		    ACTIVE(nBtn >= 19 && nBtn <= 22 && BUTTON.HOLDTIME % 600 == 0):
    			 {
    			 fnMalpesoAdjustClock(nUI_indx,nBtn) ;
    			 }
    		    ACTIVE((nBtn == 23 || nBtn == 24) && BUTTON.HOLDTIME >= 4000):
    			 {
    			 fnMalpesoAdjustClock(nUI_indx,nBtn) ;
    			 }
    		    ACTIVE((nBtn == 23 || nBtn == 24) && BUTTON.HOLDTIME % 600 == 0):
    			 {
    			 fnMalpesoAdjustClock(nUI_indx,nBtn) ;
    			 }
    

    Result on send_string 0's.
    Line     71 (20:24:33)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=194 :DEBUG <2818>
    Line     72 (20:24:33)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =194 :DEBUG <2819>
    Line     73 (20:24:33)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=394 :DEBUG <2818>
    Line     74 (20:24:33)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =394 :DEBUG <2819>
    Line     75 (20:24:33)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=594 :DEBUG <2818>
    Line     76 (20:24:33)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =594 :DEBUG <2819>
    Line     77 (20:24:33)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=794 :DEBUG <2818>
    Line     78 (20:24:33)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =194 :DEBUG <2819>
    Line     79 (20:24:33)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=994 :DEBUG <2818>
    Line     80 (20:24:33)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =394 :DEBUG <2819>
    Line     81 (20:24:34)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=1195 :DEBUG <2818>
    Line     82 (20:24:34)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =595 :DEBUG <2819>
    Line     83 (20:24:34)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=1394 :DEBUG <2818>
    Line     84 (20:24:34)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =194 :DEBUG <2819>
    Line     85 (20:24:34)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=1594 :DEBUG <2818>
    Line     86 (20:24:34)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =394 :DEBUG <2819>
    Line     87 (20:24:34)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=1794 :DEBUG <2818>
    Line     88 (20:24:34)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =594 :DEBUG <2819>
    Line     89 (20:24:35)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=1994 :DEBUG <2818>
    Line     90 (20:24:35)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =194 :DEBUG <2819>
    Line     91 (20:24:35)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=2194 :DEBUG <2818>
    Line     92 (20:24:35)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =394 :DEBUG <2819>
    Line     93 (20:24:35)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=2394 :DEBUG <2818>
    Line     94 (20:24:35)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =594 :DEBUG <2819>
    Line     95 (20:24:35)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=2594 :DEBUG <2818>
    Line     96 (20:24:35)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =194 :DEBUG <2819>
    Line     97 (20:24:35)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=2794 :DEBUG <2818>
    Line     98 (20:24:35)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =394 :DEBUG <2819>
    Line     99 (20:24:36)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=2994 :DEBUG <2818>
    Line    100 (20:24:36)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =594 :DEBUG <2819>
    Line    101 (20:24:36)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=3194 :DEBUG <2818>
    Line    102 (20:24:36)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =194 :DEBUG <2819>
    Line    103 (20:24:36)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=3394 :DEBUG <2818>
    Line    104 (20:24:36)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =394 :DEBUG <2819>
    Line    105 (20:24:36)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=3598 :DEBUG <2818>
    Line    106 (20:24:36)::  UI DEBUG (1): BUTTON.HOLDTIME % 600 =598 :DEBUG <2819>
    Line    107 (20:24:36)::  UI DEBUG (1): BUTTON_EVENT[dvUI_Arry,0] HOLD: UI_Indx=4, BTN=23, HOLDTIME=3798 :DEBUG <2818>
    
    So I guess 200 doesn't go into 600 evenly. At least not in Netlinx. No biggy though I'll just make a counter and use % on that.
  • dbradydbrady Posts: 30
    Shouldn't you be using 600 % button.holdtime if you want to check when the holdtime goes into 600 evenly?
  • viningvining Posts: 4,368
    dbrady wrote: »
    Shouldn't you be using 600 % button.holdtime if you want to check when the holdtime goes into 600 evenly?
    No that would potentially only fire once. I wanted holdtime % 600 so it would fire on 600, 1200, 1800, 2400........... Which in theory should have work since my HOLD[2,repeat] should be repeating every 200 ms or 2/10th of a second and should have yielded a pass on 200, 400, "600", 800, 1000, "1200", 1400, 1600, "1800"................but it's a bit out of whack.
  • dbradydbrady Posts: 30
    "The 2/10 goes into 600 evenly so it should work" Sorry i was just basing it on this.
    From your second test it seems like a counter is the way to go. I can't really think of any explanation for it being less than the expected holdtime each time, it's most probably a bug.
  • a_riot42a_riot42 Posts: 1,624
    vining wrote: »
    No that would potentially only fire once. I wanted holdtime % 600 so it would fire on 600, 1200, 1800, 2400........... Which in theory should have work since my HOLD[2,repeat] should be repeating every 200 ms or 2/10th of a second and should have yielded a pass on 200, 400, "600", 800, 1000, "1200", 1400, 1600, "1800"................but it's a bit out of whack.

    It seems overly complicated to do that with modulo, plus then you have all the magic numbers. If you need to keep track of how many times hold has been run wouldn't holdtime/repeattime tell you that?
    Paul
  • yuriyuri Posts: 861
    BUTTON.HOLDTIME has never worked great for me :s
  • viningvining Posts: 4,368
    yuri wrote: »
    BUTTON.HOLDTIME has never worked great for me :s

    I've used it many times in the past but it must have been used with >= not an ==. I think most of the time I've used the modulo it has been in timelines with my own counter to achieve various repeating event time.

    It seems odd though. You would think the main system timeline would be in charge of this so if a hold[2,repeat] should fire the first time at 200ms not 194ms. How did it come up with that number? After that it seems to repeat pretty steadily and 200ms (an occasional hiccup) but since the initial timing is off everything down the line is then off too and % == 0 will never work.

    Of course even when using >= my results will be off since I expect the second active to fire after 20 repeats but in fact in won't fire until 21. No big deal in this code but others using the .holdtime may have issues they didn't bargain for.
  • a_riot42a_riot42 Posts: 1,624
    vining wrote: »
    It seems odd though. You would think the main system timeline would be in charge of this so if a hold[2,repeat] should fire the first time at 200ms not 194ms. How did it come up with that number? After that it seems to repeat pretty steadily and 200ms (an occasional hiccup) but since the initial timing is off everything down the line is then off too and % == 0 will never work.

    I've never needed holdtime to be accurate to the millisecond, so generally all I have ever cared about is how many times has hold run. If you need it to do somthing different depending on the ith time its run, then I would likely just set a variable:
    hold[2, repeat]
    {
      iTimesHeld = iTimesHeld + 1
      
      if (iTimesHeld > 3)
      {
        iTimesHeld = 0
      }
      
      if (iTimesHeld == 3)
      {
        // do the thing
      }
    }
    

    This should do the thing every ~6 tenths of a second. I would think that doing different things depending on how long a button is held could be confusing to the user though.
    Paul
  • viningvining Posts: 4,368
    a_riot42 wrote: »
    I've never needed holdtime to be accurate to the millisecond, so generally all I have ever cared about is how many times has hold run. If you need it to do somthing different depending on the ith time its run, then I would likely just set a variable:
    hold[2, repeat]
    {
      iTimesHeld = iTimesHeld + 1
      
      if (iTimesHeld > 3)
      {
        iTimesHeld = 0
      }
      
      if (iTimesHeld == 3)
      {
        // do the thing
      }
    }
    

    This should do the thing every ~6 tenths of a second. I would think that doing different things depending on how long a button is held could be confusing to the user though.
    Paul

    The varying press and hold is for setting a number between 0-59 for minute inputs to set a clock. I don't do this for the hour setting cuz that's only 1-12 but when scrolling up for minutes just like on an alarm clock after a certain period of time holding (4 seconds in this case) the number starts to increments faster, release and hold again and it increment slowly again, keep holding and it's fast again. Most users I think would expect this. Of course I could just do direct numeric entry but for some reason I chose this route.

    I ended up using a variable to count repitions of the hold that resets to 0 upon release but I 'll still use the modulo so I can vary when the events trigger. Now it's nCnt % 3 == 0 (6/10th or 600ms) or nCnt >= 20 (4 seconds or 4000ms). Same thing just a different way of skinning the cat since the button.holdtime didn't work the way I expected but seldom things do so I adapt and move on and pass my observation on to the community so maybe others don't have to waste time too. :)
  • Jorde_VJorde_V Posts: 393
    vining wrote: »
    ..didn't work the way I expected but seldom things do so I adapt and move on and pass my observation on to the community so maybe others don't have to waste time too. :)

    One of the reasons I always search in the forums before doing any further research on the matters I come across. Someone might've had it and might even have the solution to it.

    Show some love, get some love.
Sign In or Register to comment.