Button.Holdtime % 600 == 0?
vining
Posts: 4,368
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?
0
Comments
Result on send_string 0's. 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.
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.
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
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.
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:
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.
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.