Home AMX User Forum AMX Technical Discussion

Variable Hold n Repeat

This is an example of making a button "hold" event with varaible repeat times. This code sample which I made for a ViewStat "Program Scheduler" (still a work in progress) was made so when the user increments or decrements the time will start changing the values slow and then after 5 seconds it speeds up. Changing time at a fixed slow rate when your trying to advance several hours is annoying to say the least especially at the typical 2/10 second repeat rate. I felt the temperature up and down (heating & cooling setpoints) would be fine at the slower rate as that range is very small.

In this example I'm only using 2 speeds, all button go slow but only the time up & time down button will go faster. You can use as many speeds as you'd like and in various combination.

DEFINE_CONSTANT

TL_VSTHold_VarRepeat   = 18 ;  //timeline for button "hold" events.
VST_HOLD_REPEAT_FAST   = 100 ; //constant for timeline fast "hold repeat". 
VST_HOLD_REPEAT_SLOW   = 750 ;//constant for timeline slow "hold repeat".
HOLD_REPEAT_WAIT_TIME  = 50 ; //five seconds to go from slow to fast repeating.



BUTTON_EVENT[devTPVStatArray,nVST_SchedBtnArry]
     
     {
     PUSH:
	  {
                  //buton push event

		    }
	       }
	  }
     HOLD[2]:
	  {
	  stack_var integer nBTN ;  
	  
	  nBTN = get_last(nVST_SchedBtnArry) ;
	  if (nBTN >= VST_TIME_UP && nBTN <= VST_CTEMP_DWN)
	       {
	       if (!timeline_active(TL_VSTHold_VarRepeat))
		    {
		    local_var long nTL_VSTHoldRepeat[1] ;
		    
		    nVST_HoldBTN = nBTN ;
		    nTL_VSTHoldRepeat[1] = VST_HOLD_REPEAT_SLOW ; 
		    timeline_create(TL_VSTHold_VarRepeat,nTL_VSTHoldRepeat,1,timeline_absolute,timeline_repeat)
		    if (nVST_HoldBTN == VST_TIME_UP || nVST_HoldBTN == VST_TIME_DWN)
			 {
			 wait HOLD_REPEAT_WAIT_TIME 'VST_HOLD_VARIABLE_REPEAT' 
			      {
			      if (timeline_active(TL_VSTHold_VarRepeat))
				   {
				   nTL_VSTHoldRepeat[1] = VST_HOLD_REPEAT_FAST ;
				   timeline_reload(TL_VSTHold_VarRepeat,nTL_VSTHoldRepeat,1) ;
				   }
			      }
			 }
		    }
	       }
	  }
     RELEASE:
	  {
	  if (timeline_active(TL_VSTHold_VarRepeat))
	       {
	       timeline_kill(TL_VSTHold_VarRepeat) ;
	       cancel_wait 'VST_HOLD_VARIABLE_REPEAT' ;
	       }
	  }
     }

TIMELINE_EVENT [TL_VSTHold_VarRepeat]
     
     {
     SWITCH (nVST_HoldBTN)
	  {
	  CASE VST_TIME_UP:
	       {
	       fnVST_ChangeTime(VST_TIME_UP,VST_RETURN_24TIME,VST_INCLUDE_SECONDS) ;
	       }
	  CASE VST_TIME_DWN:
	       {
	       fnVST_ChangeTime(VST_TIME_DWN,VST_RETURN_24TIME,VST_INCLUDE_SECONDS) ;
	       }
	  CASE VST_TEMP_UP:
	       {
	       fnVST_ChangeHeatSetPoint(VST_TEMP_UP) ;
	       }
	  CASE VST_TEMP_DWN:
	       {
	       fnVST_ChangeHeatSetPoint(VST_TEMP_DWN) ;
	       }
	  CASE VST_CTEMP_UP:
	       {
	       fnVST_ChangeCooltSetPoint(VST_CTEMP_UP) ;
	       }
	  CASE VST_CTEMP_DWN:
	       {
	       fnVST_ChangeCooltSetPoint(VST_CTEMP_DWN) ;
	       }
	  }
     }
Sign In or Register to comment.