Little Problem with flag variable
This block of code executes everytime in many different jobs but I cant seem to figure out whats stopping it this time around, can I rewrite this and still end up with the same timing and function
Code:
button_event [dcPhSpdDial]
{
Hold[30]:
{
IF(button.holdtime < 30)
{
HowLong_Phone = 0; //flag dial it
}
Else IF (button.holdtime > 30)
{
HowLong_Phone = 1; //flag go to another page
}
{
switch (button.input.channel)
{
case 21:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[1],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 22:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[2],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 23:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[3],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 24:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[4],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 25:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[5],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 26:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[6],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
DEFAULT:{HowLong_Phone = 0;}
}
}
}
}
Code:
button_event [dcPhSpdDial]
{
Hold[30]:
{
IF(button.holdtime < 30)
{
HowLong_Phone = 0; //flag dial it
}
Else IF (button.holdtime > 30)
{
HowLong_Phone = 1; //flag go to another page
}
{
switch (button.input.channel)
{
case 21:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[1],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 22:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[2],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 23:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[3],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 24:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[4],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 25:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[5],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
case 26:
{
select
{
active(HowLong_Phone == 0):{SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[6],$0A"} //Dial it
active(HowLong_Phone == 1):{Send_Command TP1A,'PAGE-Phone Book'} //Phone Book Page
}
}
DEFAULT:{HowLong_Phone = 0;}
}
}
}
}
0
Comments
So, your flag variable in the code you wrote will always = 1.
This is what I would suggest:
button_event [dcPhSpdDial] { push: { HowLong_Phone = 0; //initialize the flag everytime the button is pressed. } hold[30]: //this is when the button is held 3.0 seconds--it executes once only. { HowLong_Phone = 1; switch (button.input.channel) { case 21: { Send_Command TP1A,'PAGE-Phone Book' //Phone Book Page } case 22: { Send_Command TP1A,'PAGE-Phone Book' //Phone Book Page } ///etc. } } release: { if(!HowLong_Phone) //this will be true if the button was released before 3.0 seconds { switch (button.input.channel) { case 21: { SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[1],$0A" } case 22: { SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[2],$0A" } //etc. } } } }perhaps you could simplify the hold event handler code if it always does the same thing when one of the buttons is held for more than 3.0 seconds.
Also, the way that you have written your code suggests that you might be able to simplify the release: code
release: { stack_var integer nPhonePresetNbr if(!HowLong_Phone) { nPhonePresetNbr = button.input.channel - 20 SEND_STRING dvBiamp,"'DIAL 1 TIPHONENUM 136 ',cPhoneNumbers[nPhonePresetNbr],$0A" } }(Uncompiled and untested)
define_constant nLongHoldTenths = 30 nPhoneNumberBase = 20 button_event [dcPhSpdDial] { push: { bLongHold = False } hold[nLongHoldTenths]: { bLongHold = True OpenPage('Phone Book') } release: { if (not bLongHold) { SendBiampCommand(nBiampCodeDial,sPhoneNumbers[button.input.channel - nPhoneNumberBase]) } } } }Your approach works fine although my instinct would be to do it like this:
button_event [dcPhSpdDial] { push: { bLongHolding = True cancel_wait 'WaitLongHold' (* Just good practice *) wait nLongHoldTenths 'WaitLongHold' { bLongHolding = False OpenPage('Phone Book') } } release: { cancel_wait 'WaitLongHold' if (bLongHolding) { SendBiampCommand(nBiampCodeDial,sPhoneNumbers[button.input.channel - nPhoneNumberBase]) } } } }