SIMPL is an amazing tool to build control system logic with, but it can bite you sometimes in the way it evaluates a solution. Let me be clear: SIMPL is doing the right thing, but we have to train our brain to think around it to get the result we want. Here’s a simple example using the Logic Wave Delay symbol.
Let’s explore a Press and Hold example. Press and Hold is a great concept for storing or recalling presets. There’s a Press and Hold v1.2 module in the Crestron database, so we’ll start with a program that has just that:
If we look inside this module, it’s put together very cleanly and has been well-tested. I’ve highlighted the in signal so you can visualize everything happening in the first logic wave:
Inside this module, we see an OR has been used as a Logic Wave Delay (to create in_swd), otherwise the held signal would immediately go high for 1 logic wave until the One Shot with in_hold_time* goes low. I’m guessing this module was created before Logic Wave Delay existed, but it does use Logic Wave Pulse… so who knows.
Let’s build our own version of Press and Hold and see why a Logic Wave Delay is needed. Let’s start off with the following program (you can comment out the Press and Hold v1.2 module from before):
Press is our input so we can follow it through the first logic wave. In debugger we can look at the solutions for both press and hold:
You’ll notice that Not_Held goes high in the first solution and Held goes high in the second. But what about if we rapid fire some button presses? Let’s add a stepper to see what happens:
In debugger, we can watch the three button presses happen within a few milliseconds of each other:
Each one registered as Not_Held because the press time was well below 2 seconds. I was hoping to see an errant Held pop up here, but I think we actually built a better Press and Hold module instead! We should convert our program to a module and name it Better Press and Hold v1:
Don’t forget to define the module arguments and pass parameters into the necessary symbols:
Now we can use our Better Press and Hold v1 in our programs and get the added benefit that Held and Not_Held are now jammable with button presses!
So let that be a lesson: programming can be done in many different ways and how you set out to do something always comes around to how it performs when you test it. Unfortunately, in this case we eliminated the need for a Logic Wave Delay. I’ll take another stab at it in a future post, probably after I’ve actually needed one.
Code and module available on GitHub, of course.