05-17-2016 10:39 PM
Why wouldn't it trigger twice? It starts false. You push it and it goes true. You spend time cycling through all of the booleans. Then, you wait 200ms. Then, you cycle through all of the booleans setting them to false.
If you're going to use this nonsense, move the delay. Change the value to false immediately. You also have the index of the changed boolean by using the iteration terminal from the first for loop. Why are you cycling through all of the booleans instead of just setting the specific value to false instead? You know the index. You know the value. Stop doing silly things.
Really, you want something that is going to poll the button. Why are you going through all of this hassle to get away from a polling architecture when that's the exact behavior you want? Ditch the event structure and use the polling style.
If you want to use the event structure, you need to knock off the current system. Use the "NewVal" entry to run one of two types of logic. If NewVal = true, start executing the button and save the index to a FGV. If NewVal = false, set the FGV to -1. In the timeout case, use the FGV to determine which button needs to be added to the display. If -1, add nothing. If a legitimate index, add the value you wish. But, this STILL might as well be polling.
05-18-2016 12:39 AM
Natasftw, I used the 200ms delay because of front panel button press visual effect. Without the delay, the button press will not have visual effect at all. Performance is not my major concern here, what I want to achieve is to back space one digit for swift "BS" press and back space repeatedly for long "BS" hold. It's hard to understand your description, could you attach an example? Thanks.
05-18-2016 08:18 AM
I think you missed the point on that piece.
If you put the delay before you rewrite the false value to the control, you create a much larger period of time where the value isn't being read. If you hold it for less than 200ms, you'll trigger the event structure twice (value change from false to true. value change from true to false.) If you hold it for 200-400 ms, you'll trigger it three times (value change from false to true. control is written false. value change from false to true. value change from true to false.) This continues on for however long you hold it. You'll always get one more read.
Again, you want a polling architecture for what you're hoping to accomplish. You don't care WHEN the button is pressed. You want to know what its value is every 200ms. If it's true, run your function. If not, don't. You're making something very simple complicated by using a poor architecture design decision.
05-18-2016 08:52 AM
natasftw,
The delay is before writing all buttons to false.
If I set the delay to zero second, it will still trigger twice.
If I set the delay to 2 seconds, it will only trigger twice.
05-18-2016 10:05 AM - edited 05-18-2016 10:20 AM
@guangdew1 wrote:Natasftw, I used the 200ms delay because of front panel button press visual effect. Without the delay, the button press will not have visual effect at all.
Get rid of all that extra code and change the buttons to latch action. A latch action boolean will show the changed value until the terminal is read by the code, so all you need to do is place the terminals inside a sequence frame tied to a small wait or reset them in the timeout event. See attached quick modification.
05-18-2016 10:57 AM
altenbach, thanks for your example, you code is definitely cleaner than mine. What about the back space issue, should I just move it out of event structure and use a independent while loop to handle it?
05-18-2016 10:58 AM
@guangdew1 wrote:What about the back space issue, should I just move it out of event structure and use a independent while loop to handle it?
What "issue"? If you want an autorepeat on the backspace, use code similar as I suggested earlier. I have a look later...
05-18-2016 11:08 AM
altenbach, I want the repeated back space while holding the back space button. Your previous example used "switch until released", this mechanical action causes the event structure get triggered twice.
05-18-2016 11:33 AM
05-18-2016 11:43 AM
Here is how you can handle the backspace as well (I'm pretty sure Altenbach already showed you similar to this). The BS button should be set to Switch While Pressed. All other buttons should be Latch When Released. You will see the buttons change colors when you press them down. But the actual change does not happen until you release the button. So I see no reason for those delays.